Added support scripts.

- iris-colorize is a go executable which resolves {r iris colors} to
  ANSI escape sequences
- with-iris-news is a shell script which starts up an iris-news server,
  executes "$@" with environment vars providing its location, and shuts
  down the server once the foreground application closes
- iris-tin run /usr/bin/tin under with-iris-news
- iris-slrn runs /usr/bin/slrn under with-iris-news
This commit is contained in:
TJP 2023-02-11 11:01:42 -07:00
parent cf91cfea88
commit edb429ae5d
5 changed files with 88 additions and 0 deletions

1
iris-colorize/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
iris-colorize

59
iris-colorize/main.go Normal file
View File

@ -0,0 +1,59 @@
package main
import (
"fmt"
"io"
"log"
"os"
"regexp"
"sort"
"strings"
)
var (
delimRE = regexp.MustCompile(`\\\{|\{[niuvrgybmcw]+\s|\\\}|\}`)
colorMap = map[byte]byte{
'n': 0,
'i': 1,
'u': 4,
'v': 7,
'r': 31,
'g': 32,
'y': 33,
'b': 34,
'm': 35,
'c': 36,
'w': 37,
}
)
func main() {
src, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
_, _ = os.Stdout.Write(delimRE.ReplaceAllFunc(src, func(b []byte) []byte {
switch b[0] {
case '\\':
return []byte{b[1]}
case '}':
return []byte("\033[0m")
case '{':
mods := make([]byte, len(b)-2)
for i, c := range b[1 : len(b)-1] {
mods[i] = colorMap[c]
}
sort.Slice(mods, func(i, j int) bool { return mods[i] < mods[j] })
codes := make([]string, len(mods))
for i, c := range mods {
codes[i] = fmt.Sprintf("%d", c)
}
return []byte("\033[" + strings.Join(codes, ";") + "m")
}
panic("unreachable")
}))
}

4
script/iris-slrn Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
$(dirname $0)/with-iris-news \
sh -c "$(echo 'exec /usr/bin/slrn -h "$NNTPSERVER"' "$@")"

4
script/iris-tin Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
$(dirname $0)/with-iris-news \
sh -c "$(echo 'exec /usr/bin/tin -r -g "$NNTPHOST" -p "$NNTPPORT"' "${@:-ctrl-c.iris}")"

20
script/with-iris-news Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
$(dirname $0)/iris-news >/dev/null 2>&1 &
serverpid="$!"
sleep 1
addr="$(cat ~/.iris-news-server)"
function cleanup {
kill $serverpid
rm ~/.iris-news-server
tail --pid $serverpid -f /dev/null
}
trap cleanup EXIT
env \
NNTPSERVER="$addr" \
NNTPHOST="${addr%%:*}" \
NNTPPORT="${addr##*:}" \
"$@"