1 II_DIR="$HOME/.cache/irc"
3 FULLNAME="$USER + ii (tools.suckless.org/ii)"
7 # Prompt for server to connect to and maintain ii connection active
11 host="$(find . -maxdepth 1 -mindepth 1 -type d | cut -c 3- |
12 iomenu -p 'host' -l 10)"
15 nohup ii -i . -s "${host#./}" -p 6667 -n "$USER" &> errors
26 # Interactively prompt for a channel to connect to, and change the tail
31 find . -mindepth 1 -type d | cut -c 3- | iomenu -p '#' -l 10 > channel
35 IFS='' read -r channel < channel
36 [ -f "$channel/out" ] && tail -f -n 0 "$channel/out" | print_lines &
41 # Read one character from /dev/tty in raw mode.
46 dd if=/dev/tty count=1 status=none
52 # Manage characters typed by user.
61 while char="$(get_char)"
65 printf '%s' "$char" >> input
68 "$(printf '\020')" | "$(printf '\016')" ) # Ctrl-P | Ctrl-N
69 killall -q tail #FIXME this kills ALL running tail
73 "$(printf '\023')" ) # Ctrl-S
77 "$(printf '\033')" | "$(printf '\003')" ) # Escape | Ctrl-C
81 "$(printf '\015')" ) # Ctrl-M | Enter
82 IFS='' read -r channel < channel
83 sed 's/$/\n/' input > "$channel/in"
87 "$(printf '\025')" ) # Ctrl-U
91 "$(printf '\027')" ) # Ctrl-W
92 sed -i 's/[^ \t]* *$//' input
95 "$(printf '\010')" | "$(printf '\177')" ) # Ctrl-H | Backspace
99 "$(printf '\014')" ) # Ctrl-L
100 IFS='' read -r channel < channel
112 # Print a prompt with the current input
116 IFS='' read -r channel < channel
117 IFS='' read -r input < input
119 printf '\r\033[K%s> %s' "$channel" "$input"
124 # Update the buffer lines and prompt
128 local col="$(stty size)"; col="${col#* }"
130 printf '\033[2J;\033[0;0H'
134 IFS='' read -r channel < channel
135 [ -f "$channel/out" ] && tail -n "$col" "$channel/out"
144 # Print lines after formatting them and update the prompt.
148 while IFS='' read -r line
150 printf '\r\033[K%s\n' "$line"
162 trap 'update_screen' SIGWINCH
163 trap 'stty sane; killall tail' EXIT