Added background setting

main
noah metz 2024-04-23 22:24:38 -06:00
parent 5032b04a47
commit 2cc4fbed5c
3 changed files with 46 additions and 8 deletions

@ -16,21 +16,47 @@ func main() {
signal.Notify(os_sigs, syscall.SIGINT, syscall.SIGABRT) signal.Notify(os_sigs, syscall.SIGINT, syscall.SIGABRT)
window := ncurses.InitScr() window := ncurses.InitScr()
ret := ncurses.IdlOK(window, true) ret := ncurses.StartColor()
if ret != 0 { if ret != 0 {
panic(ret) panic(ret)
} }
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) ret = ncurses.ScrollOk(window, true)
if ret != 0 { if ret != 0 {
panic(ret) panic(ret)
} }
ncurses.WRefresh(window) ncurses.WRefresh(window)
active := true active := true
for active { for active {
select { select {
case bytes := <-input: case bytes := <-input:
ncurses.WAddStr(window, string(bytes)) for _, b := range(bytes) {
ncurses.WAddCh(window, uint32(b))
}
ncurses.WRefresh(window) ncurses.WRefresh(window)
case <-os_sigs: case <-os_sigs:
active = false active = false

@ -13,18 +13,23 @@ func bitmatch(b byte, pattern byte, length int) bool {
func UTF8Listen(file *os.File, channel chan []byte, active *atomic.Bool) { func UTF8Listen(file *os.File, channel chan []byte, active *atomic.Bool) {
b := [4]byte{} b := [4]byte{}
for active.Load() { for active.Load() {
out := make([]byte, 4)
file.Read(b[0:1]) file.Read(b[0:1])
if bitmatch(b[0], 0b00000000, 1) { if bitmatch(b[0], 0b00000000, 1) {
channel <- b[0:1] copy(out, b[0:1])
channel <- out[0:1]
} else if bitmatch(b[0], 0b11000000, 3) { } else if bitmatch(b[0], 0b11000000, 3) {
file.Read(b[1:2]) file.Read(b[1:2])
channel <- b[0:2] copy(out, b[0:2])
channel <- out[0:2]
} else if bitmatch(b[0], 0b11100000, 4) { } else if bitmatch(b[0], 0b11100000, 4) {
file.Read(b[1:3]) file.Read(b[1:3])
channel <- b[0:3] copy(out, b[0:3])
channel <- out[0:3]
} else if bitmatch(b[0], 0b11110000, 5) { } else if bitmatch(b[0], 0b11110000, 5) {
file.Read(b[1:4]) file.Read(b[1:4])
channel <- b[0:4] copy(out, b[0:4])
channel <- out[0:4]
} }
} }
} }

@ -51,10 +51,10 @@ var GetMaxX = ncursesFunction[winFP]("getmaxx")
type mvwaddstrFP func(window Window, y, x int, str string) int type mvwaddstrFP func(window Window, y, x int, str string) int
var MvWAddStr = ncursesFunction[mvwaddstrFP]("mvwaddstr") var MvWAddStr = ncursesFunction[mvwaddstrFP]("mvwaddstr")
type mvwaddchFP func(window Window, y, x int, char rune) int type mvwaddchFP func(window Window, y, x int, char uint32) int
var MvWAddCh = ncursesFunction[mvwaddchFP]("mvwaddch") var MvWAddCh = ncursesFunction[mvwaddchFP]("mvwaddch")
type waddchFP func(window Window, char rune) int type waddchFP func(window Window, char uint32) int
var WAddCh = ncursesFunction[waddchFP]("waddch") var WAddCh = ncursesFunction[waddchFP]("waddch")
type init_colorFP func(color, r, g, b int16) int type init_colorFP func(color, r, g, b int16) int
@ -76,3 +76,10 @@ var ScrollOk = ncursesFunction[setflagFP]("scrollok")
type wscrlFP func(window Window, n int) int type wscrlFP func(window Window, n int) int
var WScrl = ncursesFunction[wscrlFP]("wscrl") var WScrl = ncursesFunction[wscrlFP]("wscrl")
type colorpairFP func(pair int) uint32
var COLOR_PAIR = ncursesFunction[colorpairFP]("COLOR_PAIR")
type wuintFP func(Window, uint32) uint32
var WAttrOn = ncursesFunction[wuintFP]("wattron")
var WAttrOff = ncursesFunction[wuintFP]("wattroff")
var WBkgd = ncursesFunction[wuintFP]("wbkgd")