bubblezone 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +347 -16
- data/bubblezone.gemspec +2 -0
- data/ext/bubblezone/extconf.rb +65 -0
- data/ext/bubblezone/extension.c +107 -0
- data/ext/bubblezone/extension.h +36 -0
- data/ext/bubblezone/manager.c +127 -0
- data/ext/bubblezone/zone_info.c +100 -0
- data/go/bubblezone.go +369 -0
- data/go/go.mod +28 -0
- data/go/go.sum +47 -0
- data/lib/bubblezone/manager.rb +56 -0
- data/lib/bubblezone/version.rb +1 -1
- data/lib/bubblezone/zone_info.rb +25 -0
- data/lib/bubblezone.rb +52 -1
- metadata +14 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void manager_free(void *pointer) {
|
|
4
|
+
bubblezone_manager_t *manager = (bubblezone_manager_t *)pointer;
|
|
5
|
+
|
|
6
|
+
if (manager->handle != 0) {
|
|
7
|
+
bubblezone_free_manager(manager->handle);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
xfree(manager);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static size_t manager_memsize(const void *pointer) {
|
|
14
|
+
return sizeof(bubblezone_manager_t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rb_data_type_t manager_type = {
|
|
18
|
+
.wrap_struct_name = "Bubblezone::Manager",
|
|
19
|
+
.function = {
|
|
20
|
+
.dmark = NULL,
|
|
21
|
+
.dfree = manager_free,
|
|
22
|
+
.dsize = manager_memsize,
|
|
23
|
+
},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static VALUE manager_alloc(VALUE klass) {
|
|
28
|
+
bubblezone_manager_t *manager = ALLOC(bubblezone_manager_t);
|
|
29
|
+
manager->handle = bubblezone_new_manager();
|
|
30
|
+
return TypedData_Wrap_Struct(klass, &manager_type, manager);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
VALUE manager_wrap(VALUE klass, unsigned long long handle) {
|
|
34
|
+
bubblezone_manager_t *manager = ALLOC(bubblezone_manager_t);
|
|
35
|
+
manager->handle = handle;
|
|
36
|
+
return TypedData_Wrap_Struct(klass, &manager_type, manager);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static VALUE manager_initialize(VALUE self) {
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE manager_close(VALUE self) {
|
|
44
|
+
GET_MANAGER(self, manager);
|
|
45
|
+
bubblezone_manager_close(manager->handle);
|
|
46
|
+
return Qnil;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static VALUE manager_set_enabled(VALUE self, VALUE enabled) {
|
|
50
|
+
GET_MANAGER(self, manager);
|
|
51
|
+
bubblezone_manager_set_enabled(manager->handle, RTEST(enabled) ? 1 : 0);
|
|
52
|
+
return enabled;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static VALUE manager_enabled(VALUE self) {
|
|
56
|
+
GET_MANAGER(self, manager);
|
|
57
|
+
return bubblezone_manager_enabled(manager->handle) ? Qtrue : Qfalse;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static VALUE manager_new_prefix(VALUE self) {
|
|
61
|
+
GET_MANAGER(self, manager);
|
|
62
|
+
|
|
63
|
+
char *prefix = bubblezone_manager_new_prefix(manager->handle);
|
|
64
|
+
VALUE rb_prefix = rb_utf8_str_new_cstr(prefix);
|
|
65
|
+
bubblezone_free(prefix);
|
|
66
|
+
|
|
67
|
+
return rb_prefix;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static VALUE manager_mark(VALUE self, VALUE zone_id, VALUE text) {
|
|
71
|
+
GET_MANAGER(self, manager);
|
|
72
|
+
Check_Type(zone_id, T_STRING);
|
|
73
|
+
Check_Type(text, T_STRING);
|
|
74
|
+
|
|
75
|
+
char *result = bubblezone_manager_mark(manager->handle, StringValueCStr(zone_id), StringValueCStr(text));
|
|
76
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
77
|
+
bubblezone_free(result);
|
|
78
|
+
|
|
79
|
+
return rb_result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE manager_clear(VALUE self, VALUE zone_id) {
|
|
83
|
+
GET_MANAGER(self, manager);
|
|
84
|
+
Check_Type(zone_id, T_STRING);
|
|
85
|
+
bubblezone_manager_clear(manager->handle, StringValueCStr(zone_id));
|
|
86
|
+
return Qnil;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static VALUE manager_get(VALUE self, VALUE zone_id) {
|
|
90
|
+
GET_MANAGER(self, manager);
|
|
91
|
+
Check_Type(zone_id, T_STRING);
|
|
92
|
+
|
|
93
|
+
unsigned long long handle = bubblezone_manager_get(manager->handle, StringValueCStr(zone_id));
|
|
94
|
+
|
|
95
|
+
if (handle == 0) {
|
|
96
|
+
return Qnil;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return zone_info_wrap(cZoneInfo, handle);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static VALUE manager_scan(VALUE self, VALUE text) {
|
|
103
|
+
GET_MANAGER(self, manager);
|
|
104
|
+
Check_Type(text, T_STRING);
|
|
105
|
+
|
|
106
|
+
char *result = bubblezone_manager_scan(manager->handle, StringValueCStr(text));
|
|
107
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
108
|
+
bubblezone_free(result);
|
|
109
|
+
|
|
110
|
+
return rb_result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void Init_bubblezone_manager(void) {
|
|
114
|
+
cManager = rb_define_class_under(mBubblezone, "Manager", rb_cObject);
|
|
115
|
+
|
|
116
|
+
rb_define_alloc_func(cManager, manager_alloc);
|
|
117
|
+
|
|
118
|
+
rb_define_method(cManager, "initialize", manager_initialize, 0);
|
|
119
|
+
rb_define_method(cManager, "close", manager_close, 0);
|
|
120
|
+
rb_define_method(cManager, "enabled=", manager_set_enabled, 1);
|
|
121
|
+
rb_define_method(cManager, "enabled?", manager_enabled, 0);
|
|
122
|
+
rb_define_method(cManager, "new_prefix", manager_new_prefix, 0);
|
|
123
|
+
rb_define_method(cManager, "mark", manager_mark, 2);
|
|
124
|
+
rb_define_method(cManager, "clear", manager_clear, 1);
|
|
125
|
+
rb_define_method(cManager, "get", manager_get, 1);
|
|
126
|
+
rb_define_method(cManager, "scan", manager_scan, 1);
|
|
127
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void zone_info_free(void *pointer) {
|
|
4
|
+
bubblezone_zone_info_t *zone_info = (bubblezone_zone_info_t *)pointer;
|
|
5
|
+
|
|
6
|
+
if (zone_info->handle != 0) {
|
|
7
|
+
bubblezone_free_zone_info(zone_info->handle);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
xfree(zone_info);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static size_t zone_info_memsize(const void *pointer) {
|
|
14
|
+
return sizeof(bubblezone_zone_info_t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rb_data_type_t zone_info_type = {
|
|
18
|
+
.wrap_struct_name = "Bubblezone::ZoneInfo",
|
|
19
|
+
.function = {
|
|
20
|
+
.dmark = NULL,
|
|
21
|
+
.dfree = zone_info_free,
|
|
22
|
+
.dsize = zone_info_memsize,
|
|
23
|
+
},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
VALUE zone_info_wrap(VALUE klass, unsigned long long handle) {
|
|
29
|
+
bubblezone_zone_info_t *zone_info = ALLOC(bubblezone_zone_info_t);
|
|
30
|
+
zone_info->handle = handle;
|
|
31
|
+
return TypedData_Wrap_Struct(klass, &zone_info_type, zone_info);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static VALUE zone_info_start_x(VALUE self) {
|
|
35
|
+
GET_ZONE_INFO(self, zone_info);
|
|
36
|
+
return INT2NUM(bubblezone_zone_info_start_x(zone_info->handle));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static VALUE zone_info_start_y(VALUE self) {
|
|
40
|
+
GET_ZONE_INFO(self, zone_info);
|
|
41
|
+
return INT2NUM(bubblezone_zone_info_start_y(zone_info->handle));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static VALUE zone_info_end_x(VALUE self) {
|
|
45
|
+
GET_ZONE_INFO(self, zone_info);
|
|
46
|
+
return INT2NUM(bubblezone_zone_info_end_x(zone_info->handle));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static VALUE zone_info_end_y(VALUE self) {
|
|
50
|
+
GET_ZONE_INFO(self, zone_info);
|
|
51
|
+
return INT2NUM(bubblezone_zone_info_end_y(zone_info->handle));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static VALUE zone_info_is_zero(VALUE self) {
|
|
55
|
+
GET_ZONE_INFO(self, zone_info);
|
|
56
|
+
return bubblezone_zone_info_is_zero(zone_info->handle) ? Qtrue : Qfalse;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static VALUE zone_info_in_bounds(VALUE self, VALUE x, VALUE y) {
|
|
60
|
+
GET_ZONE_INFO(self, zone_info);
|
|
61
|
+
Check_Type(x, T_FIXNUM);
|
|
62
|
+
Check_Type(y, T_FIXNUM);
|
|
63
|
+
|
|
64
|
+
return bubblezone_zone_info_in_bounds(zone_info->handle, NUM2INT(x), NUM2INT(y)) ? Qtrue : Qfalse;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE zone_info_pos(VALUE self, VALUE x, VALUE y) {
|
|
68
|
+
GET_ZONE_INFO(self, zone_info);
|
|
69
|
+
Check_Type(x, T_FIXNUM);
|
|
70
|
+
Check_Type(y, T_FIXNUM);
|
|
71
|
+
|
|
72
|
+
int out_x, out_y;
|
|
73
|
+
int success = bubblezone_zone_info_pos(zone_info->handle, NUM2INT(x), NUM2INT(y), &out_x, &out_y);
|
|
74
|
+
|
|
75
|
+
if (!success) {
|
|
76
|
+
return rb_ary_new_from_args(2, INT2NUM(-1), INT2NUM(-1));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return rb_ary_new_from_args(2, INT2NUM(out_x), INT2NUM(out_y));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE zone_info_alloc_error(VALUE klass) {
|
|
83
|
+
rb_raise(rb_eTypeError, "allocator undefined for Bubblezone::ZoneInfo - use Manager#get instead");
|
|
84
|
+
return Qnil;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void Init_bubblezone_zone_info(void) {
|
|
88
|
+
cZoneInfo = rb_define_class_under(mBubblezone, "ZoneInfo", rb_cObject);
|
|
89
|
+
|
|
90
|
+
rb_define_alloc_func(cZoneInfo, zone_info_alloc_error);
|
|
91
|
+
rb_undef_method(rb_singleton_class(cZoneInfo), "new");
|
|
92
|
+
|
|
93
|
+
rb_define_method(cZoneInfo, "start_x", zone_info_start_x, 0);
|
|
94
|
+
rb_define_method(cZoneInfo, "start_y", zone_info_start_y, 0);
|
|
95
|
+
rb_define_method(cZoneInfo, "end_x", zone_info_end_x, 0);
|
|
96
|
+
rb_define_method(cZoneInfo, "end_y", zone_info_end_y, 0);
|
|
97
|
+
rb_define_method(cZoneInfo, "zero?", zone_info_is_zero, 0);
|
|
98
|
+
rb_define_method(cZoneInfo, "in_bounds?", zone_info_in_bounds, 2);
|
|
99
|
+
rb_define_method(cZoneInfo, "pos", zone_info_pos, 2);
|
|
100
|
+
}
|
data/go/bubblezone.go
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
*/
|
|
6
|
+
import "C"
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"runtime/debug"
|
|
10
|
+
"sync"
|
|
11
|
+
"unsafe"
|
|
12
|
+
zone "github.com/lrstanley/bubblezone"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
var (
|
|
16
|
+
nextID uint64 = 1
|
|
17
|
+
nextIDMu sync.Mutex
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
func getNextID() uint64 {
|
|
21
|
+
nextIDMu.Lock()
|
|
22
|
+
defer nextIDMu.Unlock()
|
|
23
|
+
id := nextID
|
|
24
|
+
nextID++
|
|
25
|
+
return id
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var (
|
|
29
|
+
managers = make(map[uint64]*zone.Manager)
|
|
30
|
+
managersMu sync.RWMutex
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
func allocManager(m *zone.Manager) uint64 {
|
|
34
|
+
managersMu.Lock()
|
|
35
|
+
defer managersMu.Unlock()
|
|
36
|
+
id := getNextID()
|
|
37
|
+
managers[id] = m
|
|
38
|
+
return id
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func getManager(id uint64) *zone.Manager {
|
|
42
|
+
managersMu.RLock()
|
|
43
|
+
defer managersMu.RUnlock()
|
|
44
|
+
return managers[id]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var (
|
|
48
|
+
zoneInfos = make(map[uint64]*zone.ZoneInfo)
|
|
49
|
+
zoneInfosMu sync.RWMutex
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
func allocZoneInfo(z *zone.ZoneInfo) uint64 {
|
|
53
|
+
if z == nil {
|
|
54
|
+
return 0
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
zoneInfosMu.Lock()
|
|
58
|
+
defer zoneInfosMu.Unlock()
|
|
59
|
+
id := getNextID()
|
|
60
|
+
zoneInfos[id] = z
|
|
61
|
+
|
|
62
|
+
return id
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func getZoneInfo(id uint64) *zone.ZoneInfo {
|
|
66
|
+
zoneInfosMu.RLock()
|
|
67
|
+
defer zoneInfosMu.RUnlock()
|
|
68
|
+
return zoneInfos[id]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//export bubblezone_free
|
|
72
|
+
func bubblezone_free(pointer *C.char) {
|
|
73
|
+
C.free(unsafe.Pointer(pointer))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//export bubblezone_upstream_version
|
|
77
|
+
func bubblezone_upstream_version() *C.char {
|
|
78
|
+
info, ok := debug.ReadBuildInfo()
|
|
79
|
+
if !ok {
|
|
80
|
+
return C.CString("unknown")
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for _, dep := range info.Deps {
|
|
84
|
+
if dep.Path == "github.com/lrstanley/bubblezone" {
|
|
85
|
+
return C.CString(dep.Version)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return C.CString("unknown")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//export bubblezone_new_manager
|
|
93
|
+
func bubblezone_new_manager() C.ulonglong {
|
|
94
|
+
m := zone.New()
|
|
95
|
+
return C.ulonglong(allocManager(m))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//export bubblezone_free_manager
|
|
99
|
+
func bubblezone_free_manager(id C.ulonglong) {
|
|
100
|
+
managersMu.Lock()
|
|
101
|
+
|
|
102
|
+
defer managersMu.Unlock()
|
|
103
|
+
|
|
104
|
+
if m, ok := managers[uint64(id)]; ok {
|
|
105
|
+
m.Close()
|
|
106
|
+
delete(managers, uint64(id))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//export bubblezone_manager_close
|
|
111
|
+
func bubblezone_manager_close(id C.ulonglong) {
|
|
112
|
+
m := getManager(uint64(id))
|
|
113
|
+
|
|
114
|
+
if m != nil {
|
|
115
|
+
m.Close()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//export bubblezone_manager_set_enabled
|
|
120
|
+
func bubblezone_manager_set_enabled(id C.ulonglong, enabled C.int) {
|
|
121
|
+
m := getManager(uint64(id))
|
|
122
|
+
|
|
123
|
+
if m != nil {
|
|
124
|
+
m.SetEnabled(enabled != 0)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//export bubblezone_manager_enabled
|
|
129
|
+
func bubblezone_manager_enabled(id C.ulonglong) C.int {
|
|
130
|
+
m := getManager(uint64(id))
|
|
131
|
+
|
|
132
|
+
if m != nil && m.Enabled() {
|
|
133
|
+
return 1
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return 0
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//export bubblezone_manager_new_prefix
|
|
140
|
+
func bubblezone_manager_new_prefix(id C.ulonglong) *C.char {
|
|
141
|
+
m := getManager(uint64(id))
|
|
142
|
+
|
|
143
|
+
if m == nil {
|
|
144
|
+
return C.CString("")
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return C.CString(m.NewPrefix())
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//export bubblezone_manager_mark
|
|
151
|
+
func bubblezone_manager_mark(id C.ulonglong, zoneID *C.char, text *C.char) *C.char {
|
|
152
|
+
m := getManager(uint64(id))
|
|
153
|
+
|
|
154
|
+
if m == nil {
|
|
155
|
+
return C.CString(C.GoString(text))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
result := m.Mark(C.GoString(zoneID), C.GoString(text))
|
|
159
|
+
|
|
160
|
+
return C.CString(result)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//export bubblezone_manager_clear
|
|
164
|
+
func bubblezone_manager_clear(id C.ulonglong, zoneID *C.char) {
|
|
165
|
+
m := getManager(uint64(id))
|
|
166
|
+
|
|
167
|
+
if m != nil {
|
|
168
|
+
m.Clear(C.GoString(zoneID))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//export bubblezone_manager_get
|
|
173
|
+
func bubblezone_manager_get(id C.ulonglong, zoneID *C.char) C.ulonglong {
|
|
174
|
+
m := getManager(uint64(id))
|
|
175
|
+
|
|
176
|
+
if m == nil {
|
|
177
|
+
return 0
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
z := m.Get(C.GoString(zoneID))
|
|
181
|
+
|
|
182
|
+
return C.ulonglong(allocZoneInfo(z))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//export bubblezone_manager_scan
|
|
186
|
+
func bubblezone_manager_scan(id C.ulonglong, text *C.char) *C.char {
|
|
187
|
+
m := getManager(uint64(id))
|
|
188
|
+
|
|
189
|
+
if m == nil {
|
|
190
|
+
return C.CString(C.GoString(text))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
result := m.Scan(C.GoString(text))
|
|
194
|
+
|
|
195
|
+
return C.CString(result)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//export bubblezone_free_zone_info
|
|
199
|
+
func bubblezone_free_zone_info(id C.ulonglong) {
|
|
200
|
+
zoneInfosMu.Lock()
|
|
201
|
+
defer zoneInfosMu.Unlock()
|
|
202
|
+
delete(zoneInfos, uint64(id))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//export bubblezone_zone_info_start_x
|
|
206
|
+
func bubblezone_zone_info_start_x(id C.ulonglong) C.int {
|
|
207
|
+
z := getZoneInfo(uint64(id))
|
|
208
|
+
|
|
209
|
+
if z == nil {
|
|
210
|
+
return 0
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return C.int(z.StartX)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//export bubblezone_zone_info_start_y
|
|
217
|
+
func bubblezone_zone_info_start_y(id C.ulonglong) C.int {
|
|
218
|
+
z := getZoneInfo(uint64(id))
|
|
219
|
+
|
|
220
|
+
if z == nil {
|
|
221
|
+
return 0
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return C.int(z.StartY)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//export bubblezone_zone_info_end_x
|
|
228
|
+
func bubblezone_zone_info_end_x(id C.ulonglong) C.int {
|
|
229
|
+
z := getZoneInfo(uint64(id))
|
|
230
|
+
|
|
231
|
+
if z == nil {
|
|
232
|
+
return 0
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return C.int(z.EndX)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//export bubblezone_zone_info_end_y
|
|
239
|
+
func bubblezone_zone_info_end_y(id C.ulonglong) C.int {
|
|
240
|
+
z := getZoneInfo(uint64(id))
|
|
241
|
+
|
|
242
|
+
if z == nil {
|
|
243
|
+
return 0
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return C.int(z.EndY)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
//export bubblezone_zone_info_is_zero
|
|
250
|
+
func bubblezone_zone_info_is_zero(id C.ulonglong) C.int {
|
|
251
|
+
z := getZoneInfo(uint64(id))
|
|
252
|
+
|
|
253
|
+
if z == nil || z.IsZero() {
|
|
254
|
+
return 1
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return 0
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//export bubblezone_zone_info_in_bounds
|
|
261
|
+
func bubblezone_zone_info_in_bounds(id C.ulonglong, x C.int, y C.int) C.int {
|
|
262
|
+
z := getZoneInfo(uint64(id))
|
|
263
|
+
|
|
264
|
+
if z == nil {
|
|
265
|
+
return 0
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if z.IsZero() {
|
|
269
|
+
return 0
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if z.StartX > z.EndX || z.StartY > z.EndY {
|
|
273
|
+
return 0
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if int(x) < z.StartX || int(y) < z.StartY {
|
|
277
|
+
return 0
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if int(x) > z.EndX || int(y) > z.EndY {
|
|
281
|
+
return 0
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return 1
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//export bubblezone_zone_info_pos
|
|
288
|
+
func bubblezone_zone_info_pos(id C.ulonglong, x C.int, y C.int, outX *C.int, outY *C.int) C.int {
|
|
289
|
+
z := getZoneInfo(uint64(id))
|
|
290
|
+
|
|
291
|
+
if z == nil {
|
|
292
|
+
*outX = -1
|
|
293
|
+
*outY = -1
|
|
294
|
+
return 0
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if z.IsZero() {
|
|
298
|
+
*outX = -1
|
|
299
|
+
*outY = -1
|
|
300
|
+
return 0
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
inBounds := bubblezone_zone_info_in_bounds(id, x, y)
|
|
304
|
+
|
|
305
|
+
if inBounds == 0 {
|
|
306
|
+
*outX = -1
|
|
307
|
+
*outY = -1
|
|
308
|
+
return 0
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
*outX = C.int(int(x) - z.StartX)
|
|
312
|
+
*outY = C.int(int(y) - z.StartY)
|
|
313
|
+
|
|
314
|
+
return 1
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//export bubblezone_new_global
|
|
318
|
+
func bubblezone_new_global() {
|
|
319
|
+
zone.NewGlobal()
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
//export bubblezone_global_close
|
|
323
|
+
func bubblezone_global_close() {
|
|
324
|
+
zone.Close()
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
//export bubblezone_global_set_enabled
|
|
328
|
+
func bubblezone_global_set_enabled(enabled C.int) {
|
|
329
|
+
zone.SetEnabled(enabled != 0)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//export bubblezone_global_enabled
|
|
333
|
+
func bubblezone_global_enabled() C.int {
|
|
334
|
+
if zone.Enabled() {
|
|
335
|
+
return 1
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return 0
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//export bubblezone_global_new_prefix
|
|
342
|
+
func bubblezone_global_new_prefix() *C.char {
|
|
343
|
+
return C.CString(zone.NewPrefix())
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
//export bubblezone_global_mark
|
|
347
|
+
func bubblezone_global_mark(zoneID *C.char, text *C.char) *C.char {
|
|
348
|
+
result := zone.Mark(C.GoString(zoneID), C.GoString(text))
|
|
349
|
+
return C.CString(result)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//export bubblezone_global_clear
|
|
353
|
+
func bubblezone_global_clear(zoneID *C.char) {
|
|
354
|
+
zone.Clear(C.GoString(zoneID))
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
//export bubblezone_global_get
|
|
358
|
+
func bubblezone_global_get(zoneID *C.char) C.ulonglong {
|
|
359
|
+
z := zone.Get(C.GoString(zoneID))
|
|
360
|
+
return C.ulonglong(allocZoneInfo(z))
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//export bubblezone_global_scan
|
|
364
|
+
func bubblezone_global_scan(text *C.char) *C.char {
|
|
365
|
+
result := zone.Scan(C.GoString(text))
|
|
366
|
+
return C.CString(result)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
func main() {}
|
data/go/go.mod
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module github.com/marcoroth/bubblezone-ruby/go
|
|
2
|
+
|
|
3
|
+
go 1.23.0
|
|
4
|
+
|
|
5
|
+
require github.com/lrstanley/bubblezone v1.0.0
|
|
6
|
+
|
|
7
|
+
require (
|
|
8
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
|
9
|
+
github.com/charmbracelet/bubbletea v1.3.4 // indirect
|
|
10
|
+
github.com/charmbracelet/colorprofile v0.3.1 // indirect
|
|
11
|
+
github.com/charmbracelet/lipgloss v1.1.0 // indirect
|
|
12
|
+
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
|
13
|
+
github.com/charmbracelet/x/cellbuf v0.0.13 // indirect
|
|
14
|
+
github.com/charmbracelet/x/term v0.2.1 // indirect
|
|
15
|
+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
|
16
|
+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
|
17
|
+
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
18
|
+
github.com/mattn/go-localereader v0.0.1 // indirect
|
|
19
|
+
github.com/mattn/go-runewidth v0.0.16 // indirect
|
|
20
|
+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
|
21
|
+
github.com/muesli/cancelreader v0.2.2 // indirect
|
|
22
|
+
github.com/muesli/termenv v0.16.0 // indirect
|
|
23
|
+
github.com/rivo/uniseg v0.4.7 // indirect
|
|
24
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
|
25
|
+
golang.org/x/sync v0.13.0 // indirect
|
|
26
|
+
golang.org/x/sys v0.32.0 // indirect
|
|
27
|
+
golang.org/x/text v0.24.0 // indirect
|
|
28
|
+
)
|
data/go/go.sum
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
|
2
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
|
3
|
+
github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI=
|
|
4
|
+
github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo=
|
|
5
|
+
github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40=
|
|
6
|
+
github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0=
|
|
7
|
+
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
|
8
|
+
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
|
9
|
+
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
|
10
|
+
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
|
11
|
+
github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k=
|
|
12
|
+
github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
|
13
|
+
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
|
14
|
+
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
|
15
|
+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
|
16
|
+
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
|
17
|
+
github.com/lrstanley/bubblezone v1.0.0 h1:bIpUaBilD42rAQwlg/4u5aTqVAt6DSRKYZuSdmkr8UA=
|
|
18
|
+
github.com/lrstanley/bubblezone v1.0.0/go.mod h1:kcTekA8HE/0Ll2bWzqHlhA2c513KDNLW7uDfDP4Mly8=
|
|
19
|
+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
|
20
|
+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
|
21
|
+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
22
|
+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
23
|
+
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
|
24
|
+
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
|
25
|
+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
|
26
|
+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
27
|
+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
|
28
|
+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
|
29
|
+
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
|
30
|
+
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
|
31
|
+
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
|
32
|
+
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
|
33
|
+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
34
|
+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
|
35
|
+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
|
36
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
|
37
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
|
38
|
+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
|
39
|
+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
|
40
|
+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
|
|
41
|
+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|
42
|
+
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
43
|
+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
44
|
+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
|
|
45
|
+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
|
46
|
+
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
|
|
47
|
+
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
|