go-ncurses/examples/basic.go

70 lines
1.1 KiB
Go

package main
import (
"os"
"os/signal"
"syscall"
"git.metznet.ca/MetzNet/go-ncurses"
)
func main() {
ncurses.SetLocale(0, "")
input, input_active := ncurses.UTF8Listener(100, os.Stdin)
os_sigs := make(chan os.Signal, 1)
signal.Notify(os_sigs, syscall.SIGINT, syscall.SIGABRT)
window := ncurses.InitScr()
2024-04-23 22:24:38 -06:00
ret := ncurses.StartColor()
if ret != 0 {
panic(ret)
}
2024-04-23 22:24:38 -06:00
ret = ncurses.InitColor(1, 1000, 0, 0)
if ret != 0 {
panic(ret)
}
ret = ncurses.InitColor(2, 0, 1000, 0)
if ret != 0 {
panic(ret)
}
ret = ncurses.InitPair(1, 1, 2)
if ret != 0 {
panic(ret)
}
ncurses.WBkgd(window, ncurses.COLOR_PAIR(1))
ret = ncurses.IdlOK(window, true)
if ret != 0 {
panic(ret)
}
ret = ncurses.ScrollOk(window, true)
if ret != 0 {
panic(ret)
}
2024-04-23 22:24:38 -06:00
ncurses.WRefresh(window)
active := true
for active {
select {
case bytes := <-input:
2024-04-23 22:24:38 -06:00
for _, b := range(bytes) {
ncurses.WAddCh(window, uint32(b))
}
ncurses.WRefresh(window)
case <-os_sigs:
active = false
}
}
ncurses.EndWin()
input_active.Store(false)
close(input)
}