natty-ui 0.9.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88f26cebef7a281c4b11df8e8accf096706d4308aa22d716bb516f9c85b51be6
4
- data.tar.gz: 62fc6e920615b9f4536da8a9db33cc9e4261352d36a3423cdd11c64ab7b2e93c
3
+ metadata.gz: 53cd6e051da19fb57efdfe448cfdb6ede5e7bdae3c8d59db5690ea32bb9bcd39
4
+ data.tar.gz: 39a38e0d1c1314e881b72aa7a6d74fdba47225ffadb110a47fd0db305095a564
5
5
  SHA512:
6
- metadata.gz: 231f29c1bca8face152dbb63ed1c6137866a97941e092ed3db3f30ee2c372d71bbb10b1885100fd28691fb6093d2d4deab14fcf8d95fe05106cfc0c2d44d3b66
7
- data.tar.gz: e39a9f14e9adfb4bfc1360cc9ee3dda19f96b3cce23afbf97da2315b184bf5b0b62f62c0f4e6fb283f22029d2902bc14623beec8cb42c45d528ea5168a5bb274
6
+ metadata.gz: cb080dd1ea872a74f1ad1db42be94020cea77892c1fcab5a4b7850f78c2624d9a5bb9576442b352975644f66de3bc9e2d446e2a73c5dad9390b85b0c187da1ee
7
+ data.tar.gz: c2c5ee5cfbfcc1481ab842470f654176836b962d0ffc6cc3019c5e2e45b3c50cfd0613b9c7c6a82d9800e2b84e3cc26f538a959095101a512d33947be8d8d684
@@ -7,10 +7,9 @@ ui.framed do
7
7
  This is the [[c4]]beautiful[[/]], [[c5]]nice[[/]], [[c6]]nifty[[/]],
8
8
  [[c7]]fancy[[/]], [[c8]]neat[[/]], [[c9]]pretty[[/]], [[ca]]cool[[/]],
9
9
  [[cb]]lovely[[/]], [[cc]]natty[[/]] [[bold]]user interface[[/]] you like to
10
- have for your command line applications. It contains
11
- [[curly_underline ul_c4]]elegant[[/]], [[italic]]simple[[/]] and
12
- [[double_underline ul_cc]]beautiful[[/]] tools that enhance your command
13
- line interfaces functionally and aesthetically.
10
+ have for your command line applications. It contains [[italic]]elegant[[/]],
11
+ [[italic]]simple[[/]] and [[italic]]beautiful[[/]] tools that enhance your
12
+ command line interfaces functionally and aesthetically.
14
13
  TEXT
15
14
 
16
15
  ui.msg('Features', glyph: '⭐️') { ui.ls(<<~FEATURES.lines(chomp: true)) }
data/lib/natty-ui/ansi.rb CHANGED
@@ -209,9 +209,9 @@ module NattyUI
209
209
  when (0..255)
210
210
  "38;5;#{arg}"
211
211
  when (256..511)
212
- "48;5;#{arg}"
212
+ "48;5;#{arg - 256}"
213
213
  when (512..767)
214
- "58;5;#{arg}"
214
+ "58;5;#{arg - 512}"
215
215
  else
216
216
  invalid_argument(arg)
217
217
  end
@@ -331,7 +331,12 @@ module NattyUI
331
331
  end
332
332
  end
333
333
 
334
- ESC = /(#{Reline::Unicode::CSI_REGEXP})|(#{Reline::Unicode::OSC_REGEXP})/
334
+ CSI = /\e\[[\d;:]*[ABCDEFGHJKSTfminsuhl]/
335
+ OSC = /\e\]\d+(?:;[^;\a\e]+)*(?:\a|\e\\)/
336
+ ESC = /(#{CSI})|(#{OSC})/
337
+
338
+ # @!visibility private
339
+ WIDTH_SCANNER = /\G(?:(\1)|(\2)|(#{CSI})|(#{OSC})|(\X))/
335
340
 
336
341
  CLR_PREFIX = {
337
342
  'fg' => '38',
@@ -340,8 +345,8 @@ module NattyUI
340
345
  'on' => '48'
341
346
  }.freeze
342
347
 
343
- PI2_THIRD = 2 * Math::PI / 3.0
344
- PI4_THIRD = 4 * Math::PI / 3.0
348
+ PI2_THIRD = 2 * Math::PI / 3
349
+ PI4_THIRD = 4 * Math::PI / 3
345
350
 
346
351
  SATTR =
347
352
  Module
@@ -349,6 +354,7 @@ module NattyUI
349
354
  def self.to_hash
350
355
  map = {
351
356
  # alternative names
357
+ reset: '',
352
358
  slow_blink: 5,
353
359
  conceal: 8,
354
360
  default_font: 10,
@@ -370,9 +376,8 @@ module NattyUI
370
376
  }
371
377
  add = ->(s, n) { n.each_with_index { |a, idx| map[a] = s + idx } }
372
378
  add[
373
- 0,
379
+ 1,
374
380
  %i[
375
- reset
376
381
  bold
377
382
  faint
378
383
  italic
@@ -480,6 +485,8 @@ module NattyUI
480
485
  SCLR = CLR.transform_keys(&:to_sym).compare_by_identity.freeze
481
486
 
482
487
  private_constant(
488
+ :CSI,
489
+ :OSC,
483
490
  :ESC,
484
491
  :CLR_PREFIX,
485
492
  :PI2_THIRD,
@@ -4,42 +4,31 @@ module NattyUI
4
4
  module Ansi
5
5
  CURSOR_SHOW = "\e[?25h"
6
6
  CURSOR_HIDE = "\e[?25l"
7
+
7
8
  CURSOR_HOME = cursor_pos(nil, nil)
8
9
  CURSOR_FIRST_ROW = cursor_pos(1).freeze
9
10
  CURSOR_FIRST_COLUMN = cursor_column(1).freeze
11
+
10
12
  CURSOR_SAFE_POS_SCO = "\e[s"
11
- CURSOR_RESTORE_POS_SCO = "\e[u"
12
13
  CURSOR_SAFE_POS_DEC = "\e7"
13
- CURSOR_RESTORE_POS_DEC = "\e8"
14
14
  CURSOR_SAFE_POS = CURSOR_SAFE_POS_DEC
15
- CURSOR_RESTORE_POS = CURSOR_RESTORE_POS_DEC
16
15
 
17
- CURSOR_ALIGN_RIGHT = "\e[9999G\e[1D\e[1C" # @!visibility private
16
+ CURSOR_RESTORE_POS_SCO = "\e[u"
17
+ CURSOR_RESTORE_POS_DEC = "\e8"
18
+ CURSOR_RESTORE_POS = CURSOR_RESTORE_POS_DEC
18
19
 
19
20
  SCREEN_ERASE = screen_erase(:entire)
21
+
20
22
  SCREEN_SAVE = "\e[?47h"
21
23
  SCREEN_RESTORE = "\e[?47l"
24
+
22
25
  SCREEN_ALTERNATE = "\e[?1049h"
23
26
  SCREEN_ALTERNATE_OFF = "\e[?1049l"
24
- SCREEN_SAVE_ATTRIBUTES = '\e[#{'
25
- SCREEN_RESTORE_ATTRIBUTES = '\e[#}'
26
-
27
- SCREEN_BLANK = "\e[0m\e[s\e[?47h\e[H\e[2J" # @!visibility private
28
- SCREEN_UNBLANK = "\e[?47l\e[u\e[0m" # @!visibility private
29
27
 
30
28
  LINE_PREVIOUS = cursor_previous_line(1).freeze
31
29
  LINE_NEXT = cursor_next_line(1).freeze
32
30
  LINE_ERASE = line_erase(:entire)
33
31
 
34
- # ANSI control code sequence to erase the screen and set cursor position on
35
- # upper left corner.
36
- CLS = (CURSOR_HOME + SCREEN_ERASE).freeze
37
-
38
- # ANSI control code sequence to erase current line and position to first
39
- # column.
40
- CLL = (LINE_ERASE + CURSOR_FIRST_COLUMN).freeze
41
-
42
- # ANSI control code to reset all attributes.
43
32
  RESET = self[:reset].freeze
44
33
 
45
34
  BOLD = self[:bold].freeze
@@ -69,5 +58,20 @@ module NattyUI
69
58
 
70
59
  HIDE = self[:hide].freeze
71
60
  REVEAL = self[:reveal].freeze
61
+
62
+ # @!visibility private
63
+ CLS = (CURSOR_HOME + SCREEN_ERASE).freeze
64
+
65
+ # @!visibility private
66
+ CLL = (CURSOR_FIRST_COLUMN + LINE_ERASE).freeze
67
+
68
+ # @!visibility private
69
+ SCREEN_BLANK =
70
+ (
71
+ CURSOR_SAFE_POS + SCREEN_ALTERNATE + CURSOR_HOME + SCREEN_ERASE + RESET
72
+ ).freeze
73
+
74
+ # @!visibility private
75
+ SCREEN_UNBLANK = (RESET + SCREEN_ALTERNATE_OFF + CURSOR_RESTORE_POS).freeze
72
76
  end
73
77
  end
@@ -80,7 +80,7 @@ module NattyUI
80
80
  lambda do
81
81
  count = @lines_written - count
82
82
  if count.nonzero?
83
- @stream << Ansi.cursor_prev_line(count) << Ansi.display(:erase_below)
83
+ @stream << Ansi.cursor_prev_line(count) << Ansi.screen_erase(:below)
84
84
  @lines_written -= count
85
85
  end
86
86
  @stream.flush
@@ -2,5 +2,5 @@
2
2
 
3
3
  module NattyUI
4
4
  # The version number of the gem.
5
- VERSION = '0.9.1'
5
+ VERSION = '0.9.2'
6
6
  end
data/lib/natty-ui.rb CHANGED
@@ -124,14 +124,12 @@ module NattyUI
124
124
  return 0 if str.empty?
125
125
  width = 0
126
126
  in_zero_width = false
127
- str.scan(
128
- Reline::Unicode::WIDTH_SCANNER
129
- ) do |non_printing_start, non_printing_end, _csi, _osc, gc|
127
+ str.scan(Ansi::WIDTH_SCANNER) do |np_start, np_end, _csi, _osc, gc|
130
128
  if in_zero_width
131
- in_zero_width = false if non_printing_end
129
+ in_zero_width = false if np_end
132
130
  next
133
131
  end
134
- next in_zero_width = true if non_printing_start
132
+ next in_zero_width = true if np_start
135
133
  width += Reline::Unicode.get_mbchar_width(gc) if gc
136
134
  end
137
135
  width
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natty-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-08 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, lovely,