terminal_rb 0.14.0 → 0.15.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/examples/info.rb +1 -0
- data/examples/text.rb +32 -0
- data/lib/terminal/ansi.rb +12 -1
- data/lib/terminal/text.rb +68 -69
- data/lib/terminal/version.rb +1 -1
- data/lib/terminal.rb +25 -1
- data/terminal_rb.gemspec +33 -0
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23d41a32cd285a8ec05dde44ac26131e207f567b4137ff4c1b144171abb72dd6
|
|
4
|
+
data.tar.gz: 28325ab102a8ecd1ec6e9f2b9196aa85f8bf8d59898b6105a26d6afa2cc1a065
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff88211e6ac2b869db965ef8861ddf312699c4cef971deea0f2b75bfac0f77df8f23936aa2a6870adfd60167391a720e76a089918b1e8b2bb35842d6fd32cb0a
|
|
7
|
+
data.tar.gz: '091504b7dfebe143f8df736f52db891a08a27d4bac9763706af06def5a9c2e413b620300c4188bd700c529b2446cb1ecb351a4425772bdd051b46332b96ce4bd'
|
data/examples/info.rb
CHANGED
|
@@ -12,5 +12,6 @@ Terminal.puts <<~TEXT
|
|
|
12
12
|
Terminal Size: [b]#{Terminal.size.join(' x ')}[/]
|
|
13
13
|
Cursor Position: [b]#{Terminal.pos&.join(', ')}[/]
|
|
14
14
|
Input Mode: [b]#{Terminal.input_mode}[/]
|
|
15
|
+
Link Support: [b]#{Terminal::Ansi.link('https://codeberg.org/mblumtritt/Terminal.rb', 'Link')}[/]
|
|
15
16
|
|
|
16
17
|
TEXT
|
data/examples/text.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/terminal'
|
|
4
|
+
|
|
5
|
+
LOREM = <<~IPSUM
|
|
6
|
+
This example outputs [i bright_white]Lorem ipsum[/] text so that it takes up 75% of the screen width and fits the height of your screen.
|
|
7
|
+
|
|
8
|
+
[i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet.
|
|
9
|
+
|
|
10
|
+
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla [red]facilisis[/fg] at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. [i bright_white]Lorem ipsum[/] dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore [b]magna[/b] aliquam erat volutpat.
|
|
11
|
+
|
|
12
|
+
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla [red]facilisis[/fg] at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
|
|
13
|
+
|
|
14
|
+
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. [i bright_white]Lorem ipsum[/] dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore [b]magna[/b] aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
|
|
15
|
+
|
|
16
|
+
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla [red]facilisis[/fg].
|
|
17
|
+
|
|
18
|
+
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd [b]magna[/b] no rebum. [yellow]sanctus[/fg] sea sed takimata ut vero voluptua. est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat.
|
|
19
|
+
|
|
20
|
+
Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg].
|
|
21
|
+
|
|
22
|
+
[i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet. [i bright_white]Lorem ipsum[/] dolor sit amet, [green]consetetur[/fg] sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore [b]magna[/b] aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata [yellow]sanctus[/fg] est [i bright_white]Lorem ipsum[/] dolor sit amet.
|
|
23
|
+
|
|
24
|
+
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla [red]facilisis[/fg] at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. [i bright_white]Lorem ipsum[/] dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore [b]magna[/b] aliquam erat volutpat.
|
|
25
|
+
|
|
26
|
+
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla [red]facilisis[/fg] at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
|
|
27
|
+
|
|
28
|
+
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. [i bright_white]Lorem ipsum[/] dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore [b]magna[/b] aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
|
|
29
|
+
IPSUM
|
|
30
|
+
|
|
31
|
+
rows, cols = Terminal.size
|
|
32
|
+
puts Terminal::Text.each(LOREM, limit: cols * 0.75).take(rows - 1)
|
data/lib/terminal/ansi.rb
CHANGED
|
@@ -486,6 +486,17 @@ module Terminal
|
|
|
486
486
|
# @return (see cursor_up)
|
|
487
487
|
def link(url, text) = "\e]8;;#{url}\a#{text}\e]8;;\a"
|
|
488
488
|
|
|
489
|
+
# Show a simple notification.
|
|
490
|
+
# This is not widely supported; works for
|
|
491
|
+
# Ghosty,
|
|
492
|
+
# iTerm2,
|
|
493
|
+
# Kitty,
|
|
494
|
+
# WezTerm.
|
|
495
|
+
#
|
|
496
|
+
# @param text [#to_s] text to display
|
|
497
|
+
# @return (see cursor_up)
|
|
498
|
+
def notify(text) = "\e]9;#{text}\a"
|
|
499
|
+
|
|
489
500
|
# Create scaled text.
|
|
490
501
|
# It uses the
|
|
491
502
|
# [text sizing protocol](https://sw.kovidgoyal.net/kitty/text-sizing-protocol).
|
|
@@ -588,7 +599,7 @@ module Terminal
|
|
|
588
599
|
|
|
589
600
|
@re_test =
|
|
590
601
|
/
|
|
591
|
-
(?:\e\[[\d
|
|
602
|
+
(?:\e\[[\d;:?]*[ABCDEFGHJKSTfminsuhl])
|
|
592
603
|
|
|
|
593
604
|
(?:\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
|
594
605
|
/x
|
data/lib/terminal/text.rb
CHANGED
|
@@ -28,8 +28,7 @@ module Terminal
|
|
|
28
28
|
# @param bbcode [true|false] whether to interpret embedded BBCode
|
|
29
29
|
# @return [Integer] display width
|
|
30
30
|
def width(str, bbcode: true)
|
|
31
|
-
str = bbcode ? Ansi.unbbcode(str) : str.to_s
|
|
32
|
-
return 0 if str.empty?
|
|
31
|
+
return 0 if (str = bbcode ? Ansi.unbbcode(str) : str.to_s).empty?
|
|
33
32
|
str = str.encode(@encoding) if str.encoding != @encoding
|
|
34
33
|
width = 0
|
|
35
34
|
str.scan(WIDTH_SCANNER) do |sp, gc|
|
|
@@ -68,14 +67,14 @@ module Terminal
|
|
|
68
67
|
&block
|
|
69
68
|
)
|
|
70
69
|
unless limit
|
|
71
|
-
|
|
72
|
-
return block ? lines(
|
|
70
|
+
snippets = as_snippets(text, bbcode, ansi, ignore_newline, Word)
|
|
71
|
+
return block ? lines(snippets, &block) : to_enum(:lines, snippets)
|
|
73
72
|
end
|
|
74
73
|
limit = limit.to_i
|
|
75
74
|
raise(ArgumentError, "invalid limit - #{limit}") if limit < 1
|
|
76
|
-
|
|
77
|
-
return lim_lines(
|
|
78
|
-
to_enum(:lim_lines,
|
|
75
|
+
snippets = as_snippets(text, bbcode, ansi, ignore_newline, WordEx)
|
|
76
|
+
return lim_lines(snippets, limit, &block) if block
|
|
77
|
+
to_enum(:lim_lines, snippets, limit)
|
|
79
78
|
end
|
|
80
79
|
alias each each_line
|
|
81
80
|
|
|
@@ -98,14 +97,14 @@ module Terminal
|
|
|
98
97
|
&block
|
|
99
98
|
)
|
|
100
99
|
unless limit
|
|
101
|
-
|
|
102
|
-
return block ? pairs(
|
|
100
|
+
snippets = as_snippets(text, bbcode, ansi, ignore_newline, Word)
|
|
101
|
+
return block ? pairs(snippets, &block) : to_enum(:pairs, snippets)
|
|
103
102
|
end
|
|
104
103
|
limit = limit.to_i
|
|
105
104
|
raise(ArgumentError, "invalid limit - #{limit}") if limit < 1
|
|
106
|
-
|
|
107
|
-
return lim_pairs(
|
|
108
|
-
to_enum(:lim_pairs,
|
|
105
|
+
snippets = as_snippets(text, bbcode, ansi, ignore_newline, WordEx)
|
|
106
|
+
return lim_pairs(snippets, limit, &block) if block
|
|
107
|
+
to_enum(:lim_pairs, snippets, limit)
|
|
109
108
|
end
|
|
110
109
|
alias each_with_size each_line_with_size
|
|
111
110
|
|
|
@@ -123,12 +122,12 @@ module Terminal
|
|
|
123
122
|
char.size < 2 ? 1 : char.each_char.sum { char_width(_1) }
|
|
124
123
|
end
|
|
125
124
|
|
|
126
|
-
def lim_pairs(
|
|
125
|
+
def lim_pairs(snippets, limit)
|
|
127
126
|
line = @empty.dup
|
|
128
127
|
size = 0
|
|
129
128
|
csi = nil
|
|
130
|
-
|
|
131
|
-
if
|
|
129
|
+
snippets.each do |snippet|
|
|
130
|
+
if snippet == :space
|
|
132
131
|
next if size == 0
|
|
133
132
|
next line << ' ' if (size += 1) <= limit
|
|
134
133
|
yield(line, size - 1)
|
|
@@ -136,31 +135,31 @@ module Terminal
|
|
|
136
135
|
next size = 0
|
|
137
136
|
end
|
|
138
137
|
|
|
139
|
-
if
|
|
138
|
+
if snippet == :nl
|
|
140
139
|
line[-1] == ' ' ? yield(line.chop, size - 1) : yield(line, size)
|
|
141
140
|
line = "#{csi}"
|
|
142
141
|
next size = 0
|
|
143
142
|
end
|
|
144
143
|
|
|
145
|
-
if
|
|
144
|
+
if snippet == :hard_nl
|
|
146
145
|
line[-1] == ' ' ? yield(line.chop, size - 1) : yield(line, size)
|
|
147
146
|
line = @empty.dup
|
|
148
147
|
csi = nil
|
|
149
148
|
next size = 0
|
|
150
149
|
end
|
|
151
150
|
|
|
152
|
-
if
|
|
151
|
+
if snippet == CsiEnd
|
|
153
152
|
line << CsiEnd if csi
|
|
154
153
|
next csi = nil
|
|
155
154
|
end
|
|
156
155
|
|
|
157
|
-
next line << (csi =
|
|
158
|
-
next line <<
|
|
156
|
+
next line << (csi = snippet) if snippet.is_a?(Csi)
|
|
157
|
+
next line << snippet if snippet.is_a?(Osc)
|
|
159
158
|
|
|
160
159
|
# Word:
|
|
161
160
|
|
|
162
|
-
if (ns = size +
|
|
163
|
-
line <<
|
|
161
|
+
if (ns = size + snippet.size) <= limit
|
|
162
|
+
line << snippet
|
|
164
163
|
next size = ns
|
|
165
164
|
end
|
|
166
165
|
|
|
@@ -170,16 +169,16 @@ module Terminal
|
|
|
170
169
|
end
|
|
171
170
|
yield(line, size) if size != 0
|
|
172
171
|
|
|
173
|
-
if
|
|
174
|
-
line = "#{csi}#{
|
|
175
|
-
next size =
|
|
172
|
+
if snippet.size <= limit
|
|
173
|
+
line = "#{csi}#{snippet}"
|
|
174
|
+
next size = snippet.size
|
|
176
175
|
end
|
|
177
176
|
|
|
178
|
-
words =
|
|
177
|
+
words = snippet.split(limit)
|
|
179
178
|
if words[-1].size <= limit
|
|
180
|
-
|
|
181
|
-
line = "#{csi}#{
|
|
182
|
-
size =
|
|
179
|
+
snippet = words.pop
|
|
180
|
+
line = "#{csi}#{snippet}"
|
|
181
|
+
size = snippet.size
|
|
183
182
|
else
|
|
184
183
|
line = "#{csi}"
|
|
185
184
|
size = 0
|
|
@@ -189,51 +188,51 @@ module Terminal
|
|
|
189
188
|
nil
|
|
190
189
|
end
|
|
191
190
|
|
|
192
|
-
def pairs(
|
|
191
|
+
def pairs(snippets)
|
|
193
192
|
line = @empty.dup
|
|
194
193
|
size = 0
|
|
195
194
|
csi = nil
|
|
196
|
-
|
|
197
|
-
if
|
|
195
|
+
snippets.each do |snippet|
|
|
196
|
+
if snippet == :space
|
|
198
197
|
next if size == 0
|
|
199
198
|
line << ' '
|
|
200
199
|
next size += 1
|
|
201
200
|
end
|
|
202
201
|
|
|
203
|
-
if
|
|
202
|
+
if snippet == :nl
|
|
204
203
|
line[-1] == ' ' ? yield(line.chop, size - 1) : yield(line, size)
|
|
205
204
|
line = "#{csi}"
|
|
206
205
|
next size = 0
|
|
207
206
|
end
|
|
208
207
|
|
|
209
|
-
if
|
|
208
|
+
if snippet == :hard_nl
|
|
210
209
|
line[-1] == ' ' ? yield(line.chop, size - 1) : yield(line, size)
|
|
211
210
|
line = @empty.dup
|
|
212
211
|
csi = nil
|
|
213
212
|
next size = 0
|
|
214
213
|
end
|
|
215
214
|
|
|
216
|
-
if
|
|
215
|
+
if snippet == CsiEnd
|
|
217
216
|
line << CsiEnd if csi
|
|
218
217
|
next csi = nil
|
|
219
218
|
end
|
|
220
219
|
|
|
221
|
-
next line << (csi =
|
|
222
|
-
next line <<
|
|
220
|
+
next line << (csi = snippet) if snippet.is_a?(Csi)
|
|
221
|
+
next line << snippet if snippet.is_a?(Osc)
|
|
223
222
|
|
|
224
223
|
# Word:
|
|
225
|
-
line <<
|
|
226
|
-
size +=
|
|
224
|
+
line << snippet
|
|
225
|
+
size += snippet.size
|
|
227
226
|
end
|
|
228
227
|
nil
|
|
229
228
|
end
|
|
230
229
|
|
|
231
|
-
def lim_lines(
|
|
230
|
+
def lim_lines(snippets, limit)
|
|
232
231
|
line = @empty.dup
|
|
233
232
|
size = 0
|
|
234
233
|
csi = nil
|
|
235
|
-
|
|
236
|
-
if
|
|
234
|
+
snippets.each do |snippet|
|
|
235
|
+
if snippet == :space
|
|
237
236
|
next if size == 0
|
|
238
237
|
next line << ' ' if (size += 1) <= limit
|
|
239
238
|
yield(line)
|
|
@@ -241,31 +240,31 @@ module Terminal
|
|
|
241
240
|
next size = 0
|
|
242
241
|
end
|
|
243
242
|
|
|
244
|
-
if
|
|
243
|
+
if snippet == :nl
|
|
245
244
|
yield(line[-1] == ' ' ? line.chop : line)
|
|
246
245
|
line = "#{csi}"
|
|
247
246
|
next size = 0
|
|
248
247
|
end
|
|
249
248
|
|
|
250
|
-
if
|
|
249
|
+
if snippet == :hard_nl
|
|
251
250
|
yield(line[-1] == ' ' ? line.chop : line)
|
|
252
251
|
line = @empty.dup
|
|
253
252
|
csi = nil
|
|
254
253
|
next size = 0
|
|
255
254
|
end
|
|
256
255
|
|
|
257
|
-
if
|
|
256
|
+
if snippet == CsiEnd
|
|
258
257
|
line << CsiEnd if csi
|
|
259
258
|
next csi = nil
|
|
260
259
|
end
|
|
261
260
|
|
|
262
|
-
next line << (csi =
|
|
263
|
-
next line <<
|
|
261
|
+
next line << (csi = snippet) if snippet.is_a?(Csi)
|
|
262
|
+
next line << snippet if snippet.is_a?(Osc)
|
|
264
263
|
|
|
265
264
|
# Word:
|
|
266
265
|
|
|
267
|
-
if (ns = size +
|
|
268
|
-
line <<
|
|
266
|
+
if (ns = size + snippet.size) <= limit
|
|
267
|
+
line << snippet
|
|
269
268
|
next size = ns
|
|
270
269
|
end
|
|
271
270
|
|
|
@@ -275,16 +274,16 @@ module Terminal
|
|
|
275
274
|
end
|
|
276
275
|
yield(line) if size != 0
|
|
277
276
|
|
|
278
|
-
if
|
|
279
|
-
line = "#{csi}#{
|
|
280
|
-
next size =
|
|
277
|
+
if snippet.size <= limit
|
|
278
|
+
line = "#{csi}#{snippet}"
|
|
279
|
+
next size = snippet.size
|
|
281
280
|
end
|
|
282
281
|
|
|
283
|
-
words =
|
|
282
|
+
words = snippet.split(limit)
|
|
284
283
|
if words[-1].size <= limit
|
|
285
|
-
|
|
286
|
-
line = "#{csi}#{
|
|
287
|
-
size =
|
|
284
|
+
snippet = words.pop
|
|
285
|
+
line = "#{csi}#{snippet}"
|
|
286
|
+
size = snippet.size
|
|
288
287
|
else
|
|
289
288
|
line = "#{csi}"
|
|
290
289
|
size = 0
|
|
@@ -294,46 +293,46 @@ module Terminal
|
|
|
294
293
|
nil
|
|
295
294
|
end
|
|
296
295
|
|
|
297
|
-
def lines(
|
|
296
|
+
def lines(snippets)
|
|
298
297
|
line = @empty.dup
|
|
299
298
|
size = 0
|
|
300
299
|
csi = nil
|
|
301
|
-
|
|
302
|
-
if
|
|
300
|
+
snippets.each do |snippet|
|
|
301
|
+
if snippet == :space
|
|
303
302
|
next if size == 0
|
|
304
303
|
line << ' '
|
|
305
304
|
next size += 1
|
|
306
305
|
end
|
|
307
306
|
|
|
308
|
-
if
|
|
307
|
+
if snippet == :nl
|
|
309
308
|
yield(line[-1] == ' ' ? line.chop : line)
|
|
310
309
|
line = "#{csi}"
|
|
311
310
|
next size = 0
|
|
312
311
|
end
|
|
313
312
|
|
|
314
|
-
if
|
|
313
|
+
if snippet == :hard_nl
|
|
315
314
|
yield(line[-1] == ' ' ? line.chop : line)
|
|
316
315
|
line = @empty.dup
|
|
317
316
|
csi = nil
|
|
318
317
|
next size = 0
|
|
319
318
|
end
|
|
320
319
|
|
|
321
|
-
if
|
|
320
|
+
if snippet == CsiEnd
|
|
322
321
|
line << CsiEnd if csi
|
|
323
322
|
next csi = nil
|
|
324
323
|
end
|
|
325
324
|
|
|
326
|
-
next line << (csi =
|
|
327
|
-
next line <<
|
|
325
|
+
next line << (csi = snippet) if snippet.is_a?(Csi)
|
|
326
|
+
next line << snippet if snippet.is_a?(Osc)
|
|
328
327
|
|
|
329
328
|
# Word:
|
|
330
|
-
line <<
|
|
331
|
-
size +=
|
|
329
|
+
line << snippet
|
|
330
|
+
size += snippet.size
|
|
332
331
|
end
|
|
333
332
|
nil
|
|
334
333
|
end
|
|
335
334
|
|
|
336
|
-
def
|
|
335
|
+
def as_snippets(text, bbcode, ansi, ignore_newline, word_class)
|
|
337
336
|
ret = []
|
|
338
337
|
last = nil
|
|
339
338
|
text.each do |txt|
|
|
@@ -451,7 +450,7 @@ module Terminal
|
|
|
451
450
|
SCAN_EXPR =
|
|
452
451
|
/\G(?:
|
|
453
452
|
(\r?\n)
|
|
454
|
-
| (\e\[[\d
|
|
453
|
+
| (\e\[[\d;:?]*[ABCDEFGHJKSTfhilmnsu])
|
|
455
454
|
| (\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
|
456
455
|
| (\s+)
|
|
457
456
|
| (\X)
|
|
@@ -459,7 +458,7 @@ module Terminal
|
|
|
459
458
|
|
|
460
459
|
WIDTH_SCANNER =
|
|
461
460
|
/\G(?:
|
|
462
|
-
(?:\e\[[\d
|
|
461
|
+
(?:\e\[[\d;:?]*[ABCDEFGHJKSTfhilmnsu])
|
|
463
462
|
| (?:\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
|
464
463
|
| (\s+)
|
|
465
464
|
| (\X)
|
data/lib/terminal/version.rb
CHANGED
data/lib/terminal.rb
CHANGED
|
@@ -154,6 +154,30 @@ module Terminal
|
|
|
154
154
|
self
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
+
# Show the alternate screen.
|
|
158
|
+
# Will not send the control code if the alternate screen is already used.
|
|
159
|
+
#
|
|
160
|
+
# When you called {show_alt_screen} n-times you need to call
|
|
161
|
+
# {hide_alt_screen} n-times to show the default screen again.
|
|
162
|
+
#
|
|
163
|
+
# @return [Terminal] itself
|
|
164
|
+
def show_alt_screen
|
|
165
|
+
raw_write(Ansi::SCREEN_ALTERNATE) if ansi? && (@as += 1) == 1
|
|
166
|
+
self
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Hide the alternate screen.
|
|
170
|
+
# Will not send the control code if the alternate screen is not used.
|
|
171
|
+
#
|
|
172
|
+
# When you called {show_alt_screen} n-times you need to call
|
|
173
|
+
# {hide_alt_screen} n-times to show the default screen again.
|
|
174
|
+
#
|
|
175
|
+
# @return [Terminal] itself
|
|
176
|
+
def hide_alt_screen
|
|
177
|
+
raw_write(Ansi::SCREEN_ALTERNATE_OFF) if @as > 0 && (@as -= 1).zero?
|
|
178
|
+
self
|
|
179
|
+
end
|
|
180
|
+
|
|
157
181
|
# Writes the given object to the terminal.
|
|
158
182
|
# Interprets embedded BBCode.
|
|
159
183
|
#
|
|
@@ -290,7 +314,7 @@ module Terminal
|
|
|
290
314
|
end
|
|
291
315
|
end
|
|
292
316
|
|
|
293
|
-
@cc = 0
|
|
317
|
+
@cc = @as = 0
|
|
294
318
|
tty, @ansi = _determine_modes
|
|
295
319
|
|
|
296
320
|
unless tty.nil?
|
data/terminal_rb.gemspec
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/terminal/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'terminal_rb'
|
|
7
|
+
spec.version = Terminal::VERSION
|
|
8
|
+
spec.summary =
|
|
9
|
+
'Fast terminal access with ANSI, CSIu, BBCode, word-wise line break support.'
|
|
10
|
+
spec.description = <<~DESCRIPTION.tr("\n", ' ')
|
|
11
|
+
Terminal.rb supports you with input and output on your terminal.
|
|
12
|
+
Simple BBCode-like markup for attributes and coloring, word-wise line
|
|
13
|
+
breaks, and correct special key recognition enable you to implement your
|
|
14
|
+
CLI app quickly and easily.
|
|
15
|
+
DESCRIPTION
|
|
16
|
+
|
|
17
|
+
spec.author = 'Mike Blumtritt'
|
|
18
|
+
spec.licenses = %w[MIT Ruby]
|
|
19
|
+
spec.homepage = 'https://codeberg.org/mblumtritt/Terminal.rb'
|
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
|
|
22
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/terminal_rb'
|
|
23
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
24
|
+
spec.metadata['yard.run'] = 'yard'
|
|
25
|
+
|
|
26
|
+
spec.required_ruby_version = '> 3.0'
|
|
27
|
+
|
|
28
|
+
spec.files = Dir['lib/**/*.rb']
|
|
29
|
+
spec.files += Dir['examples/*.rb']
|
|
30
|
+
spec.files += %w[terminal_rb.gemspec .yardopts]
|
|
31
|
+
spec.executables = %w[bbcode]
|
|
32
|
+
spec.extra_rdoc_files = %w[README.md]
|
|
33
|
+
end
|
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.
|
|
4
|
+
version: 0.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
@@ -28,6 +28,7 @@ files:
|
|
|
28
28
|
- examples/bbcode.rb
|
|
29
29
|
- examples/info.rb
|
|
30
30
|
- examples/key-codes.rb
|
|
31
|
+
- examples/text.rb
|
|
31
32
|
- lib/terminal.rb
|
|
32
33
|
- lib/terminal/ansi.rb
|
|
33
34
|
- lib/terminal/ansi/named_colors.rb
|
|
@@ -40,9 +41,11 @@ files:
|
|
|
40
41
|
- lib/terminal/text/char_width.rb
|
|
41
42
|
- lib/terminal/version.rb
|
|
42
43
|
- lib/terminal_rb.rb
|
|
44
|
+
- terminal_rb.gemspec
|
|
43
45
|
homepage: https://codeberg.org/mblumtritt/Terminal.rb
|
|
44
46
|
licenses:
|
|
45
47
|
- MIT
|
|
48
|
+
- Ruby
|
|
46
49
|
metadata:
|
|
47
50
|
source_code_uri: https://codeberg.org/mblumtritt/Terminal.rb
|
|
48
51
|
bug_tracker_uri: https://codeberg.org/mblumtritt/Terminal.rb/issues
|
|
@@ -63,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
63
66
|
- !ruby/object:Gem::Version
|
|
64
67
|
version: '0'
|
|
65
68
|
requirements: []
|
|
66
|
-
rubygems_version: 3.
|
|
69
|
+
rubygems_version: 3.7.2
|
|
67
70
|
specification_version: 4
|
|
68
71
|
summary: Fast terminal access with ANSI, CSIu, BBCode, word-wise line break support.
|
|
69
72
|
test_files: []
|