Browse Source

Curses

pull/155/head
Jure Šorn 1 year ago
parent
commit
6ba3db8cb2
2 changed files with 4 additions and 4 deletions
  1. 4
      README.md
  2. 4
      index.html

4
README.md

@ -2428,10 +2428,10 @@ from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER
def main(screen): def main(screen):
ch, first, selected, paths = 0, 0, 0, os.listdir() ch, first, selected, paths = 0, 0, 0, os.listdir()
while ch != curses.ascii.ESC: while ch != curses.ascii.ESC:
height, _ = screen.getmaxyx()
height, width = screen.getmaxyx()
screen.erase() screen.erase()
for y, filename in enumerate(paths[first : first+height]): for y, filename in enumerate(paths[first : first+height]):
screen.addstr(y, 0, filename, A_REVERSE * (selected == first + y))
screen.addstr(y, 0, filename[:width-1], A_REVERSE * (filename == paths[selected]))
ch = screen.getch() ch = screen.getch()
selected += (ch == KEY_DOWN) - (ch == KEY_UP) selected += (ch == KEY_DOWN) - (ch == KEY_UP)
selected = max(0, min(len(paths)-1, selected)) selected = max(0, min(len(paths)-1, selected))

4
index.html

@ -1990,10 +1990,10 @@ print(table)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">(screen)</span>:</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">(screen)</span>:</span>
ch, first, selected, paths = <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, os.listdir() ch, first, selected, paths = <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, os.listdir()
<span class="hljs-keyword">while</span> ch != curses.ascii.ESC: <span class="hljs-keyword">while</span> ch != curses.ascii.ESC:
height, _ = screen.getmaxyx()
height, width = screen.getmaxyx()
screen.erase() screen.erase()
<span class="hljs-keyword">for</span> y, filename <span class="hljs-keyword">in</span> enumerate(paths[first : first+height]): <span class="hljs-keyword">for</span> y, filename <span class="hljs-keyword">in</span> enumerate(paths[first : first+height]):
screen.addstr(y, <span class="hljs-number">0</span>, filename, A_REVERSE * (selected == first + y))
screen.addstr(y, <span class="hljs-number">0</span>, filename[:width<span class="hljs-number">-1</span>], A_REVERSE * (filename == paths[selected]))
ch = screen.getch() ch = screen.getch()
selected += (ch == KEY_DOWN) - (ch == KEY_UP) selected += (ch == KEY_DOWN) - (ch == KEY_UP)
selected = max(<span class="hljs-number">0</span>, min(len(paths)<span class="hljs-number">-1</span>, selected)) selected = max(<span class="hljs-number">0</span>, min(len(paths)<span class="hljs-number">-1</span>, selected))

Loading…
Cancel
Save