Skip to content

Commit

Permalink
Merge pull request #154 from ceccopierangiolieugenio/Fix_153
Browse files Browse the repository at this point in the history
FIX: #153 Non blocking SIGWINCH
  • Loading branch information
ceccopierangiolieugenio authored Aug 1, 2023
2 parents 2c2647d + f57809c commit 3b3f918
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions TermTk/TTkCore/TTkTerm/term_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# SOFTWARE.

import sys, os, signal
from threading import Thread, Lock

try: import termios
except Exception as e:
Expand Down Expand Up @@ -118,11 +119,20 @@ def _getTerminalSize():
print(f'ERROR: {e}')
TTkTermBase.getTerminalSize = _getTerminalSize

_sigWinChMutex = Lock()

@staticmethod
def _sigWinChThreaded():
if not TTkTerm._sigWinChMutex.acquire(blocking=False): return
while (TTkTerm.width, TTkTerm.height) != (wh:=TTkTerm.getTerminalSize()):
TTkTerm.width, TTkTerm.height = wh
if TTkTerm._sigWinChCb is not None:
TTkTerm._sigWinChCb(TTkTerm.width, TTkTerm.height)
TTkTerm._sigWinChMutex.release()

@staticmethod
def _sigWinCh(signum, frame):
TTkTerm.width, TTkTerm.height = TTkTerm.getTerminalSize()
if TTkTerm._sigWinChCb is not None:
TTkTerm._sigWinChCb(TTkTerm.width, TTkTerm.height)
Thread(target=TTkTerm._sigWinChThreaded).start()

@staticmethod
def _registerResizeCb(callback):
Expand Down
1 change: 1 addition & 0 deletions tools/check.import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __check(){
-e "term.*.py:import sys, os, signal" \
-e "term.*.py:from .term_base import TTkTermBase" \
-e "term_pyodide.py:import pyodideProxy" \
-e "term_unix.py:from threading import Thread, Lock" \
-e "timer.py:import importlib" \
-e "timer_unix.py:import threading" \
-e "timer_pyodide.py:import pyodideProxy" \
Expand Down

0 comments on commit 3b3f918

Please sign in to comment.