boon

unix terminal framework
git clone https://git.ce9e.org/boon.git

commit
1a9361c86eb1cb8c0d7980d8a3280483b67ae0e1
parent
4f405567c2ca0d4db3769002383fee940ede5108
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-07-13 07:05
mv select to App

Diffstat

M README.md 6 +++---
M boon.py 16 ++++++++--------

2 files changed, 11 insertions, 11 deletions


diff --git a/README.md b/README.md

@@ -105,7 +105,7 @@ def getpass(prompt):
  105   105 Context manager that enters cup and cbreak mode and also hides the cursor.
  106   106 Everything is restored to the previous state after the nested block.
  107   107 
  108    -1 ### `getch(timeout=0.5) -> string`
   -1   108 ### `getch() -> string`
  109   109 
  110    -1 Reads from stdin. If no keys are available within the given timeout, `None` is
  111    -1 returned. See `App.on_key()` for details on the return value.
   -1   110 Read from stdin. This is non-blocking. See `App.on_key()` for details on the
   -1   111 return value.

diff --git a/boon.py b/boon.py

@@ -71,13 +71,9 @@ def fullscreen():
   71    71 		sys.stdout.flush()
   72    72 
   73    73 
   74    -1 def getch(timeout=0.5):
   -1    74 def getch():
   75    75 	# NOTE: result might contain more than one key
   76    76 	fd = sys.stdin.fileno()
   77    -1 	try:
   78    -1 		r, _w, _e = select.select([fd], [], [], timeout)
   79    -1 	except select.error:
   80    -1 		return
   81    77 	with tty_restore(fd):
   82    78 		flags = termios.tcgetattr(fd)
   83    79 		flags[6][termios.VMIN] = 0
@@ -90,6 +86,7 @@ class App:
   90    86 	def __init__(self):
   91    87 		self.old_lines = []
   92    88 		self.running = False
   -1    89 		self.timeout = 0.5
   93    90 		signal.signal(signal.SIGWINCH, self.on_resize)
   94    91 
   95    92 	def update(self, force=False):
@@ -118,9 +115,12 @@ class App:
  118   115 		with fullscreen():
  119   116 			self.on_resize()
  120   117 			while self.running:
  121    -1 				key = getch()
  122    -1 				if key:
  123    -1 					self.on_key(key)
   -1   118 				try:
   -1   119 					r, _w, _e = select.select([sys.stdin], [], [], self.timeout)
   -1   120 				except select.error:
   -1   121 					continue
   -1   122 				if sys.stdin in r:
   -1   123 					self.on_key(getch())
  124   124 					self.update()
  125   125 
  126   126 	def render(self, rows, cols):