Coding style.
- Main tui function should also set the window title.
This commit is contained in:
parent
0679cb14b5
commit
5fd06479da
4 changed files with 16 additions and 15 deletions
|
|
@ -452,16 +452,17 @@ def signal_handler(loop, signal_, func):
|
|||
loop.remove_signal_handler(signal_)
|
||||
|
||||
|
||||
async def tui(screen_widget):
|
||||
async def tui(title, screen_widget):
|
||||
global APPEARANCE_CHANGED_EVENT
|
||||
global SHUTDOWN_EVENT
|
||||
APPEARANCE_CHANGED_EVENT = asyncio.Event()
|
||||
SHUTDOWN_EVENT = asyncio.Event()
|
||||
loop = asyncio.get_running_loop()
|
||||
with (signal_handler(loop, signal.SIGWINCH, lambda: draw_screen(screen_widget)),
|
||||
with (terminal.title(title), signal_handler(loop, signal.SIGWINCH, lambda: draw_screen(screen_widget)),
|
||||
signal_handler(loop, signal.SIGINT, SHUTDOWN_EVENT.set),
|
||||
signal_handler(loop, signal.SIGTERM, SHUTDOWN_EVENT.set),
|
||||
terminal.alternate_buffer(), terminal.interactive(), terminal.mouse_tracking()):
|
||||
terminal.alternate_buffer(), terminal.interactive(), terminal.mouse_tracking()
|
||||
):
|
||||
update_task = asyncio.create_task(update_screen(screen_widget))
|
||||
try:
|
||||
loop.add_reader(sys.stdin, on_terminal_input, screen_widget)
|
||||
|
|
@ -498,4 +499,4 @@ class _Screen:
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(tui(_Screen()))
|
||||
asyncio.run(tui("Hello World", _Screen()))
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ def move(x, y):
|
|||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def terminal_title(title):
|
||||
def title(title):
|
||||
sys.stdout.write(ESC + "7") # save
|
||||
sys.stdout.write(f"\033]0;{title}\007") # set title
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue