From 586c00dbfd3ef5182bb01357152bd936b167dbd1 Mon Sep 17 00:00:00 2001 From: Jimmy O'Rourke Date: Sat, 24 Mar 2018 13:01:15 -0400 Subject: [PATCH 1/3] specify pokemon name in terminal title bar --- pokemonterminal/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pokemonterminal/main.py b/pokemonterminal/main.py index 1665215..0aa1dac 100644 --- a/pokemonterminal/main.py +++ b/pokemonterminal/main.py @@ -3,6 +3,7 @@ import os import random +import subprocess import sys import time from multiprocessing import Process @@ -51,6 +52,11 @@ def slideshow(filtered, delay, changer_func): random.shuffle(filtered) queque = iter(filtered) continue + if changer_func == scripter.change_terminal: + # Update the terminal window's title + # Shelling out is required when running the slideshow due to it being a detached process without access + # to the terminal title bar via sys.stdout until after the join + subprocess.run(['echo','-n', '\033]2;{}\007'.format(next_pkmn.get_name().title())]) changer_func(next_pkmn.get_path()) p.join(delay * 60) @@ -114,6 +120,8 @@ def main(argv): pipe_out = os.open(PIPE_PATH, os.O_WRONLY) os.write(pipe_out, b"quit\n") os.close(pipe_out) + # clear any updates to the terminal window's title bar + sys.stdout.write("\x1b]2;\x07") scripter.clear_terminal() return @@ -132,6 +140,8 @@ def main(argv): if options.wallpaper: scripter.change_wallpaper(target.get_path()) else: + # Update the terminal window's title + sys.stdout.write("\x1b]2;{}\x07".format(target.get_name().title())) scripter.change_terminal(target.get_path()) From cffde2b3c25888bfca8bafecdbbebb46c938ae88 Mon Sep 17 00:00:00 2001 From: Jimmy O'Rourke Date: Sat, 24 Mar 2018 13:52:29 -0400 Subject: [PATCH 2/3] refactor all terminal related changes into scripter.py --- pokemonterminal/main.py | 14 ++------------ pokemonterminal/scripter.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pokemonterminal/main.py b/pokemonterminal/main.py index 0aa1dac..250e850 100644 --- a/pokemonterminal/main.py +++ b/pokemonterminal/main.py @@ -3,7 +3,6 @@ import os import random -import subprocess import sys import time from multiprocessing import Process @@ -52,12 +51,7 @@ def slideshow(filtered, delay, changer_func): random.shuffle(filtered) queque = iter(filtered) continue - if changer_func == scripter.change_terminal: - # Update the terminal window's title - # Shelling out is required when running the slideshow due to it being a detached process without access - # to the terminal title bar via sys.stdout until after the join - subprocess.run(['echo','-n', '\033]2;{}\007'.format(next_pkmn.get_name().title())]) - changer_func(next_pkmn.get_path()) + changer_func(next_pkmn.get_path(), title=next_pkmn.get_name().title(), background_process=True) p.join(delay * 60) @@ -120,8 +114,6 @@ def main(argv): pipe_out = os.open(PIPE_PATH, os.O_WRONLY) os.write(pipe_out, b"quit\n") os.close(pipe_out) - # clear any updates to the terminal window's title bar - sys.stdout.write("\x1b]2;\x07") scripter.clear_terminal() return @@ -140,9 +132,7 @@ def main(argv): if options.wallpaper: scripter.change_wallpaper(target.get_path()) else: - # Update the terminal window's title - sys.stdout.write("\x1b]2;{}\x07".format(target.get_name().title())) - scripter.change_terminal(target.get_path()) + scripter.change_terminal(target.get_path(), title=target.get_name().title(), background_process=False) if __name__ == "__main__": diff --git a/pokemonterminal/scripter.py b/pokemonterminal/scripter.py index 3c7de73..bf3aa6b 100644 --- a/pokemonterminal/scripter.py +++ b/pokemonterminal/scripter.py @@ -1,4 +1,5 @@ # Used for creating, running and analyzing applescript and bash scripts. +import subprocess import sys from .terminal import get_current_terminal_adapters @@ -69,19 +70,28 @@ def __init_wallpaper_provider(): def clear_terminal(): + # clear any updates to the terminal window's title bar + sys.stdout.write("\x1b]2;\x07") __init_terminal_provider() TERMINAL_PROVIDER.clear() -def change_terminal(image_file_path): +def change_terminal(image_file_path, title, background_process): if not isinstance(image_file_path, str): print("A image path must be passed to the change terminal function.") return + # Update the terminal window's title + # Shelling out is required when running the slideshow due to it being a detached process without access + # to the terminal title bar via sys.stdout until after the join + if background_process: + subprocess.run(['echo','-n', '\033]2;{}\007'.format(title)]) + else: + sys.stdout.write("\x1b]2;{}\x07".format(title)) __init_terminal_provider() TERMINAL_PROVIDER.change_terminal(image_file_path) -def change_wallpaper(image_file_path): +def change_wallpaper(image_file_path, title=None, background_process=False): if not isinstance(image_file_path, str): print("A image path must be passed to the change wallpapper function.") return From 1880e70c04fa4d217dd554289ea1115bc2b9c070 Mon Sep 17 00:00:00 2001 From: Jimmy O'Rourke Date: Tue, 10 Jul 2018 23:55:35 -0400 Subject: [PATCH 3/3] dont mix hex and decimal for differenct commands --- pokemonterminal/scripter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemonterminal/scripter.py b/pokemonterminal/scripter.py index bf3aa6b..d2243e1 100644 --- a/pokemonterminal/scripter.py +++ b/pokemonterminal/scripter.py @@ -71,7 +71,7 @@ def __init_wallpaper_provider(): def clear_terminal(): # clear any updates to the terminal window's title bar - sys.stdout.write("\x1b]2;\x07") + sys.stdout.write("\033]2;\007") __init_terminal_provider() TERMINAL_PROVIDER.clear() @@ -86,7 +86,7 @@ def change_terminal(image_file_path, title, background_process): if background_process: subprocess.run(['echo','-n', '\033]2;{}\007'.format(title)]) else: - sys.stdout.write("\x1b]2;{}\x07".format(title)) + sys.stdout.write("\033]2;{}\007".format(title)) __init_terminal_provider() TERMINAL_PROVIDER.change_terminal(image_file_path)