This repository was archived by the owner on Oct 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstfl.go
100 lines (84 loc) · 2.43 KB
/
stfl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package stfl
/*
#cgo pkg-config: stfl
#cgo LDFLAGS: -lncursesw -lpthread
#include <stdlib.h>
#include <stfl.h>
#include "stfl_wrapper.h"
#include <locale.h>
*/
import "C"
import "unsafe"
type Form C.stfl_form
func Init() {
emptystr := C.CString("")
defer C.free(unsafe.Pointer(emptystr))
C.setlocale(C.LC_ALL, emptystr)
}
func Create(text string) *Form {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
return (*Form)(C.stfl_create_wrapper(ctext))
}
func(form *Form) Free() {
C.stfl_free((*C.stfl_form)(form))
}
func(form *Form) Run(timeout int) string {
return C.GoString(C.stfl_run_wrapper((*C.stfl_form)(form), C.int(timeout)))
}
func Reset() {
C.stfl_reset()
}
func(form *Form) Get(name string) string {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cvalue := C.stfl_get_wrapper((*C.stfl_form)(form), cname)
return C.GoString(cvalue)
}
func(form *Form) Set(name string, value string) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cvalue := C.CString(value)
defer C.free(unsafe.Pointer(cvalue))
C.stfl_set_wrapper((*C.stfl_form)(form), cname, cvalue)
}
func(form *Form) GetFocus() string {
return C.GoString(C.stfl_get_focus_wrapper((*C.stfl_form)(form)))
}
func(form *Form) SetFocus(name string) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
C.stfl_set_focus_wrapper((*C.stfl_form)(form), cname)
}
func Quote(text string) string {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
return C.GoString(C.stfl_quote_wrapper(ctext))
}
func(form *Form) Modify(name string, mode string, text string) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cmode := C.CString(mode)
defer C.free(unsafe.Pointer(cmode))
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
C.stfl_modify_wrapper((*C.stfl_form)(form), cname, cmode, ctext)
}
func(form *Form) Lookup(path string, newname string) string {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
cnewname := C.CString(newname)
defer C.free(unsafe.Pointer(cnewname))
return C.GoString(C.stfl_lookup_wrapper((*C.stfl_form)(form), cpath, cnewname))
}
func(form *Form) Dump(name string, prefix string, focus bool) string {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cprefix := C.CString(prefix)
defer C.free(unsafe.Pointer(cprefix))
cfocus := 0
if focus {
cfocus = 1
}
return C.GoString(C.stfl_dump_wrapper((*C.stfl_form)(form), cname, cprefix, C.int(cfocus)))
}