1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
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
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 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]=--------------------------------
[xterm, linux console]
user | ^ Program
input v | output
[ ptyim ]
IM | ^ Program
output v | Output
[ pseudoterminal ]
stdin | ^
v |stdout
[bash(session leader)]
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
pageup/pagedown does not work when the im is turned on
vim
If the im is turned on, it will start in vreplace mode
------------------------------=[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
|