-
Notifications
You must be signed in to change notification settings - Fork 3
/
vte.go
125 lines (108 loc) · 2.34 KB
/
vte.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
package vte
/*
#include <stdlib.h>
#include <vte/vte.h>
static inline char** make_strings(int count) {
return (char**)malloc(sizeof(char*) * count);
}
static inline void set_string(char** strings, int n, char* str) {
strings[n] = str;
}
*/
// #cgo pkg-config: vte
import "C"
import (
"github.com/mattn/go-gtk/gdk"
"github.com/mattn/go-gtk/gtk"
"unsafe"
)
const (
Black = iota
Red
Green
Yellow
Blue
Magenta
Cyan
White
BlackLight
RedLight
GreenLight
YellowLight
BlueLight
MagentaLight
CyanLight
WhiteLight
)
var MikePal = map[int]string{
Black: "#000000",
BlackLight: "#252525",
Red: "#803232",
RedLight: "#982B2B",
Green: "#85A136",
GreenLight: "#85A136",
Yellow: "#AA9943",
YellowLight: "#EFEF60",
Blue: "#324C80",
BlueLight: "#4186BE",
Magenta: "#706C9A",
MagentaLight: "#826AB1",
Cyan: "#92B19E",
CyanLight: "#A1CDCD",
White: "#E7E7E7",
WhiteLight: "#E7E7E&",
}
type Terminal struct {
gtk.GtkWidget
}
func (v *Terminal) getTerminal() *C.VteTerminal {
return (*C.VteTerminal)(unsafe.Pointer(v.Widget))
}
func (v *Terminal) Feed(m string) {
c := C.CString(m)
defer C.free(unsafe.Pointer(c))
C.vte_terminal_feed(v.getTerminal(), C.CString(m), -1)
}
func (v *Terminal) Fork(args []string) {
cargs := C.make_strings(C.int(len(args)))
for i, j := range args {
ptr := C.CString(j)
defer C.free(unsafe.Pointer(ptr))
C.set_string(cargs, C.int(i), ptr)
}
C.vte_terminal_fork_command_full(v.getTerminal(),
C.VTE_PTY_DEFAULT,
nil,
cargs,
nil,
C.G_SPAWN_SEARCH_PATH,
nil,
nil,
nil, nil)
}
type Palette struct {
}
func (v *Terminal) SetBgColor(s string) {
C.vte_terminal_set_color_background(v.getTerminal(), getColor(s))
}
func (v *Terminal) SetFgColor(s string) {
C.vte_terminal_set_color_foreground(v.getTerminal(), getColor(s))
}
func (v *Terminal) SetColors(pal map[int]string) {
colors := new([16]C.GdkColor)
for i := 0; i < len(colors); i++ {
C.gdk_color_parse((*C.gchar)(C.CString(pal[i])), &colors[i])
}
C.vte_terminal_set_colors(
v.getTerminal(),
nil, nil,
(*C.GdkColor)(unsafe.Pointer(colors)),
16)
}
func NewTerminal() *Terminal {
return &Terminal{*gtk.WidgetFromNative(unsafe.Pointer(C.vte_terminal_new()))}
}
func getColor(s string) *C.GdkColor {
c := gdk.Color(s).Color
return (*C.GdkColor)(unsafe.Pointer(&c))
}