diff --git a/pokemonterminal/main.py b/pokemonterminal/main.py index 1665215..250e850 100644 --- a/pokemonterminal/main.py +++ b/pokemonterminal/main.py @@ -51,7 +51,7 @@ def slideshow(filtered, delay, changer_func): random.shuffle(filtered) queque = iter(filtered) continue - 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) @@ -132,7 +132,7 @@ def main(argv): if options.wallpaper: scripter.change_wallpaper(target.get_path()) else: - 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..d2243e1 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("\033]2;\007") __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("\033]2;{}\007".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