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:
parent
cf91cfea88
commit
edb429ae5d
|
@ -0,0 +1 @@
|
|||
iris-colorize
|
|
@ -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")
|
||||
}))
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
$(dirname $0)/with-iris-news \
|
||||
sh -c "$(echo 'exec /usr/bin/slrn -h "$NNTPSERVER"' "$@")"
|
|
@ -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}")"
|
|
@ -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##*:}" \
|
||||
"$@"
|
Loading…
Reference in New Issue