Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Konsole #193

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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

```
Expand Down
61 changes: 61 additions & 0 deletions pokemonterminal/terminal/adapters/konsole.py
Original file line number Diff line number Diff line change
@@ -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"