Re: [dev] a terminal transformer, analogous to a unix filter

From: Steffen Nurpmeso <steffen_AT_sdaoden.eu>
Date: Sat, 14 Sep 2024 00:02:28 +0200

Rodrigo Martins wrote in
 <ZuRDTxKD39TKAvPp_AT_firemail.cc>:
 |It was thus said that the Great Greg Reagle once stated:
 |> I have coined the phrase terminal transformer for a class of programs
 |> like tmux, dvtm, tcvt, and splitvt. Perhaps there is already a phrase.
 |> A terminal transformer runs on top of a terminal emulator and acts as
 |> a terminal emulator itself, with an application like nano running on
 |> top of it. In other words, it uses a terminal emulator and is used
 |> as a terminal emulator.
 |>
 |> I would like to experiment with a completely transparent transformer as
 |> a starting point. A transparent transformer passes through everything.
 |> Ideally it does nothing. Just as a--not useful--example, if I want
 |> hitting the left cursor key to move the cursor left then right then left
 |> again, I can add code to intercept that escape sequence and program it
 |> to do that. That is how I imagine experimenting with more sophisticated
 |> and useful transformations.
 |>
 |> I would like some guidance on developing a program that is a transparent
 |> terminal transformer in a way that is as simple and stupid as possible.

dtach.

  #?0|kent:dwm.git$ prt-get info dtach
  Name: dtach
  Version: 0.9
  Release: 3
  Description: Emulates the detach feature of screen.
  URL: https://github.com/crigler/dtach

  #?0|kent:dwm.git$ ldd /usr/bin/dtach
          linux-vdso.so.1 (0x00007fffe5b62000)
          libc.so.6 => /lib/libc.so.6 (0x00007f23accfd000)
          /lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f23acef6000)

I use it on the (v)server to drive the IRC proxy:

          mkfifo -m 0666 ${rundir}/root/linger_control

          cat > ${rundir}/root/init <<_EOT
  #!/bin/sh -

  [ -n "${BUSYBOX}" ] && /bin/mount -n -t proc -o nosuid,nodev,noexec proc /proc

  if [ -n "${SUPER_IS_DOAS}" ]; then
          arg1="-u ${boxuser}"
          arg2=
  else
          arg1='-p -c'
          arg2=${boxuser}
  fi

  exec ${SUPER} \${arg1} sh -c '
          dtach -n /tmp/.${boxuser}-irssi ${irssi}
          read x < /linger_control
          pkill -TERM ${irssi}
          sleep 1
          pgrep ${irssi} && pkill -KILL ${irssi}
          echo done > /linger_control
  ' \${arg2}
  _EOT

Ie this runs "boxed":

  ip netns exec ${netns} \
          /usr/bin/env -i TERM=${TERM} \
                  /usr/bin/unshare --ipc --uts --pid --fork --mount --mount-proc \
                          ${kill_child} ${rooter} /init </dev/null >/dev/null 2>&1 &
  pid=${!}
  [ -d /sys/fs/cgroup/_box_ircproxy ] && printf '%s\n' ${pid} > /sys/fs/cgroup/_box_ircproxy/cgroup.procs

It is pretty cool in that i usually access this proxy from my
laptop's irssi and have IRC as one would expect, but i can also
ssh into the box and then enter the irssi running via dtach via
dtach. (This is good because the local irssi does not see
anything the "real irssi" aka the proxy sees.

Anyhow, dtach is super old and super stable and i thankfully think
of the Japanese user (who, one could believe, also listens here)
who mentions this program to me.
Last commit in 2017 (https://github.com/crigler/dtach.git).

--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
Received on Sat Sep 14 2024 - 00:02:28 CEST

This archive was generated by hypermail 2.3.0 : Sat Sep 14 2024 - 00:12:08 CEST