terminal_rb 0.16.0 → 0.16.1
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/README.md +1 -1
- data/lib/terminal/ansi.rb +1 -1
- data/lib/terminal/input/key_event.rb +27 -19
- data/lib/terminal/text.rb +2 -2
- data/lib/terminal/version.rb +1 -1
- data/lib/terminal.rb +34 -7
- data/terminal_rb.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1127036c0cda3cdc5e44853ba2f650d7475338166d363ca3f50c35900ac858d7
|
|
4
|
+
data.tar.gz: 638eaaa9c3d072d8ee1acddab353150f4619f50420b03682b7436d9de19ff71a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 562cef6e62f27adadf22e361017968c422e0c3661787be87d4474debffb26e73f87fc104aeb5e2e4d10fb9a7ba4634d14f44e8c9bebf88ba776cee63912fabcb
|
|
7
|
+
data.tar.gz: 5668c79725449d1bb9989ba691997adb93a18186a0bfde224ebd8a626a523db08b34a1b45aa2639d46e32acaab7490d47c7987daf875ea5ab6047e690d265885
|
data/README.md
CHANGED
|
@@ -16,7 +16,7 @@ Terminal.rb supports you with input and output on your terminal. Simple [BBCode]
|
|
|
16
16
|
- calculation for correct display width of strings containing Unicdode chars inclusive emojis
|
|
17
17
|
- word-wise line break generator
|
|
18
18
|
- supports [CSIu protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol)
|
|
19
|
-
- mouse events
|
|
19
|
+
- mouse events
|
|
20
20
|
|
|
21
21
|
## Examples
|
|
22
22
|
|
data/lib/terminal/ansi.rb
CHANGED
|
@@ -5,13 +5,6 @@ module Terminal
|
|
|
5
5
|
# Key event reported from {read_key_event} and {on_key_event}.
|
|
6
6
|
#
|
|
7
7
|
class KeyEvent
|
|
8
|
-
# ANSI code sequence received from standard input.
|
|
9
|
-
# This can be a simple value like `"a"`or more complex input like
|
|
10
|
-
# `"\e[24;6~"` (for Shift+Ctrl+F12).
|
|
11
|
-
#
|
|
12
|
-
# @return [String] received ANSI code sequence
|
|
13
|
-
attr_reader :raw
|
|
14
|
-
|
|
15
8
|
# Pressed key without any modifiers.
|
|
16
9
|
# This can be a string for simple keys like `"a"` or a Symbol like `:F12`
|
|
17
10
|
# (see {.key_names}).
|
|
@@ -24,11 +17,9 @@ module Terminal
|
|
|
24
17
|
# @return [Integer] modifier key code
|
|
25
18
|
attr_reader :modifier
|
|
26
19
|
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
# @return nil when no coordinates are assigned
|
|
31
|
-
attr_reader :position
|
|
20
|
+
# @attribute [r] modifier?
|
|
21
|
+
# @return [true, false] whether a key modifier was pressed
|
|
22
|
+
def modifier? = @modifier != 0
|
|
32
23
|
|
|
33
24
|
# Name of the key event.
|
|
34
25
|
# This can be a simple name like `"a"` or `"Shift+Ctrl+F12"` for combined
|
|
@@ -37,9 +28,18 @@ module Terminal
|
|
|
37
28
|
# @return [String] key name
|
|
38
29
|
attr_reader :name
|
|
39
30
|
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
|
|
31
|
+
# Mouse event position.
|
|
32
|
+
#
|
|
33
|
+
# @return [[Integer,Integer]] row and column
|
|
34
|
+
# @return nil when no coordinates are assigned
|
|
35
|
+
attr_reader :position
|
|
36
|
+
|
|
37
|
+
# ANSI code sequence received from standard input.
|
|
38
|
+
# This can be a simple value like `"a"`or more complex input like
|
|
39
|
+
# `"\e[24;6~"` (for Shift+Ctrl+F12).
|
|
40
|
+
#
|
|
41
|
+
# @return [String] received ANSI code sequence
|
|
42
|
+
attr_reader :raw
|
|
43
43
|
|
|
44
44
|
# @attribute [r] simple?
|
|
45
45
|
# @return [true, false] whether a simple key was pressed
|
|
@@ -48,6 +48,14 @@ module Terminal
|
|
|
48
48
|
# All pressed keys.
|
|
49
49
|
# This is composed by all {modifier} and the {key}.
|
|
50
50
|
#
|
|
51
|
+
# @example
|
|
52
|
+
# Terminal::KeyEvent["\e\r"].to_a
|
|
53
|
+
# => [:Alt, :Enter]
|
|
54
|
+
# Terminal::KeyEvent['a'].to_a
|
|
55
|
+
# => ['a']
|
|
56
|
+
# Terminal::KeyEvent["\e[<12;45;30m"].to_a
|
|
57
|
+
# => [:Shift, :Alt, :MBLeftUp]
|
|
58
|
+
#
|
|
51
59
|
# @return [Array<Symbol, String>] all pressed keys
|
|
52
60
|
def to_a = @ary.dup
|
|
53
61
|
|
|
@@ -76,9 +84,9 @@ module Terminal
|
|
|
76
84
|
@key = key
|
|
77
85
|
@modifier = modifier
|
|
78
86
|
@position = position
|
|
79
|
-
@ary = MODIFIERS.filter_map { |b, n| n if modifier
|
|
87
|
+
@ary = MODIFIERS.filter_map { |b, n| n if (modifier & b) == b }
|
|
80
88
|
@ary << key if key
|
|
81
|
-
@name = @ary.join('+')
|
|
89
|
+
@name = @ary.join('+')
|
|
82
90
|
end
|
|
83
91
|
|
|
84
92
|
class << self
|
|
@@ -103,9 +111,9 @@ module Terminal
|
|
|
103
111
|
).dup
|
|
104
112
|
end
|
|
105
113
|
|
|
106
|
-
# Translate
|
|
114
|
+
# Translate an ANSI input code sequence into a related KeyEvent.
|
|
107
115
|
#
|
|
108
|
-
# @param raw [String] keyboard
|
|
116
|
+
# @param raw [String] keyboard, mouse or focus event sequence
|
|
109
117
|
# @return [KeyEvent] related key event
|
|
110
118
|
def [](raw)
|
|
111
119
|
cached = @cache[raw] and return cached if @cache
|
data/lib/terminal/text.rb
CHANGED
|
@@ -447,7 +447,7 @@ module Terminal
|
|
|
447
447
|
@scan_snippet =
|
|
448
448
|
/\G(?:
|
|
449
449
|
(\r?\n)
|
|
450
|
-
| (\e\[[\
|
|
450
|
+
| (\e\[[\x30-\x3f]*[\x20-\x2f]*[a-zA-Z])
|
|
451
451
|
| (\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
|
452
452
|
| (\s+)
|
|
453
453
|
| (\X)
|
|
@@ -455,7 +455,7 @@ module Terminal
|
|
|
455
455
|
|
|
456
456
|
@scan_width =
|
|
457
457
|
/\G(?:
|
|
458
|
-
(?:\e\[[\
|
|
458
|
+
(?:\e\[[\x30-\x3f]*[\x20-\x2f]*[a-zA-Z])
|
|
459
459
|
| (?:\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
|
460
460
|
| (\s+)
|
|
461
461
|
| (\X)
|
data/lib/terminal/version.rb
CHANGED
data/lib/terminal.rb
CHANGED
|
@@ -16,16 +16,42 @@ require_relative 'terminal/input'
|
|
|
16
16
|
#
|
|
17
17
|
module Terminal
|
|
18
18
|
class << self
|
|
19
|
-
# Return true if the current terminal supports ANSI control codes
|
|
20
|
-
#
|
|
21
|
-
# all output methods ({<<}, {print}, {puts}) will
|
|
22
|
-
# codes to the terminal
|
|
23
|
-
#
|
|
19
|
+
# Return `true` if the current terminal supports ANSI control codes for
|
|
20
|
+
# output.
|
|
21
|
+
# In this case all output methods ({<<}, {print}, {puts}) will forward ANSI
|
|
22
|
+
# control codes to the terminal and translate BBCode (see {Ansi.bbcode}).
|
|
23
|
+
#
|
|
24
|
+
# When `false` is returned (ANSI is not supported) the output methods will
|
|
25
|
+
# not forward ANSI control codes and BBCodes will be removed.
|
|
26
|
+
# The {colors} method will just return 2 (two).
|
|
27
|
+
#
|
|
28
|
+
# @see tui?
|
|
24
29
|
#
|
|
25
30
|
# @attribute [r] ansi?
|
|
26
|
-
# @return [
|
|
31
|
+
# @return [true, false] whether ANSI control codes are supported for output
|
|
27
32
|
def ansi? = @ansi
|
|
28
33
|
|
|
34
|
+
# Return `true` if the current terminal supports ANSI control codes for
|
|
35
|
+
# input _and_ output.
|
|
36
|
+
# In this case not only all output methods ({<<}, {print}, {puts}) will
|
|
37
|
+
# forward ANSI control codes to the terminal and translate BBCode
|
|
38
|
+
# (see {Ansi.bbcode}). But also the input methods {read_key_event} and
|
|
39
|
+
# {on_key_event} will support extended key codes, mouse and focus events.
|
|
40
|
+
#
|
|
41
|
+
# @see ansi?
|
|
42
|
+
#
|
|
43
|
+
# @attribute [r] tui?
|
|
44
|
+
# @return [true, false]
|
|
45
|
+
# whether ANSI control codes are supported for input and output
|
|
46
|
+
def tui?
|
|
47
|
+
case input_mode
|
|
48
|
+
when :csi_u, :legacy
|
|
49
|
+
@ansi
|
|
50
|
+
else
|
|
51
|
+
false
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
29
55
|
# Terminal application identifier.
|
|
30
56
|
#
|
|
31
57
|
# The detection supports a wide range of terminal emulators but may return
|
|
@@ -127,7 +153,7 @@ module Terminal
|
|
|
127
153
|
|
|
128
154
|
# @see colors
|
|
129
155
|
# @attribute [r] true_color?
|
|
130
|
-
# @return [
|
|
156
|
+
# @return [true, false] whether true colors are supported
|
|
131
157
|
def true_color? = (colors == 16_777_216)
|
|
132
158
|
|
|
133
159
|
# Hide the cursor.
|
|
@@ -365,5 +391,6 @@ module Terminal
|
|
|
365
391
|
autoload :Text, "#{dir}/text.rb"
|
|
366
392
|
autoload :Detect, "#{dir}/detect.rb"
|
|
367
393
|
autoload :Shell, "#{dir}/shell.rb"
|
|
394
|
+
autoload :VERSION, "#{dir}/version.rb"
|
|
368
395
|
private_constant :Detect, :Shell
|
|
369
396
|
end
|
data/terminal_rb.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
|
|
|
6
6
|
spec.name = 'terminal_rb'
|
|
7
7
|
spec.version = Terminal::VERSION
|
|
8
8
|
spec.summary = <<~SUMMARY.tr("\n", ' ')
|
|
9
|
-
Fast terminal access with ANSI, CSIu, mouse
|
|
9
|
+
Fast terminal access with ANSI, CSIu, mouse events, BBCode, word-wise
|
|
10
10
|
line break support and much more.
|
|
11
11
|
SUMMARY
|
|
12
12
|
spec.description = <<~DESCRIPTION.tr("\n", ' ')
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: terminal_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.16.
|
|
4
|
+
version: 0.16.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
@@ -69,6 +69,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
69
69
|
requirements: []
|
|
70
70
|
rubygems_version: 3.7.2
|
|
71
71
|
specification_version: 4
|
|
72
|
-
summary: Fast terminal access with ANSI, CSIu, mouse
|
|
72
|
+
summary: Fast terminal access with ANSI, CSIu, mouse events, BBCode, word-wise line
|
|
73
73
|
break support and much more.
|
|
74
74
|
test_files: []
|