From e345e72ff0e54e5c25271223849cad34ce8620b3 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Wed, 24 Apr 2024 01:18:32 -0600 Subject: [PATCH] Added constants --- libc.go | 2 +- ncurses.go | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/libc.go b/libc.go index 6a01ce1..34db39f 100644 --- a/libc.go +++ b/libc.go @@ -19,5 +19,5 @@ func libcFunction[T any](name string) T { return *tmp } -type setlocaleFP func(category int, locale string) +type setlocaleFP func(category int, locale string) string var SetLocale = libcFunction[setlocaleFP]("setlocale") diff --git a/ncurses.go b/ncurses.go index 5b60083..8562dd3 100644 --- a/ncurses.go +++ b/ncurses.go @@ -1,6 +1,8 @@ package ncurses import ( + "unsafe" + "github.com/ebitengine/purego" ) @@ -19,16 +21,35 @@ func ncursesFunction[T any](name string) T { 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_x, begin_y int) Window +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 @@ -48,6 +69,8 @@ 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") @@ -72,6 +95,10 @@ 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") @@ -83,3 +110,14 @@ 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")