bubbletea 0.1.4-arm-linux-gnu → 0.1.5-arm-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8f34d8ff5e01c256b880e0bc3eb190240a3c4d54620e489b768b8c62c2c0e42
4
- data.tar.gz: 735370c8078e954c3f9082e04bc5571166b88dcd5b292e89d09897fdbcd05814
3
+ metadata.gz: a7b7cfe9720b8ffac2cf11f9f82c3ab9806f01da46d6c622a653fb9751a6d355
4
+ data.tar.gz: 59320b0ce0ddef69c673aa67e0461fa35b75daa40820a95c31270e2da0f2a7f6
5
5
  SHA512:
6
- metadata.gz: 17f8ce57cbfdc47886a4609d47a170c257d0381d660db2607e0bd7bba1d91b660872eec5d3affac19f0de093cbb7e088d35621a38dc628d0c5fdb3df53dabd57
7
- data.tar.gz: d3ad2b92115ff3f2e27bfee464aa6db6dcb44d89ba146c7e83f77be985c9d5e2ec06f0ecaf4ea75c67f550dd6a560f37b55e0fe6c97c3f0cba3e23a591d99377
6
+ metadata.gz: d1f309cea230062e6dd578aeb60391e8b9ed08fc39bba6b89ed717c15719d9f4d56aa1e395661da16149a5a7103b9404607e48338bd4fe1f71199cda8c3ac873
7
+ data.tar.gz: e36f301fd5140234ebb54f294746f0335b3f3bc2f2c7492c02b28a32d5dddcaf0bccf51bc3d8544afd88c2803afb210a5310ffd3f91ddbb990146273f82a9b84
@@ -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) \
@@ -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
- char buffer[256];
162
- int bytes_read = tea_input_read_raw(program->handle, buffer, sizeof(buffer), NUM2INT(timeout_ms));
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 (bytes_read <= 0) {
165
- return Qnil; // Timeout or error
175
+ if (consumed <= 0 || consumed > program->input_length) {
176
+ consumed = program->input_length;
166
177
  }
167
178
 
168
- int consumed;
169
- char *json = tea_parse_input_with_consumed(buffer, bytes_read, &consumed);
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 & 3
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bubbletea
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
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
4
+ version: 0.1.5
5
5
  platform: arm-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