package ncurses import ( "sync/atomic" "github.com/ebitengine/purego" ) var ncurses atomic.Value func ncursesFunction[T any](name string) T { if ncurses.Load() == nil { lib, err := purego.Dlopen(LIBRARY_PATH, purego.RTLD_GLOBAL | purego.RTLD_LAZY) if err != nil { panic(err) } ncurses.CompareAndSwap(nil, lib) } var tmp = new(T) purego.RegisterLibFunc(tmp, ncurses.Load().(uintptr), name) return *tmp } type Window uintptr type voidFP func() int type winFP func(window Window) int type initscrFP func() Window var InitScr = ncursesFunction[initscrFP]("initscr") var EndWin = ncursesFunction[voidFP]("endwin") type newwinFP func(nlines, ncols, begin_x, begin_y 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") type mvwaddstrFP func(window Window, x, y int, str string) int var MvWAddStr = ncursesFunction[mvwaddstrFP]("mvwaddstr")