- commit
- 38a7537104e801f0e043496c78330f33c1f8df03
- parent
- 3b3149eb8e0957c8de41cd7a67f0e3a75ba19e2e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-03-30 05:31
exit fullscreen on SIGTSTP
Diffstat
| M | boon.py | 13 | ++++++++++++- |
1 files changed, 12 insertions, 1 deletions
diff --git a/boon.py b/boon.py
@@ -111,10 +111,12 @@ class App: 111 111 self.running = False 112 112 self.timeout = 0.5 113 113 self.selector = selectors.DefaultSelector() -1 114 self.fullscreen = fullscreen() 114 115 115 116 # self-pipe to avoid concurrency issues with signal 116 117 self.sig_in, self.sig_out = os.pipe2(os.O_NONBLOCK) 117 118 signal.signal(signal.SIGWINCH, self.on_resize) -1 119 signal.signal(signal.SIGTSTP, self.on_stop) 118 120 119 121 def update(self, force=False): 120 122 lines = list(self.render(self.rows, self.cols)) @@ -136,6 +138,9 @@ class App: 136 138 def on_resize(self, *args): 137 139 os.write(self.sig_out, b'r') 138 140 -1 141 def on_stop(self, *args): -1 142 os.write(self.sig_out, b's') -1 143 139 144 def select(self, *fileobjs): 140 145 with self.selector as sel: 141 146 for fileobj in fileobjs: @@ -145,7 +150,7 @@ class App: 145 150 146 151 def run(self): 147 152 self.running = True148 -1 with fullscreen():-1 153 with self.fullscreen: 149 154 self.on_resize() 150 155 for key, mask in self.select(sys.stdin, self.sig_in): 151 156 if key.fileobj is self.sig_in: @@ -153,6 +158,12 @@ class App: 153 158 if b == b'r': 154 159 self.cols, self.rows = shutil.get_terminal_size() 155 160 self.update(force=True) -1 161 elif b == b's': -1 162 self.fullscreen.__exit__(None, None, None) -1 163 os.kill(os.getpid(), signal.SIGSTOP) -1 164 # paused until SIGCONT -1 165 self.fullscreen.__enter__() -1 166 self.update(force=True) 156 167 else: 157 168 if key.fileobj is sys.stdin: 158 169 self.on_key(getch())