typr 1.8.0 → 1.9.2
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/CHANGELOG.md +24 -0
- data/README.md +4 -4
- data/lib/browser.rb +98 -19
- data/lib/grid.rb +120 -31
- data/lib/line.rb +50 -8
- data/lib/space.rb +113 -8
- data/lib/stack.rb +106 -34
- data/lib/terminal.rb +393 -55
- data/lib/text.rb +57 -11
- data/lib/typr.rb +5 -3
- data/typr.gemspec +2 -2
- metadata +2 -2
data/lib/text.rb
CHANGED
|
@@ -4,7 +4,9 @@ require_relative 'stack.rb'
|
|
|
4
4
|
module Typr
|
|
5
5
|
|
|
6
6
|
# A vertically scrollable text viewer with word-wrapping, header bar,
|
|
7
|
-
# row selection via hint characters
|
|
7
|
+
# row selection via hint characters (+pick :row+), word selection via
|
|
8
|
+
# +pick :column+ (hints sit on word boundaries), and pager-style
|
|
9
|
+
# search (/ n p).
|
|
8
10
|
#
|
|
9
11
|
# Accepts String, IO, or StringIO input. Content is split into display
|
|
10
12
|
# rows by newlines and line width, then rendered as a sliding window.
|
|
@@ -22,7 +24,12 @@ module Typr
|
|
|
22
24
|
|
|
23
25
|
class Text < Stack
|
|
24
26
|
|
|
25
|
-
##
|
|
27
|
+
##
|
|
28
|
+
# Tabstop width in spaces applied by {#build}. Default: 2.
|
|
29
|
+
#
|
|
30
|
+
# text.tabspace = 4
|
|
31
|
+
# text.tabspace #=> 4
|
|
32
|
+
|
|
26
33
|
attr_accessor :tabspace
|
|
27
34
|
|
|
28
35
|
# Rebuilds the internal line buffer from +input+.
|
|
@@ -32,6 +39,9 @@ module Typr
|
|
|
32
39
|
# text.build("one\ntwo three") # => #<Typr::Text ...>
|
|
33
40
|
# text << "appended line" # alias for build
|
|
34
41
|
|
|
42
|
+
# @param input [String, IO, nil] text (or stream) to append; nil reflows
|
|
43
|
+
# @return [Text] self
|
|
44
|
+
|
|
35
45
|
def build input=nil
|
|
36
46
|
( input, @data, @lines = @data, "", [0] ) if rebuild = !input
|
|
37
47
|
return self if rebuild && input == ""
|
|
@@ -77,7 +87,7 @@ module Typr
|
|
|
77
87
|
else
|
|
78
88
|
@tail = ""
|
|
79
89
|
end
|
|
80
|
-
@lines << @data.length if
|
|
90
|
+
@lines << @data.length if line.include?("\n") || pos < str.size || !@tail.empty?
|
|
81
91
|
end
|
|
82
92
|
until @tail.empty?
|
|
83
93
|
wrap_idx = @tail.index("\n") || @tail.rindex(" ") || @tail.length
|
|
@@ -92,6 +102,7 @@ module Typr
|
|
|
92
102
|
end
|
|
93
103
|
@lines << @data.length unless @lines.last == @data.length
|
|
94
104
|
highlight if @re
|
|
105
|
+
self
|
|
95
106
|
end
|
|
96
107
|
alias :<< :build
|
|
97
108
|
|
|
@@ -132,8 +143,7 @@ module Typr
|
|
|
132
143
|
def show
|
|
133
144
|
(build; @lastwidth = width) if width != @lastwidth
|
|
134
145
|
range = @lines[@start..@start+height]
|
|
135
|
-
page =
|
|
136
|
-
@page=range[1..-1].map{|pos| page.read(pos-range.first-page.pos).rstrip}
|
|
146
|
+
@page = range.each_cons(2).map{ |a, b| @data[a...b].rstrip }
|
|
137
147
|
super
|
|
138
148
|
end
|
|
139
149
|
|
|
@@ -173,15 +183,31 @@ module Typr
|
|
|
173
183
|
step
|
|
174
184
|
end
|
|
175
185
|
|
|
176
|
-
##
|
|
186
|
+
##
|
|
187
|
+
# Jump to the next match of the last search (wrap-around).
|
|
188
|
+
#
|
|
189
|
+
# text.search_next #=> 12 (next matching line id, or nil)
|
|
190
|
+
#
|
|
191
|
+
# @return [Integer, nil] matched line id
|
|
177
192
|
|
|
178
193
|
def search_next; @search[:dir] = :forward; step end
|
|
179
194
|
|
|
180
|
-
##
|
|
195
|
+
##
|
|
196
|
+
# Jump to the previous match of the last search (wrap-around).
|
|
197
|
+
#
|
|
198
|
+
# text.search_prev #=> 12 (previous matching line id, or nil)
|
|
199
|
+
#
|
|
200
|
+
# @return [Integer, nil] matched line id
|
|
181
201
|
|
|
182
202
|
def search_prev; @search[:dir] = :backward; step end
|
|
183
203
|
|
|
184
|
-
##
|
|
204
|
+
##
|
|
205
|
+
# Recompute the set of lines containing the current pattern (called
|
|
206
|
+
# by {#search} and {#build}).
|
|
207
|
+
#
|
|
208
|
+
# text.highlight # @search[:matches] updated
|
|
209
|
+
#
|
|
210
|
+
# @return [nil]
|
|
185
211
|
|
|
186
212
|
def highlight
|
|
187
213
|
@search[:matches] = @re ?
|
|
@@ -190,7 +216,12 @@ module Typr
|
|
|
190
216
|
return
|
|
191
217
|
end
|
|
192
218
|
|
|
193
|
-
##
|
|
219
|
+
##
|
|
220
|
+
# Clear the search pattern and all match highlights.
|
|
221
|
+
#
|
|
222
|
+
# text.highlight_clear # matches => [], pattern => nil
|
|
223
|
+
#
|
|
224
|
+
# @return [nil]
|
|
194
225
|
|
|
195
226
|
def highlight_clear
|
|
196
227
|
@re = @search[:pattern] = nil
|
|
@@ -203,6 +234,12 @@ module Typr
|
|
|
203
234
|
#
|
|
204
235
|
# text = Typr::Text.new(input: "hello", header: "Title")
|
|
205
236
|
# text = Typr::Text.new(input: $stdin, tabspace: 4)
|
|
237
|
+
#
|
|
238
|
+
# Option | Value
|
|
239
|
+
# -----------|------------------------------------------------
|
|
240
|
+
# +input+ | String, IO, or StringIO (nil reflows from empty)
|
|
241
|
+
# +tabspace+ | tabstop width in spaces (default 2)
|
|
242
|
+
# +colors+ | +regex:+ paint map or scheme name (see {Typr.paint})
|
|
206
243
|
|
|
207
244
|
def initialize args={}
|
|
208
245
|
@tabspace = 2
|
|
@@ -215,8 +252,17 @@ module Typr
|
|
|
215
252
|
self << @input
|
|
216
253
|
end
|
|
217
254
|
|
|
218
|
-
|
|
219
|
-
#
|
|
255
|
+
##
|
|
256
|
+
# Reset state: +:search+ clears the pattern and highlights, +:all+
|
|
257
|
+
# resets position, selection, and search; anything else falls through
|
|
258
|
+
# to {Stack#reset}.
|
|
259
|
+
#
|
|
260
|
+
# text.reset :search
|
|
261
|
+
# text.reset :all
|
|
262
|
+
#
|
|
263
|
+
# @param type [:search, :all, :position, :selection, Array<Symbol>]
|
|
264
|
+
# @return [void]
|
|
265
|
+
|
|
220
266
|
def reset type=:all
|
|
221
267
|
case type
|
|
222
268
|
when :search; highlight_clear
|
data/lib/typr.rb
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
#
|
|
6
6
|
# * Typr::Grid - Sortable, filterable table with formatted columns and row selection
|
|
7
7
|
# * Typr::Text - Scrollable text viewer with word/line picking and search
|
|
8
|
-
# * Typr::Browser - File-system directory browser with MIME type detection
|
|
8
|
+
# * Typr::Browser - File-system directory browser with MIME type detection,
|
|
9
|
+
# live / narrowing, mark/range selection, and a rebindable keybar
|
|
9
10
|
# * Typr::Stack - Scrollable container with keyboard navigation and hint overlays
|
|
10
11
|
# * Typr::Space - Base layout primitive with border drawing
|
|
11
|
-
# * Typr::Line - Interactive prompt/input with colored questions and
|
|
12
|
+
# * Typr::Line - Interactive prompt/input with colored questions and
|
|
13
|
+
# answers, ask question types, and shell command-line completion
|
|
12
14
|
#
|
|
13
15
|
# == Terminal Control
|
|
14
16
|
#
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
# grid = Typr::Grid.new(
|
|
36
38
|
# input: [['Alice', 30], ['Bob', 25]],
|
|
37
39
|
# header: ['Name', 'Age'],
|
|
38
|
-
# format: [:max, :
|
|
40
|
+
# format: [:max, :min]
|
|
39
41
|
# )
|
|
40
42
|
# grid.show
|
|
41
43
|
# key = Typr.read_key
|
data/typr.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kilian Reitmayr
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-10-
|
|
10
|
+
date: 2026-10-13 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: unicode-display_width
|