Browse Source

Curses

pull/44/head
Jure Šorn 5 years ago
parent
commit
406fe580af
2 changed files with 10 additions and 6 deletions
  1. 8
      README.md
  2. 8
      index.html

8
README.md

@ -2286,12 +2286,14 @@ with open(<filename>, encoding='utf-8', newline='') as file:
Curses
------
```python
from curses import wrapper, ascii
from curses import wrapper, curs_set, ascii
from curses import KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_LEFT
def main():
wrapper(draw)
def draw(screen):
curs_set(0)
screen.clear()
screen.addstr(0, 0, 'Press ESC to quit.')
while screen.getch() != ascii.ESC:
@ -2299,9 +2301,9 @@ def draw(screen):
def get_border(screen):
from collections import namedtuple
P = namedtuple('P', 'y x')
P = namedtuple('P', 'x y')
height, width = screen.getmaxyx()
return P(height-1, width-1)
return P(width-1, height-1)
if __name__ == '__main__':
main()

8
index.html

@ -1970,12 +1970,14 @@ pyplot.clf() <span class="hljs-comment"># Clears figure.</sp
</code></pre></div></div>
<div><h2 id="curses"><a href="#curses" name="curses">#</a>Curses</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> wrapper, ascii
<div><h2 id="curses"><a href="#curses" name="curses">#</a>Curses</h2><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> wrapper, curs_set, ascii
<span class="hljs-keyword">from</span> curses <span class="hljs-keyword">import</span> KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_LEFT
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>:</span>
wrapper(draw)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">draw</span><span class="hljs-params">(screen)</span>:</span>
curs_set(<span class="hljs-number">0</span>)
screen.clear()
screen.addstr(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-string">'Press ESC to quit.'</span>)
<span class="hljs-keyword">while</span> screen.getch() != ascii.ESC:
@ -1983,9 +1985,9 @@ pyplot.clf() <span class="hljs-comment"># Clears figure.</sp
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_border</span><span class="hljs-params">(screen)</span>:</span>
<span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> namedtuple
P = namedtuple(<span class="hljs-string">'P'</span>, <span class="hljs-string">'y x'</span>)
P = namedtuple(<span class="hljs-string">'P'</span>, <span class="hljs-string">'x y'</span>)
height, width = screen.getmaxyx()
<span class="hljs-keyword">return</span> P(height<span class="hljs-number">-1</span>, width<span class="hljs-number">-1</span>)
<span class="hljs-keyword">return</span> P(width<span class="hljs-number">-1</span>, height<span class="hljs-number">-1</span>)
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
main()

Loading…
Cancel
Save