diff --git a/README.md b/README.md index f8da651..82231ae 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ - Select Pokemon by name or by index number - Ability to change the Desktop Wallpaper & the Terminal background - Internal search system for finding Pokemon -- Supports iTerm2, ConEmu, Terminology, Windows Terminal and Tilix terminal emulators +- Supports iTerm2, ConEmu, Terminology, Windows Terminal, Tilix and Konsole terminal emulators - Supports Windows, MacOS, GNOME, Openbox (with feh), i3wm (with feh) and sway for desktops # Installation @@ -54,6 +54,7 @@ Get a compatible terminal emulator: - [Terminology](https://www.enlightenment.org/about-terminology) - [Tilix](https://gnunn1.github.io/tilix-web/) - [Windows Terminal](https://www.microsoft.com/p/windows-terminal-preview/9n0dx20hk701) +- [Konsole](https://konsole.kde.org/) (minor setup required; instructions [here](#konsole)) You can then proceed with one of the following methods for installation: - [Arch Linux User Repository package (System-wide)](https://aur.archlinux.org/packages/pokemon-terminal-git/) (maintained by [@sylveon](https://github.com/sylveon)) @@ -97,6 +98,12 @@ If you want a system-wide install, run the command as superuser or administrator If you want a per-user install, append the `--user` flag. Look at the pip directives to add a per-user install to your `PATH`. +## Konsole + +The appearance of Konsole is controlled by text files called colorschemes. These files cannot be edited on-the-fly, thus a reference colorscheme must be created. Copy or symlink the desired file to `~/.local/share/konsole/Pokemon.colorscheme`. Local colorschemes are found in the same folder while system colorschemes are found in `/usr/share/konsole`. + +Since Konsole doesn't support on-the-fly editing of colorschemes, a colorscheme file is created on-demand for each Pokemon. The created files can be removed with ```rm ~/.local/share/konsole/p--*```. + # Usage ``` diff --git a/pokemonterminal/terminal/adapters/konsole.py b/pokemonterminal/terminal/adapters/konsole.py new file mode 100644 index 0000000..6855a41 --- /dev/null +++ b/pokemonterminal/terminal/adapters/konsole.py @@ -0,0 +1,61 @@ +import os +from subprocess import run + +from . import TerminalProvider as _TProv + + +class KonsoleProvider(_TProv): + __colorscheme_path__ = os.environ.get("HOME") + "/.local/share/konsole/" + __base_colorscheme__ = "Pokemon" + + def is_compatible() -> bool: + # This gives a false positive if Konsole is open but not the active terminal emulator. + return "KONSOLE_VERSION" in os.environ + + def change_terminal(path: str): + # Make it easy to rm + prefix = "p--" + base_colorscheme_path = ( + KonsoleProvider.__colorscheme_path__ + + KonsoleProvider.__base_colorscheme__ + + ".colorscheme" + ) + pokemon = prefix + path.split("/")[-1].split(".")[0] + new_scheme_path = ( + KonsoleProvider.__colorscheme_path__ + pokemon + ".colorscheme" + ) + + # Caching the colorschemes saves some disk reads and writes. + try: + colorscheme_needs_update = ( + not os.path.isfile(new_scheme_path) + or os.stat(base_colorscheme_path, follow_symlinks=True).st_mtime + > os.stat(new_scheme_path).st_mtime + ) + except IOError: + print(base_colorscheme_path + "not found") + exit(1) + + if colorscheme_needs_update: + new_scheme = "" + with open(base_colorscheme_path, "r") as f: + for line in f: + if line.startswith("Wallpaper"): + line = "Wallpaper=" + path + "\n" + elif line.startswith("Description"): + line = "Description=" + pokemon + "\n" + new_scheme += line + + with open(new_scheme_path, "w") as f: + f.write(new_scheme) + + run(["konsoleprofile", "ColorScheme=" + pokemon], check=True) + + def clear(): + run( + ["konsoleprofile", "ColorScheme=" + KonsoleProvider.__base_colorscheme__], + check=True, + ) + + def __str__(): + return "Konsole"