- commit
- 25290a5f9fc5ab9fbb82155ea3832d612a156216
- parent
- 01623df24d7847d03707f474a8d883857c439fe1
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-10-25 08:07
expose selector
Diffstat
| M | README.md | 6 | ++++++ |
| M | boon.py | 17 | ++++++++++------- |
2 files changed, 16 insertions, 7 deletions
diff --git a/README.md b/README.md
@@ -43,6 +43,12 @@ Call to start the main loop. 43 43 44 44 Set to `False` to stop the main loop. 45 45 -1 46 ### `App.selector` -1 47 -1 48 In instance of -1 49 [`selectors.DefaultSelector`](https://docs.python.org/3/library/selectors.html#selectors.DefaultSelector) -1 50 you can use to register additional file objects to the main loop. -1 51 46 52 ### `App.render(rows, cols)` 47 53 48 54 Overwrite to define your view. For every line in the UI, this functions should
diff --git a/boon.py b/boon.py
@@ -87,6 +87,7 @@ class App: 87 87 self.old_lines = [] 88 88 self.running = False 89 89 self.timeout = 0.5 -1 90 self.selector = selectors.DefaultSelector() 90 91 91 92 # self-pipe to avoid concurrency issues with signal 92 93 self.resize_in, self.resize_out = os.pipe2(os.O_NONBLOCK) @@ -113,24 +114,26 @@ class App: 113 114 os.write(self.resize_out, b'.') 114 115 115 116 def select(self, *fileobjs):116 -1 with selectors.DefaultSelector() as sel:-1 117 with self.selector as sel: 117 118 for fileobj in fileobjs: 118 119 sel.register(fileobj, selectors.EVENT_READ) 119 120 while self.running:120 -1 for key, mask in sel.select():121 -1 yield key.fileobj-1 121 yield from sel.select() 122 122 123 123 def run(self): 124 124 self.running = True 125 125 with fullscreen(): 126 126 self.on_resize()127 -1 for fileobj in self.select(sys.stdin, self.resize_in):128 -1 if fileobj is self.resize_in:-1 127 for key, mask in self.select(self.resize_in): -1 128 if key.fileobj is self.resize_in: 129 129 os.read(self.resize_in, 8) 130 130 self.cols, self.rows = shutil.get_terminal_size() 131 131 self.update(force=True)132 -1 elif fileobj is sys.stdin:133 -1 self.on_key(getch())-1 132 else: -1 133 if key.fileobj is sys.stdin: -1 134 self.on_key(getch()) -1 135 elif callable(key.data): -1 136 key.data() 134 137 self.update() 135 138 136 139 def render(self, rows, cols):