bubbletea 0.1.3-x86_64-linux-gnu → 0.1.5-x86_64-linux-gnu
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/ext/bubbletea/extension.h +4 -0
- data/ext/bubbletea/program.c +17 -6
- data/go/build/linux_amd64/libbubbletea.a +0 -0
- data/go/keys.go +23 -9
- data/go/keys_test.go +36 -0
- data/lib/bubbletea/3.2/bubbletea.so +0 -0
- data/lib/bubbletea/3.3/bubbletea.so +0 -0
- data/lib/bubbletea/3.4/bubbletea.so +0 -0
- data/lib/bubbletea/4.0/bubbletea.so +0 -0
- data/lib/bubbletea/commands.rb +14 -0
- data/lib/bubbletea/runner.rb +23 -0
- data/lib/bubbletea/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ac9573b6ff0cfae125ba0b87e02d53456b717ef1d252899ad1fe02d334291d8
|
|
4
|
+
data.tar.gz: 9902419a80db7416bcdfbb873e0fdb93a01a9996678b90112d5b1a063e520bc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91f9581d8e80b09d9a46f4ca5e42343ab4661c7a5f9373760618d394670c1ac4e5f08d36664b6874a46741cf13df3d612502758cde2e36c6f405c8e7838a45f5
|
|
7
|
+
data.tar.gz: 0be43f949cb8b12e14e6dcde187f19753f405700f40a0778bba90471ccfe0106501bc1f04781c2a338ff07a9952a2b555b062c66e6559c99cfc504ed8ef41529
|
data/ext/bubbletea/extension.h
CHANGED
|
@@ -9,8 +9,12 @@ extern VALUE cProgram;
|
|
|
9
9
|
|
|
10
10
|
extern const rb_data_type_t program_type;
|
|
11
11
|
|
|
12
|
+
#define BUBBLETEA_INPUT_BUFFER_SIZE 256
|
|
13
|
+
|
|
12
14
|
typedef struct {
|
|
13
15
|
unsigned long long handle;
|
|
16
|
+
char input[BUBBLETEA_INPUT_BUFFER_SIZE];
|
|
17
|
+
int input_length;
|
|
14
18
|
} bubbletea_program_t;
|
|
15
19
|
|
|
16
20
|
#define GET_PROGRAM(self, program) \
|
data/ext/bubbletea/program.c
CHANGED
|
@@ -27,6 +27,7 @@ const rb_data_type_t program_type = {
|
|
|
27
27
|
static VALUE program_alloc(VALUE klass) {
|
|
28
28
|
bubbletea_program_t *program = ALLOC(bubbletea_program_t);
|
|
29
29
|
program->handle = tea_new_program();
|
|
30
|
+
program->input_length = 0;
|
|
30
31
|
return TypedData_Wrap_Struct(klass, &program_type, program);
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -158,15 +159,25 @@ static VALUE program_read_raw_input(VALUE self, VALUE timeout_ms) {
|
|
|
158
159
|
static VALUE program_poll_event(VALUE self, VALUE timeout_ms) {
|
|
159
160
|
GET_PROGRAM(self, program);
|
|
160
161
|
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
if (program->input_length == 0) {
|
|
163
|
+
int bytes_read = tea_input_read_raw(program->handle, program->input, sizeof(program->input), NUM2INT(timeout_ms));
|
|
164
|
+
|
|
165
|
+
if (bytes_read <= 0) {
|
|
166
|
+
return Qnil;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
program->input_length = bytes_read;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
int consumed = 0;
|
|
173
|
+
char *json = tea_parse_input_with_consumed(program->input, program->input_length, &consumed);
|
|
163
174
|
|
|
164
|
-
if (
|
|
165
|
-
|
|
175
|
+
if (consumed <= 0 || consumed > program->input_length) {
|
|
176
|
+
consumed = program->input_length;
|
|
166
177
|
}
|
|
167
178
|
|
|
168
|
-
|
|
169
|
-
|
|
179
|
+
program->input_length -= consumed;
|
|
180
|
+
memmove(program->input, program->input + consumed, program->input_length);
|
|
170
181
|
|
|
171
182
|
if (json == NULL || json[0] == '\0') {
|
|
172
183
|
tea_free(json);
|
|
Binary file
|
data/go/keys.go
CHANGED
|
@@ -334,6 +334,28 @@ func ParseInput(data []byte) (int, string) {
|
|
|
334
334
|
return size, string(jsonBytes)
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
// mouseButton maps mouse report buttons to Bubbletea::MouseMessage buttons
|
|
338
|
+
func mouseButton(button int) int {
|
|
339
|
+
low := button & 3
|
|
340
|
+
|
|
341
|
+
if (button & 64) != 0 {
|
|
342
|
+
switch low {
|
|
343
|
+
case 0:
|
|
344
|
+
return 4 // wheel up
|
|
345
|
+
case 1:
|
|
346
|
+
return 5 // wheel down
|
|
347
|
+
default:
|
|
348
|
+
return 0 // wheel left/right
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if low == 3 {
|
|
353
|
+
return 0 // none
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return low + 1
|
|
357
|
+
}
|
|
358
|
+
|
|
337
359
|
// parseMouseSGR parses SGR mouse format: ESC [ < Cb ; Cx ; Cy M/m
|
|
338
360
|
func parseMouseSGR(data []byte) (int, MouseEvent) {
|
|
339
361
|
// Format: \x1b[<button;x;y(M|m)
|
|
@@ -368,7 +390,7 @@ func parseMouseSGR(data []byte) (int, MouseEvent) {
|
|
|
368
390
|
alt := (button & 8) != 0
|
|
369
391
|
ctrl := (button & 16) != 0
|
|
370
392
|
motion := (button & 32) != 0
|
|
371
|
-
buttonNum := button
|
|
393
|
+
buttonNum := mouseButton(button)
|
|
372
394
|
|
|
373
395
|
action := 0 // press
|
|
374
396
|
|
|
@@ -378,14 +400,6 @@ func parseMouseSGR(data []byte) (int, MouseEvent) {
|
|
|
378
400
|
action = 2 // motion
|
|
379
401
|
}
|
|
380
402
|
|
|
381
|
-
if (button & 64) != 0 {
|
|
382
|
-
if buttonNum == 0 {
|
|
383
|
-
buttonNum = 4 // wheel up
|
|
384
|
-
} else if buttonNum == 1 {
|
|
385
|
-
buttonNum = 5 // wheel down
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
403
|
return endIndex + 1, MouseEvent{
|
|
390
404
|
Type: "mouse",
|
|
391
405
|
X: x - 1,
|
data/go/keys_test.go
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "testing"
|
|
4
|
+
|
|
5
|
+
func TestParseMouseSGR(t *testing.T) {
|
|
6
|
+
tests := []struct {
|
|
7
|
+
name string
|
|
8
|
+
input string
|
|
9
|
+
x, y int
|
|
10
|
+
button, action int
|
|
11
|
+
}{
|
|
12
|
+
{"left press", "\x1b[<0;10;5M", 9, 4, 1, 0},
|
|
13
|
+
{"middle press", "\x1b[<1;10;5M", 9, 4, 2, 0},
|
|
14
|
+
{"right press", "\x1b[<2;10;5M", 9, 4, 3, 0},
|
|
15
|
+
{"left release", "\x1b[<0;10;5m", 9, 4, 1, 1},
|
|
16
|
+
{"left drag", "\x1b[<32;12;5M", 11, 4, 1, 2},
|
|
17
|
+
{"motion without a button", "\x1b[<35;20;8M", 19, 7, 0, 2},
|
|
18
|
+
{"wheel up", "\x1b[<64;1;1M", 0, 0, 4, 0},
|
|
19
|
+
{"wheel down", "\x1b[<65;1;1M", 0, 0, 5, 0},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for _, tt := range tests {
|
|
23
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
24
|
+
consumed, event := parseMouseSGR([]byte(tt.input))
|
|
25
|
+
|
|
26
|
+
if consumed != len(tt.input) {
|
|
27
|
+
t.Fatalf("consumed %d bytes, want %d", consumed, len(tt.input))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if event.X != tt.x || event.Y != tt.y || event.Button != tt.button || event.Action != tt.action {
|
|
31
|
+
t.Errorf("got x=%d y=%d button=%d action=%d, want x=%d y=%d button=%d action=%d",
|
|
32
|
+
event.X, event.Y, event.Button, event.Action, tt.x, tt.y, tt.button, tt.action)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/bubbletea/commands.rb
CHANGED
|
@@ -78,6 +78,16 @@ module Bubbletea
|
|
|
78
78
|
class SuspendCommand < Command
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
class ExecCommand < Command
|
|
82
|
+
attr_reader :callable, :message
|
|
83
|
+
|
|
84
|
+
def initialize(callable, message: nil)
|
|
85
|
+
super()
|
|
86
|
+
@callable = callable
|
|
87
|
+
@message = message
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
81
91
|
class << self
|
|
82
92
|
def quit
|
|
83
93
|
QuitCommand.new
|
|
@@ -122,5 +132,9 @@ module Bubbletea
|
|
|
122
132
|
def suspend
|
|
123
133
|
SuspendCommand.new
|
|
124
134
|
end
|
|
135
|
+
|
|
136
|
+
def exec(callable, message: nil)
|
|
137
|
+
ExecCommand.new(callable, message: message)
|
|
138
|
+
end
|
|
125
139
|
end
|
|
126
140
|
end
|
data/lib/bubbletea/runner.rb
CHANGED
|
@@ -233,6 +233,9 @@ module Bubbletea
|
|
|
233
233
|
when SuspendCommand
|
|
234
234
|
suspend_process
|
|
235
235
|
|
|
236
|
+
when ExecCommand
|
|
237
|
+
exec_process(command)
|
|
238
|
+
|
|
236
239
|
when Proc
|
|
237
240
|
Thread.new do
|
|
238
241
|
result = command.call
|
|
@@ -286,6 +289,9 @@ module Bubbletea
|
|
|
286
289
|
when SuspendCommand
|
|
287
290
|
suspend_process
|
|
288
291
|
|
|
292
|
+
when ExecCommand
|
|
293
|
+
exec_process(command)
|
|
294
|
+
|
|
289
295
|
when Proc
|
|
290
296
|
result = command.call
|
|
291
297
|
return unless result
|
|
@@ -360,6 +366,23 @@ module Bubbletea
|
|
|
360
366
|
handle_message(ResumeMessage.new)
|
|
361
367
|
end
|
|
362
368
|
|
|
369
|
+
def exec_process(command)
|
|
370
|
+
@program.disable_mouse if @options[:mouse_cell_motion] || @options[:mouse_all_motion]
|
|
371
|
+
@program.show_cursor
|
|
372
|
+
@program.stop_input_reader
|
|
373
|
+
@program.exit_raw_mode
|
|
374
|
+
|
|
375
|
+
command.callable.call
|
|
376
|
+
|
|
377
|
+
@program.enter_raw_mode
|
|
378
|
+
@program.hide_cursor
|
|
379
|
+
@program.start_input_reader
|
|
380
|
+
@program.enable_mouse_cell_motion if @options[:mouse_cell_motion]
|
|
381
|
+
@program.enable_mouse_all_motion if @options[:mouse_all_motion]
|
|
382
|
+
|
|
383
|
+
handle_message(command.message) if command.message
|
|
384
|
+
end
|
|
385
|
+
|
|
363
386
|
def render
|
|
364
387
|
return if @options[:without_renderer]
|
|
365
388
|
return unless @renderer_id
|
data/lib/bubbletea/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bubbletea
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: x86_64-linux-gnu
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
@@ -45,6 +45,7 @@ files:
|
|
|
45
45
|
- go/go.sum
|
|
46
46
|
- go/input.go
|
|
47
47
|
- go/keys.go
|
|
48
|
+
- go/keys_test.go
|
|
48
49
|
- go/renderer.go
|
|
49
50
|
- go/terminal.go
|
|
50
51
|
- lib/bubbletea.rb
|