forked from rthornton128/goncurses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slk.go
136 lines (115 loc) · 3.53 KB
/
slk.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// goncurses - ncurses library for Go.
// Copyright 2011 Rob Thornton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package goncurses
// #include <stdlib.h>
// #include <curses.h>
import "C"
import (
"errors"
"unsafe"
)
type SlkFormat byte
const (
SLK_323 SlkFormat = iota // 8 labels; 3-2-3 arrangement
SLK_44 // 8 labels; 4-4 arrangement
SLK_PC444 // 12 labels; 4-4-4 arrangement
SLK_PC444INDEX // 12 labels; 4-4-4 with index line
)
type SlkJustify byte
const (
SLK_LEFT SlkJustify = iota
SLK_CENTER
SLK_RIGHT
)
// Initializes the soft-key labels with the given format; keys like the
// F1-F12 keys on most keyboards. After a call to SlkRefresh a bar at the
// bottom of the standard screen returned by Init will be displayed. This
// function MUST be called prior to Init()
func SlkInit(f SlkFormat) {
C.slk_init(C.int(f))
}
// SlkSet sets the 'labnum' text to the supplied 'label'. Labels must not
// be greater than 8 characters
func SlkSet(labnum int, label string, just SlkJustify) error {
cstr := C.CString(label)
defer C.free(unsafe.Pointer(cstr))
if C.slk_set(C.int(labnum), (*C.char)(cstr), C.int(just)) == C.ERR {
return errors.New("Soft-keys or terminal not initialized")
}
return nil
}
// SlkRefresh behaves the same as Window.Refresh. Most applications would use
// SlkNoutRefresh because a Window.Refresh is likely to follow
func SlkRefresh() error {
if C.slk_refresh() == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkNoutFresh behaves like Window.NoutRefresh
func SlkNoutRefresh() error {
if C.slk_noutrefresh() == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkLabel returns the label for the given key
func SlkLabel(labnum int) string {
return C.GoString(C.slk_label(C.int(labnum)))
}
// SlkClear removes the soft-key labels from the screen
func SlkClear() error {
if C.slk_clear() == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkRestore restores the soft-key labels to the screen after an SlkClear()
func SlkRestore() error {
if C.slk_restore() == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkTouch behaves just like Window.Touch
func SlkTouch() error {
if C.slk_touch() == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkColor sets the color pair for the soft-keys
func SlkColor(cp int16) error {
if C.slk_color(C.short(cp)) == C.ERR {
return errors.New("Invalid color pair or soft-keys not initialized.")
}
return nil
}
/* TODO: Not available in PDCurses
// SlkAttribute returns the currently set attributes
func SlkAttribute() Char {
return Char(C.slk_attr())
}*/
// SlkSetAttribute sets the OR'd attributes to use
func SlkSetAttribute(attr Char) error {
if C.slk_attrset(C.chtype(attr)) == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkAttributeOn turns on the given OR'd attributes without turning any off
func SlkAttributeOn(attr Char) error {
if C.slk_attron(C.chtype(attr)) == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}
// SlkAttributeOff turns off the given OR'd attributes without turning any on
func SlkAttributeOff(attr Char) error {
if C.slk_attroff(C.chtype(attr)) == C.ERR {
return errors.New("Soft-keys or terminal not initialized.")
}
return nil
}