typr 1.7.0 → 1.9.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.
data/lib/text.rb CHANGED
@@ -22,7 +22,12 @@ module Typr
22
22
 
23
23
  class Text < Stack
24
24
 
25
- ## Tabstop width in spaces. Default: 2.
25
+ ##
26
+ # Tabstop width in spaces applied by {#build}. Default: 2.
27
+ #
28
+ # text.tabspace = 4
29
+ # text.tabspace #=> 4
30
+
26
31
  attr_accessor :tabspace
27
32
 
28
33
  # Rebuilds the internal line buffer from +input+.
@@ -33,13 +38,19 @@ module Typr
33
38
  # text << "appended line" # alias for build
34
39
 
35
40
  def build input=nil
36
- ( input, @data, @lines = sanitize(@data), "", [0] ) if rebuild = !input
41
+ ( input, @data, @lines = @data, "", [0] ) if rebuild = !input
37
42
  return self if rebuild && input == ""
38
- rows = @lines[0...-1].each_index.map{ |i| sanitize(@data[@lines[i]...@lines[i+1]]) }
43
+ rows = @lines[0...-1].each_index.map{ |i| @data[@lines[i]...@lines[i+1]] }
39
44
  @data = rows.join
40
45
  off = [ 0 ]; rows.each{ |row| off << off.last + row.length }
41
46
  @lines = off
42
47
  str = input.respond_to?(:read) ? input.read : input.to_s
48
+ if !rebuild and (r = @colors[:regex]) and r != {}
49
+ base = color_code( @colors[:default][0] ).to_s
50
+ # Paint new spans once, whole (multiline matches included); rebuilds
51
+ # below only reflow, so paint can neither stack nor need stripping.
52
+ str = Typr.paint(str, r, base)
53
+ end
43
54
  str = str.gsub("\t", " " * @tabspace)
44
55
  @tail = ""
45
56
  pos = 0
@@ -85,14 +96,6 @@ module Typr
85
96
  end
86
97
  end
87
98
  @lines << @data.length unless @lines.last == @data.length
88
- if (r = @colors[:regex]) and r != {}
89
- base = color_code( @colors[:default][0] ).to_s
90
- painted = @lines[0...-1].each_index.map{ |i|
91
- Typr.paint @data[@lines[i]...@lines[i+1]], r, base }
92
- @data = painted.join
93
- off = [ 0 ]; painted.each{ |line| off << off.last + line.length }
94
- @lines = off
95
- end
96
99
  highlight if @re
97
100
  end
98
101
  alias :<< :build
@@ -175,15 +178,31 @@ module Typr
175
178
  step
176
179
  end
177
180
 
178
- ## Jump to the next match of the last search (wrap-around). Returns its line id or nil.
181
+ ##
182
+ # Jump to the next match of the last search (wrap-around).
183
+ #
184
+ # text.search_next #=> 12 (next matching line id, or nil)
185
+ #
186
+ # @return [Integer, nil] matched line id
179
187
 
180
188
  def search_next; @search[:dir] = :forward; step end
181
189
 
182
- ## Jump to the previous match of the last search (wrap-around). Returns its line id or nil.
190
+ ##
191
+ # Jump to the previous match of the last search (wrap-around).
192
+ #
193
+ # text.search_prev #=> 12 (previous matching line id, or nil)
194
+ #
195
+ # @return [Integer, nil] matched line id
183
196
 
184
197
  def search_prev; @search[:dir] = :backward; step end
185
198
 
186
- ## Recompute the set of lines containing the current pattern.
199
+ ##
200
+ # Recompute the set of lines containing the current pattern (called
201
+ # by {#search} and {#build}).
202
+ #
203
+ # text.highlight # @search[:matches] updated
204
+ #
205
+ # @return [nil]
187
206
 
188
207
  def highlight
189
208
  @search[:matches] = @re ?
@@ -192,7 +211,12 @@ module Typr
192
211
  return
193
212
  end
194
213
 
195
- ## Clear the search pattern and all match highlights.
214
+ ##
215
+ # Clear the search pattern and all match highlights.
216
+ #
217
+ # text.highlight_clear # matches => [], pattern => nil
218
+ #
219
+ # @return [nil]
196
220
 
197
221
  def highlight_clear
198
222
  @re = @search[:pattern] = nil
@@ -217,8 +241,17 @@ module Typr
217
241
  self << @input
218
242
  end
219
243
 
220
- # Reset state: +:search+ clears the pattern and highlights; +:all+ resets
221
- # position, selection, and search; else falls through to {Stack#reset}.
244
+ ##
245
+ # Reset state: +:search+ clears the pattern and highlights, +:all+
246
+ # resets position, selection, and search; anything else falls through
247
+ # to {Stack#reset}.
248
+ #
249
+ # text.reset :search
250
+ # text.reset :all
251
+ #
252
+ # @param type [:search, :all, :position, :selection, Array<Symbol>]
253
+ # @return [void]
254
+
222
255
  def reset type=:all
223
256
  case type
224
257
  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 answers
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
  #
data/typr.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "typr"
5
- s.version = "1.7.0"
6
- s.date = "2026-10-02"
5
+ s.version = "1.9.0"
6
+ s.date = "2026-10-12"
7
7
  s.homepage = "https://codeberg.org/typr/typr"
8
8
  s.licenses = ["MIT"]
9
9
  s.require_paths = ["lib"]
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.7.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kilian Reitmayr
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-10-02 00:00:00.000000000 Z
10
+ date: 2026-10-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: unicode-display_width