From c83653117623c2ba9e0270fb9fdca9babb17d06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 25 Feb 2025 19:52:24 +0100 Subject: [PATCH] Plot, Console app --- README.md | 12 ++++++------ index.html | 16 ++++++++-------- parse.js | 9 +++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d3321c7..34a553e 100644 --- a/README.md +++ b/README.md @@ -2419,8 +2419,7 @@ import matplotlib.pyplot as plt plt.plot/bar/scatter(x_data, y_data [, label=]) # Also plt.plot(y_data). plt.legend() # Adds a legend. plt.title/xlabel/ylabel() # Adds a title or label. -plt.savefig() # Saves the plot. -plt.show() # Displays the plot. +plt.show() # Also plt.savefig(). plt.clf() # Clears the plot. ``` @@ -2443,7 +2442,7 @@ Console App ```python # $ pip3 install windows-curses import curses, os -from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER +from curses import A_REVERSE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER def main(screen): ch, first, selected, paths = 0, 0, 0, os.listdir() @@ -2454,9 +2453,10 @@ def main(screen): color = A_REVERSE if filename == paths[selected] else 0 screen.addnstr(y, 0, filename, width-1, color) ch = screen.getch() - selected += (ch == KEY_DOWN) - (ch == KEY_UP) - selected = max(0, min(len(paths)-1, selected)) - first += (selected >= first + height) - (selected < first) + selected -= (ch == KEY_UP) and (selected > 0) + selected += (ch == KEY_DOWN) and (selected < len(paths)-1) + first = min(first, selected) + first = max(first, selected - (height-1)) if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord('\n'), ord('\r')]: new_dir = '..' if ch == KEY_LEFT else paths[selected] if os.path.isdir(new_dir): diff --git a/index.html b/index.html index 13d8668..8757f5e 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@
- +
@@ -1990,8 +1990,7 @@ Processing: 100%|████████████████████| 3 plt.plot/bar/scatter(x_data, y_data [, label=<str>]) # Also plt.plot(y_data). plt.legend() # Adds a legend. plt.title/xlabel/ylabel(<str>) # Adds a title or label. -plt.savefig(<path>) # Saves the plot. -plt.show() # Displays the plot. +plt.show() # Also plt.savefig(<path>). plt.clf() # Clears the plot. @@ -2005,7 +2004,7 @@ print(tabulate.tabulate(rows, headers='firstrow'

#Console App

Runs a basic file explorer in the console:

# $ pip3 install windows-curses
 import curses, os
-from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER
+from curses import A_REVERSE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER
 
 def main(screen):
     ch, first, selected, paths = 0, 0, 0, os.listdir()
@@ -2016,9 +2015,10 @@ print(tabulate.tabulate(rows, headers='firstrow'if filename == paths[selected] else 0
             screen.addnstr(y, 0, filename, width-1, color)
         ch = screen.getch()
-        selected += (ch == KEY_DOWN) - (ch == KEY_UP)
-        selected = max(0, min(len(paths)-1, selected))
-        first += (selected >= first + height) - (selected < first)
+        selected -= (ch == KEY_UP) and (selected > 0)
+        selected += (ch == KEY_DOWN) and (selected < len(paths)-1)
+        first = min(first, selected)
+        first = max(first, selected - (height-1))
         if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord('\n'), ord('\r')]:
             new_dir = '..' if ch == KEY_LEFT else paths[selected]
             if os.path.isdir(new_dir):
@@ -2942,7 +2942,7 @@ $ deactivate                # Deactivates the active
  
 
   
- +
diff --git a/parse.js b/parse.js index 7a1a3fd..1c660ed 100755 --- a/parse.js +++ b/parse.js @@ -168,7 +168,7 @@ const COROUTINES = const CURSES = '# $ pip3 install windows-curses\n' + 'import curses, os\n' + - 'from curses import A_REVERSE, KEY_DOWN, KEY_UP, KEY_LEFT, KEY_RIGHT, KEY_ENTER\n' + + 'from curses import A_REVERSE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER\n' + '\n' + 'def main(screen):\n' + ' ch, first, selected, paths = 0, 0, 0, os.listdir()\n' + @@ -179,9 +179,10 @@ const CURSES = ' color = A_REVERSE if filename == paths[selected] else 0\n' + ' screen.addnstr(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' + + ' selected -= (ch == KEY_UP) and (selected > 0)\n' + + ' selected += (ch == KEY_DOWN) and (selected < len(paths)-1)\n' + + ' first = min(first, selected)\n' + + ' first = max(first, selected - (height-1))\n' + ' if ch in [KEY_LEFT, KEY_RIGHT, KEY_ENTER, ord(\'\\n\'), ord(\'\\r\')]:\n' + ' new_dir = \'..\' if ch == KEY_LEFT else paths[selected]\n' + ' if os.path.isdir(new_dir):\n' +