55
package main
import (
"fmt"
"git.sophuwu.com/rbprompt"
"os"
)
func Err(err *error) func() {
if err == nil {
fmt.Println("null pointer given to error handler")
os.Exit(1)
}
return func() {
if *err != nil {
fmt.Println(*err)
os.Exit(1)
}
}
}
func main() {
var err error
chk := Err(&err)
var ps rbprompt.PS
ps.NoColor = false
ps.LineNo = 0
ps.User = "sophie"
ps.HostName = "sophuwu.com"
ps.HostIP = [4]byte{217, 160, 162, 187}
ps.Home = "/home/sophie"
ps.PWD = "/home/sophie/.local/share/applications"
fmt.Printf("testing as: %s@%s\nin: %s\n", ps.User, ps.HostName, ps.PWD)
for _, v := range []string{
"%i %l %e %u @ %h %p $ ",
"%e %l %u @ %h %2p $ ",
"%e %l %u#ff4500 @ %h %2p#ff00ff $ ",
"%l %u %2p $ ",
} {
ps.Fmt = v
err = ps.Next()
chk()
fmt.Printf("\nFmt: \"%s\"\n%s\n", ps.Fmt, ps.String())
}
err = ps.Next()
chk()
ps.PWD = "/usr/local/share/man"
fmt.Printf("\nFmt: \"%s\"\n%scd %s\n", ps.Fmt, ps.String(), ps.PWD)
ps.Fmt = "%l %u %p#ff00ff $ "
err = ps.Next()
chk()
fmt.Printf("\nFmt: \"%s\"\n%s\n", ps.Fmt, ps.String())
}