- commit
- 3b3149eb8e0957c8de41cd7a67f0e3a75ba19e2e
- parent
- c71d656276d9dd9ecc01c2ee7a5da985e17bd726
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-03-30 05:30
refactor signal selfpipe to be more generic
Diffstat
| M | boon.py | 15 | ++++++++------- |
1 files changed, 8 insertions, 7 deletions
diff --git a/boon.py b/boon.py
@@ -113,7 +113,7 @@ class App: 113 113 self.selector = selectors.DefaultSelector() 114 114 115 115 # self-pipe to avoid concurrency issues with signal116 -1 self.resize_in, self.resize_out = os.pipe2(os.O_NONBLOCK)-1 116 self.sig_in, self.sig_out = os.pipe2(os.O_NONBLOCK) 117 117 signal.signal(signal.SIGWINCH, self.on_resize) 118 118 119 119 def update(self, force=False): @@ -134,7 +134,7 @@ class App: 134 134 self.old_lines = lines 135 135 136 136 def on_resize(self, *args):137 -1 os.write(self.resize_out, b'.')-1 137 os.write(self.sig_out, b'r') 138 138 139 139 def select(self, *fileobjs): 140 140 with self.selector as sel: @@ -147,11 +147,12 @@ class App: 147 147 self.running = True 148 148 with fullscreen(): 149 149 self.on_resize()150 -1 for key, mask in self.select(sys.stdin, self.resize_in):151 -1 if key.fileobj is self.resize_in:152 -1 os.read(self.resize_in, 8)153 -1 self.cols, self.rows = shutil.get_terminal_size()154 -1 self.update(force=True)-1 150 for key, mask in self.select(sys.stdin, self.sig_in): -1 151 if key.fileobj is self.sig_in: -1 152 b = os.read(self.sig_in, 1) -1 153 if b == b'r': -1 154 self.cols, self.rows = shutil.get_terminal_size() -1 155 self.update(force=True) 155 156 else: 156 157 if key.fileobj is sys.stdin: 157 158 self.on_key(getch())