diff --git a/README.md b/README.md
index 51daab5..37c7113 100644
--- a/README.md
+++ b/README.md
@@ -2429,7 +2429,7 @@ from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER
def main(screen):
ch, first, selected, paths = 0, 0, 0, os.listdir()
- while ch not in [curses.ascii.ESC, ord('q')]:
+ while ch not in [ord('q'), curses.ascii.ESC]:
height, width = screen.getmaxyx()
screen.erase()
for y, filename in enumerate(paths[first : first+height]):
diff --git a/index.html b/index.html
index 6db54ec..fbfc3fb 100644
--- a/index.html
+++ b/index.html
@@ -1991,15 +1991,15 @@ print(table)
def main(screen):
ch, first, selected, paths = 0, 0, 0, os.listdir()
- while ch not in [curses.ascii.ESC, ord('q')]:
+ while ch not in [ord('q'), curses.ascii.ESC]:
height, width = screen.getmaxyx()
screen.erase()
for y, filename in enumerate(paths[first : first+height]):
color = A_REVERSE if filename == paths[selected] else 0
- screen.addstr(y, 0, filename[:width-1], color)
+ screen.addstr(y, 0, filename[:width-1], color)
ch = screen.getch()
selected += (ch == KEY_DOWN) - (ch == KEY_UP)
- selected = max(0, min(len(paths)-1, selected))
+ selected = max(0, min(len(paths)-1, selected))
first += (selected >= first + height) - (selected < first)
if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, 10, 13]:
new_dir = '..' if ch == KEY_LEFT else paths[selected]
diff --git a/parse.js b/parse.js
index 8f69ea5..0c34300 100755
--- a/parse.js
+++ b/parse.js
@@ -161,6 +161,31 @@ const COROUTINES =
'if __name__ == \'__main__\':\n' +
' curses.wrapper(main)\n';
+const CURSES =
+ 'import curses, curses.ascii, os\n' +
+ 'from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER\n' +
+ '\n' +
+ 'def main(screen):\n' +
+ ' ch, first, selected, paths = 0, 0, 0, os.listdir()\n' +
+ ' while ch not in [ord(\'q\'), curses.ascii.ESC]:\n' +
+ ' height, width = screen.getmaxyx()\n' +
+ ' screen.erase()\n' +
+ ' for y, filename in enumerate(paths[first : first+height]):\n' +
+ ' color = A_REVERSE if filename == paths[selected] else 0\n' +
+ ' screen.addstr(y, 0, filename[:width-1], color)\n' +
+ ' ch = screen.getch()\n' +
+ ' selected += (ch == KEY_DOWN) - (ch == KEY_UP)\n' +
+ ' selected = max(0, min(len(paths)-1, selected))\n' +
+ ' first += (selected >= first + height) - (selected < first)\n' +
+ ' if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, 10, 13]:\n' +
+ ' new_dir = \'..\' if ch == KEY_LEFT else paths[selected]\n' +
+ ' if os.path.isdir(new_dir):\n' +
+ ' os.chdir(new_dir)\n' +
+ ' first, selected, paths = 0, 0, os.listdir()\n' +
+ '\n' +
+ 'if __name__ == \'__main__\':\n' +
+ ' curses.wrapper(main)\n';
+
const PROGRESS_BAR =
'\n' +
'>>> from tqdm import tqdm\n' +
@@ -767,6 +792,7 @@ function fixHighlights() {
$(`code:contains(\'\', , )`).html(TYPE);
$(`code:contains(ValueError: malformed node)`).html(EVAL);
$(`code:contains(import asyncio, collections, curses, curses.textpad, enum, random)`).html(COROUTINES);
+ $(`code:contains(import curses, curses.ascii, os)`).html(CURSES);
$(`code:contains(pip3 install tqdm)`).html(PROGRESS_BAR);
$(`code:contains(>>> logging.basicConfig(level=)`).html(LOGGING_EXAMPLE);
$(`code:contains(samples_f = (sin(i *)`).html(AUDIO);