Closed mike-fabian closed 1 year ago
I added some code to fallback to checking the program name if input purpose TERMINAL is not set:
https://github.com/mike-fabian/ibus-typing-booster/blob/main/engine/itb_util.py#L2272
def detect_terminal(input_purpose: int, im_client: str) -> bool:
'''Detect whether the focus is on a terminal
Checks input purpose first and if that is not set to TERMINAL,
checks the program name in im_client to guess whether it is
a terminal.
'''
if input_purpose in [InputPurpose.TERMINAL.value]:
return True
if not im_client:
return False
terminal_regexps = [
'^xim:xterm:',
'^QIBusInputContext:konsole:',
'^xim:rxvt:',
'^xim:urxvt:',
]
for regexp in terminal_regexps:
LOGGER.info('FIXME regexp=%s', regexp)
if re.compile(regexp).search(im_client):
LOGGER.info('FIXME match')
return True
LOGGER.info('FIXME nothing matched')
return False
So this works not only for Gtk based terminals like gnome-terminal, gnome-console, xfce4-terminal, …, it also works for xterm, konsole, rxvt, and urxvt.
Some people do not want to use ibus-typing-booster in terminals because they don’t use terminals to write normal text.
If one types shell commands, the completions offered by shells like bash for that special purpose are usually better then the ibus-typing-booster completions as the latter are more for natural language text. So if one uses an editor running in a terminal to type natural language text or a chat program running in a terminal, then using ibus-typing-booster will give helpful predictions, but not so much for shell commands or programming.
Some people never write natural language text in terminals and therefore want to switch ibus-typing-booster off in terminals always.
Personally I don’t disable ibus-typing-booster completely in terminals, I often switch it off using the key binding for
toggle_input_mode_on_off
but I want to be able to switch it on sometimes.I like to switch it on from time to time because even though the bash completions are usually good, there are some corner cases when the ibus-typing-booster predictions are better. And I usually know from experience when I can expect a good ibus-typing-booster prediction and then switch it on using the key binding.
But adding an option
seems useful for people who always want to disable it in terminals.
Unfortunately it is not so easy to reliably detect terminals. In Gtk there is
GTK_INPUT_PURPOSE_TERMINAL
:https://docs.gtk.org/gtk3/enum.InputPurpose.html#terminal
which is set in some Gtk based terminals, for example
and maybe other Gtk based terminals. But not in konsole (KDE), xterm, rxvt-unicode, and many others.
Even if this does not work for all terminals, I think it is useful adding a
option using
GTK_INPUT_PURPOSE_TERMINAL
, at least there are some terminals available which work nicely with that option.I could extend the scope of that option later to work for other terminals if I find reliable ways to detect other terminals.