summaryrefslogtreecommitdiff
path: root/cont/ptyim.html
blob: 6fff58b67d152ca18bfe03958d6e96f545fb2f21 (plain)
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
<!--
123456789-223456789-323456789-423456789-523456789-623456789-723456789-8234567890
一二三四-->
[TITLE]    [DATE]
--------------------------------------------------------------------------------
[SETTITLE]Non-Janky Input Method for the Linux Console (and other Terminals)
[SETDATE]09-06-2025

I've implemented boshiamy in a lot of convoluted ways so far. I've done it using
<a href="https://hairydiode.xyz/jankime">bash scripts</a> and using <a href="https://hairydiode.xyz/xkbabuse">xkb compose rules</a>.

But the reason I've been trying to do this to be able to use an input method in
the Linux Console, and eventually a physical terminal. Back in the day they had
zhcon, which was a userspace virtual console with the input method built in, but
it's ugly and only supports dbcs encoding.

I've also been building a real world physical serial terminal, and having the
input method implemented in software saves me the trouble of trying to fit it
inside of microcontroller ROM.

One Idea I've had for a while is to simply write an input method that sits
between the terminal/console and whatever program is running. If tmux can do it
so can I, right?

After digging through a LOT of manpages I finally made my idea true. It's a
program that creates a pseudoterminal with a shell (or your program of choice)
attached to it, and routes all input through an input method before it reaches
the pseudo terminal. 

I had to mess around with a bunch of stuff like low level POSIX termios
libraries, obscure linux system calls, session/process groups, and even terminal
escape codes. Luckily, almost everything I needed was in the manpages.

The final implementation should be encoding agnostic, although it does make some
assumptions about the terminal you're using. All this can be changed by
modifying some macros.

Testing so far it works on st, the linux console, kmscon and other terminal
emulators. It's compatible with pretty much every ncurses program I tried. 

Special Thanks to:
	- 何震邦(jdh8) for this <a href="https://github.com/jdh8/ibus-boshiamy">ibus boshiamy implementation</a> I based my IM table
	off of
	- Linux Akesson for this <a href="https://www.linusakesson.net/programming/tty/">writeup</a> which explained a everything 
	about how ttys work  on linux

Code and further reading are in a git repo <a href="https://hairydiode.xyz/cgit/ptyim">here</a>