124 lines
3.5 KiB
Go
124 lines
3.5 KiB
Go
package ncurses
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/ebitengine/purego"
|
|
)
|
|
|
|
var ncurses uintptr = 0
|
|
func ncursesFunction[T any](name string) T {
|
|
if ncurses == 0 {
|
|
var err error
|
|
ncurses, err = purego.Dlopen(LIBRARY_PATH, purego.RTLD_GLOBAL | purego.RTLD_LAZY)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
var tmp = new(T)
|
|
purego.RegisterLibFunc(tmp, ncurses, name)
|
|
return *tmp
|
|
}
|
|
|
|
func ncursesSymbol[T any](name string) *T {
|
|
if ncurses == 0 {
|
|
var err error
|
|
ncurses, err = purego.Dlopen(LIBRARY_PATH, purego.RTLD_GLOBAL | purego.RTLD_LAZY)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
sym, err := purego.Dlsym(ncurses, name)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return (*T)(unsafe.Pointer(sym))
|
|
}
|
|
|
|
type Window uintptr
|
|
|
|
type voidFP func() int
|
|
type winFP func(window Window) int
|
|
|
|
var WGetCh = ncursesFunction[winFP]("wgetch")
|
|
|
|
type initscrFP func() Window
|
|
var InitScr = ncursesFunction[initscrFP]("initscr")
|
|
var EndWin = ncursesFunction[voidFP]("endwin")
|
|
|
|
type newwinFP func(nlines, ncols, begin_y, begin_x int) Window
|
|
var NewWin = ncursesFunction[newwinFP]("newwin")
|
|
var DelWin = ncursesFunction[winFP]("delwin")
|
|
type dupwinFP func(window Window) Window
|
|
var DupWin = ncursesFunction[dupwinFP]("dupwin")
|
|
|
|
var Refresh = ncursesFunction[voidFP]("refresh")
|
|
var WRefresh = ncursesFunction[winFP]("wrefresh")
|
|
var WNOutRefresh = ncursesFunction[winFP]("wnoutrefresh")
|
|
var DoUpdate = ncursesFunction[voidFP]("doupdate")
|
|
|
|
type waddstrFP func(window Window, str string) int
|
|
var WAddStr = ncursesFunction[waddstrFP]("waddstr")
|
|
|
|
type waddnstrFP func(window Window, str string, n int) int
|
|
var WAddNStr = ncursesFunction[waddstrFP]("waddnstr")
|
|
|
|
var GetMaxY = ncursesFunction[winFP]("getmaxy")
|
|
var GetMaxX = ncursesFunction[winFP]("getmaxx")
|
|
|
|
var WClear = ncursesFunction[winFP]("wclear")
|
|
|
|
type mvwaddstrFP func(window Window, y, x int, str string) int
|
|
var MvWAddStr = ncursesFunction[mvwaddstrFP]("mvwaddstr")
|
|
|
|
type mvwaddchFP func(window Window, y, x int, char uint32) int
|
|
var MvWAddCh = ncursesFunction[mvwaddchFP]("mvwaddch")
|
|
|
|
type waddchFP func(window Window, char uint32) int
|
|
var WAddCh = ncursesFunction[waddchFP]("waddch")
|
|
|
|
type init_colorFP func(color, r, g, b int16) int
|
|
var InitColor = ncursesFunction[init_colorFP]("init_color")
|
|
|
|
type init_pairFP func(pair, fg, bg int16) int
|
|
var InitPair = ncursesFunction[init_pairFP]("init_pair")
|
|
|
|
var StartColor = ncursesFunction[voidFP]("start_color")
|
|
|
|
type checkFP func() bool
|
|
var HasColors = ncursesFunction[checkFP]("has_colors")
|
|
|
|
type setflagFP func(window Window, bf bool) int
|
|
var ClearOK = ncursesFunction[setflagFP]("clearok")
|
|
var IdlOK = ncursesFunction[setflagFP]("idlok")
|
|
var ScrollOk = ncursesFunction[setflagFP]("scrollok")
|
|
var NoDelay = ncursesFunction[setflagFP]("nodelay")
|
|
|
|
type idcokFP func(window Window, bf bool)
|
|
var IdcOK = ncursesFunction[idcokFP]("idcok")
|
|
|
|
type wscrlFP func(window Window, n int) int
|
|
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")
|
|
|
|
type wyxFP func(window Window, y, x int) int
|
|
var WMove = ncursesFunction[wyxFP]("wmove")
|
|
var WResize = ncursesFunction[wyxFP]("wresize")
|
|
var MvWin = ncursesFunction[wyxFP]("mvwin")
|
|
|
|
var StdScr = ncursesSymbol[Window]("stdscr")
|
|
var CurScr = ncursesSymbol[Window]("curscr")
|
|
|
|
type restarttermFP func(term string, fd int, errret *int) int
|
|
var RestartTerm = ncursesFunction[restarttermFP]("restartterm")
|