boon

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

commit
2d2aa960398c4195ffbbd9756f970b45002eb19c
parent
99c519334c82023fb89de530e4d964d3a4ce2c09
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-07-13 05:23
rm get_size() in favor of shutils.get_terminal_size()

Diffstat

M README.md 5 -----
M boon.py 15 ++-------------

2 files changed, 2 insertions, 18 deletions


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

@@ -86,11 +86,6 @@ print(get_cap('setaf', 13) + 'foo' + get_cap('sgr0'))
   86    86 
   87    87 Move the cursor to the given position.
   88    88 
   89    -1 ### `get_size() -> (rows, cols)`
   90    -1 
   91    -1 Get the current size of the terminal. This is more reliable than
   92    -1 `get_cap('rows')` / `get_cap('cols')`.
   93    -1 
   94    89 ### `tty_restore(fd)`
   95    90 
   96    91 Context manager that restores tty settings after the nested block.

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

@@ -1,13 +1,12 @@
    1     1 import os
    2     2 import curses
    3     3 import select
   -1     4 import shutil
    4     5 import signal
    5    -1 import struct
    6     6 import sys
    7     7 import termios
    8     8 import tty
    9     9 from contextlib import contextmanager
   10    -1 from fcntl import ioctl
   11    10 
   12    11 curses.setupterm()
   13    12 
@@ -47,16 +46,6 @@ def move(y, x):
   47    46 	sys.stdout.write(get_cap('cup', y, x))
   48    47 
   49    48 
   50    -1 def get_size():
   51    -1 	# curses.tigetnum('cols') does not update on resize
   52    -1 	try:
   53    -1 		raw = ioctl(sys.stdout, termios.TIOCGWINSZ, '\000' * 8)
   54    -1 		parsed = struct.unpack('hhhh', raw)
   55    -1 		return parsed[0], parsed[1]
   56    -1 	except OSError:
   57    -1 		return 0, 0
   58    -1 
   59    -1 
   60    49 @contextmanager
   61    50 def tty_restore(fd):
   62    51 	old = termios.tcgetattr(fd)
@@ -121,7 +110,7 @@ class App:
  121   110 		self.old_lines = lines
  122   111 
  123   112 	def on_resize(self, *args):
  124    -1 		self.rows, self.cols = get_size()
   -1   113 		self.cols, self.rows = shutil.get_terminal_size()
  125   114 		self.update()
  126   115 
  127   116 	def run(self):