diff options
author | Jacob Moody <moody@posixcafe.org> | 2022-08-17 14:20:56 +0000 |
---|---|---|
committer | Jacob Moody <moody@posixcafe.org> | 2022-08-17 14:20:56 +0000 |
commit | 7828ffb8a486e188b61394436a434e8cae4fd487 (patch) | |
tree | f397e48ee42cc51958556be06d67271b63b57c78 | |
parent | 3331ccc6a4e1959253e3d34beee495d191484660 (diff) |
ktrans: use stdio by default
The kbdtap is now given as the first argument instead.
The use of stdio allows for multiple taps to be chained
together in something like:
; </dev/kbdtap ktrans | progB | progC >/dev/kbdtap
-rw-r--r-- | sys/man/1/ktrans | 52 | ||||
-rw-r--r-- | sys/src/cmd/ktrans/main.c | 24 |
2 files changed, 40 insertions, 36 deletions
diff --git a/sys/man/1/ktrans b/sys/man/1/ktrans index a5acd1125..7662a9a5c 100644 --- a/sys/man/1/ktrans +++ b/sys/man/1/ktrans @@ -4,39 +4,41 @@ ktrans \- language transliterator .SH SYNOPSIS .B ktrans [ -.B -t -.I kbdtap -] -[ .B -l .I lang ] +[ +.I kbdtap +] .SH DESCRIPTION .I Ktrans -provides a transliteration layer -to keyboard input through reads and -writes to -.BR /dev/kbdtap . -The -.B -t -flag changes the +transliterates a stream of keyboard +events. Without any arguments, +.I ktrans +reads events from standard input +and writes out converted events to stdout. +If a .I kbdtap -file used. The -.B -l -flag changes the initial -language. +file is given, it is used for both +input and output instead. .SH CONVERSION -Conversion is done in two steps: An implicit layer -that is used for direct mappings between ascii characters and -an explicit multi rune conversion used for compound mappings. +Conversion is done in two layers, an implicit +layer for unambigious mappings, and an explicit +layer for selecting one match out of a list of +ambigious matches. +.PP +The implicit layer happens automatically as characters +are input, transforming a consecutive set of key strokes +in to their rune counterpart. A series of these runes can +then be explicitely converted using ctrl-\\. Consecutive +inputs of ctrl-\\ can then be used to cycle through all the +matches. A newline may also be used to perform an explicit +conversion, but will not cycle through other possible matches. +.PP +Input is always passed along, when a match is found .I Ktrans -does implicit conversion by passing through characters -as they are input. Then when a sequence of input is matched, -backspaces are emitted to clear the input sequence and the matched -rune sequence is emitted. The last 'word' of input may be then -explicitely transliterated by typing ctrl-\\. A newline character also -performs this lookup, but additional newline characters will not -cycle through alternatives. +will emit backspaces to clear the input sequence and replace +it with the matched sequence. .SH CONTROL The language is selected by typing a control character: .TP diff --git a/sys/src/cmd/ktrans/main.c b/sys/src/cmd/ktrans/main.c index f41d3cfe3..6d6da0cf7 100644 --- a/sys/src/cmd/ktrans/main.c +++ b/sys/src/cmd/ktrans/main.c @@ -581,7 +581,7 @@ kbdsink(void*) void usage(void) { - fprint(2, "usage: %s [ -t tap ] [ -l lang ]\n", argv0); + fprint(2, "usage: %s [ -l lang ] [ kbdtap ]\n", argv0); threadexits("usage"); } @@ -592,14 +592,9 @@ threadmain(int argc, char *argv[]) { char *jishoname, *zidianname; - char *tap; - tap = "/dev/kbdtap"; deflang = LangEN; ARGBEGIN{ - case 't': - tap = EARGF(usage()); - break; case 'l': deflang = parselang(EARGF(usage())); if(deflang < 0) @@ -608,12 +603,19 @@ threadmain(int argc, char *argv[]) default: usage(); }ARGEND; - if(argc != 0) + switch(argc){ + case 0: + kbdin = 0; + kbdout = 1; + break; + case 1: + kbdin = kbdout = open(argv[0], ORDWR); + if(kbdin < 0) + sysfatal("failed to open kbdtap: %r"); + break; + default: usage(); - - kbdin = kbdout = open(tap, ORDWR); - if(kbdin < 0 || kbdout < 0) - sysfatal("failed to get keyboard: %r"); + } memset(backspace, '\b', sizeof backspace-1); backspace[sizeof backspace-1] = '\0'; |