ptyim, routes terminal input through an input method via pseudottys. Installation: $ make $ sudo make install Usage: $ ptyim $ ptyim /bin/bash Shell: To find the path to the shell, ptyim first looks for - argument 1 - $SHELL then it defaults to /bin/sh Controls: '^K' (0x0B Vertical Tab) to toggle input method '`' (0x80 Backtick) cancel input '^[^[' (0x1B ESC) x 2 cancel input *note: This will send 1 escape to the running program in *addition to cancelling im input Backspace (0x7F DEL) delete last input char Enter (0x0D Carriage Retrun) pass the im buffer through Configuration: All special keys listed above can be configured in "im.h" IM_PREVIEW and IM_PREVIEW_ENTRIES in "im.h" sets the number of preview entries displayed and or disables previews entirely im_key_ranges and im_selector_ranges in "im.h" determines which characters are put into the im buffer #include boshiamy.h in "im.h" can be replaced with any other im file you would like to use. Refer to imtable.h for format questions. --------------------------------=[How it Works]=-------------------------------- ptyim allows for an input method to be used without any sort of desktop environment. All it requires is a terminal, even a physical terminal (given it can display the characters being used) ptyim ibus/fcitx whatever [xterm, linux console] [x11,wayland ] user | ^ Program | input v | output v keypresses [ ptyim ] vs. [ fcitx, ibus ] IM | ^ Program | IM output v | Output v output [ pseudoterminal ] [xterm ] stdin | ^ stdin | ^ v |stdout v | stdout [bash(session leader)] [bash ] Terminal Emulators, Tmux, Screen, etc. all make use of linux pseudoterminals, which are virtual terminals controlled by another piece of software. pytim runs in an existing terminal or terminal emulator, and creates a pseudoterminal. It then routes all input from the real terminal through itself, so that it can apply an input method, before sending that to the pseudoterminal. Output from the pseudoterminal is routed as is back to the real terminal. Caveats: ptyim starts the program running on the pseudoterminal, and makes sure to set it to be the session leader for the pseudoterminal. This is usually bash or some other shell ptyim has to handle sigwinch signals for when the terminal is resized, and relay this back to the pseudoterminal The line discipline has to happen entirely in the pseudoterminal, ptyim makes sure to set the real terminal to raw mode, and restores the previous settings when exiting The Input method is a simple sorted list of key sequences and outputs, searched through a binary search. Encoding Everything is written to be encoding agnostic, except for user input which is assumed to be 8bit ascii (there aren't any encodings in use today where the first 128 characters aren't ascii), but you should be able to configure im.h to use any 8bit encoding for the input assuming your terminal supports it. All the encoded text should be in the input method. the boshiamy.h provided is encoded in utf-8, but a custom im table using any other encoding should work fine. Widths of strings are also stored in the the same file. ---------------------------=[Compatibility and Bugs]=--------------------------- bash fg/bg ctrl-c ctrl-z works cmus, vitetris telnet towel.blinkenlights.nl ranger vim less ------------------------------=[Acknowledgements]=------------------------------ I would like to thank jdh8 on github for creating the ibus-table format boshiamy file I used to make boshiamy.h https://github.com/jdh8/ibus-boshiamy -------------------------------=[Further Reading]=------------------------------ https://www.linusakesson.net/programming/tty/ A great explanation on how ttys, pttys, sessions, groups, etc. work on Linux man pty Details on the linux pseudoterminal system man setsid Creating a new session group/process group man ioctl_tty Linux Terminal System Calls man TIOCSWINSZ Setting window size man TIOCSCTTY Setting Controlling Terminal man termios POSIX Terminal settings man console_codes Terminal escape codes supported by the Linux Console, which along with xterm are the de facto standard for how modern terminal emulators behave