I am new to ii and experimenting and learning. I had the thought, "Why
re-invent the wheel?" Questions and comments are welcome. I am sharing my
thoughts.
For a little program that deals with an in and an out file, like lchat or xii
[1], I need only three features: an out-displayer, an in-sender, and a
combiner. These tools already exist, so no need to write a new GUI or curses
TUI etc.
For the out-displayer, I want these features: scrolling to see all output,
select and copy, notification when out grows. For the in-sender: edit text and
send text to in file. For the combiner: make the out-displayer real big and
put the in-sender real small below it.
For the out-displayer, use "tail -n +0 -f out" in a dvtm window and I get all
the features except notification.
For the in-sender, use "nano -nw in" in a dvtm window. Of course you could
choose a different editor. For the combiner I use dvtm. It allows me to
combine the two components, set their relative size and position. It also
provides scrolling and access to the scrollback buffer, and select and copy and
paste.
So here is the script. Note that my-dvtm is just an extremely simple shell
script that sets a few options that I prefer (e.g. bigger scrollback buffer). I
could not figure out how to make this script work without calling a new
terminal window (st). If I put dvtm into the background (calling dvtm directly
without st) I get all sorts of problems. Is it possible? Any other
improvements could be made to this script?
#!/bin/sh
set -u
[ -d "$1" -a -r "$1"/out -a -p "$1"/in ] || exit 1
cmd_fifo=$(mktemp -u) || exit 1
mkfifo "$cmd_fifo" || exit 1
st -e my-dvtm -c "$cmd_fifo" "nano -nw \"$1/in\"" "tail -n +0 -f \"$1\"/out" &
d="0.09" # dvtm crashes without pausing at leat 0.07 seconds
# I had to customize dvtm to allow these commands to the command fifo, and it
# was very easy to do so. They are based on the keyboard commands.
{
for cmd in b j l l l l l l; do
sleep "$d"
echo "$cmd"
done
} >"$cmd_fifo"
[1] https://tools.suckless.org/ii/usage/