natty-ui 0.12.1 → 0.25.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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +22 -26
  4. data/examples/24bit-colors.rb +4 -7
  5. data/examples/3bit-colors.rb +28 -6
  6. data/examples/8bit-colors.rb +18 -21
  7. data/examples/attributes.rb +30 -22
  8. data/examples/cols.rb +40 -0
  9. data/examples/elements.rb +31 -0
  10. data/examples/examples.rb +45 -0
  11. data/examples/illustration.rb +56 -54
  12. data/examples/ls.rb +16 -16
  13. data/examples/named-colors.rb +23 -0
  14. data/examples/sections.rb +29 -0
  15. data/examples/tables.rb +62 -0
  16. data/examples/tasks.rb +52 -0
  17. data/lib/natty-ui/attributes.rb +604 -0
  18. data/lib/natty-ui/choice.rb +56 -0
  19. data/lib/natty-ui/dumb_choice.rb +45 -0
  20. data/lib/natty-ui/element.rb +78 -0
  21. data/lib/natty-ui/features.rb +798 -0
  22. data/lib/natty-ui/framed.rb +51 -0
  23. data/lib/natty-ui/ls_renderer.rb +93 -0
  24. data/lib/natty-ui/progress.rb +187 -0
  25. data/lib/natty-ui/section.rb +69 -0
  26. data/lib/natty-ui/table.rb +241 -0
  27. data/lib/natty-ui/table_renderer.rb +147 -0
  28. data/lib/natty-ui/task.rb +44 -0
  29. data/lib/natty-ui/temporary.rb +38 -0
  30. data/lib/natty-ui/theme.rb +303 -0
  31. data/lib/natty-ui/utils.rb +79 -0
  32. data/lib/natty-ui/version.rb +1 -1
  33. data/lib/natty-ui/width_finder.rb +125 -0
  34. data/lib/natty-ui.rb +89 -147
  35. metadata +44 -53
  36. data/examples/animate.rb +0 -42
  37. data/examples/attributes_list.rb +0 -12
  38. data/examples/demo.rb +0 -51
  39. data/examples/message.rb +0 -30
  40. data/examples/progress.rb +0 -66
  41. data/examples/query.rb +0 -39
  42. data/examples/read_key.rb +0 -13
  43. data/examples/table.rb +0 -39
  44. data/lib/natty-ui/animation/binary.rb +0 -36
  45. data/lib/natty-ui/animation/default.rb +0 -38
  46. data/lib/natty-ui/animation/matrix.rb +0 -51
  47. data/lib/natty-ui/animation/rainbow.rb +0 -28
  48. data/lib/natty-ui/animation/type_writer.rb +0 -44
  49. data/lib/natty-ui/animation.rb +0 -69
  50. data/lib/natty-ui/ansi/constants.rb +0 -75
  51. data/lib/natty-ui/ansi.rb +0 -530
  52. data/lib/natty-ui/ansi_wrapper.rb +0 -232
  53. data/lib/natty-ui/frame.rb +0 -53
  54. data/lib/natty-ui/glyph.rb +0 -64
  55. data/lib/natty-ui/key_map.rb +0 -142
  56. data/lib/natty-ui/preload.rb +0 -12
  57. data/lib/natty-ui/spinner.rb +0 -120
  58. data/lib/natty-ui/text/east_asian_width.rb +0 -2529
  59. data/lib/natty-ui/text.rb +0 -203
  60. data/lib/natty-ui/wrapper/animate.rb +0 -17
  61. data/lib/natty-ui/wrapper/ask.rb +0 -78
  62. data/lib/natty-ui/wrapper/element.rb +0 -79
  63. data/lib/natty-ui/wrapper/features.rb +0 -21
  64. data/lib/natty-ui/wrapper/framed.rb +0 -45
  65. data/lib/natty-ui/wrapper/heading.rb +0 -64
  66. data/lib/natty-ui/wrapper/horizontal_rule.rb +0 -37
  67. data/lib/natty-ui/wrapper/list_in_columns.rb +0 -138
  68. data/lib/natty-ui/wrapper/message.rb +0 -109
  69. data/lib/natty-ui/wrapper/mixins.rb +0 -75
  70. data/lib/natty-ui/wrapper/progress.rb +0 -63
  71. data/lib/natty-ui/wrapper/query.rb +0 -89
  72. data/lib/natty-ui/wrapper/quote.rb +0 -25
  73. data/lib/natty-ui/wrapper/request.rb +0 -54
  74. data/lib/natty-ui/wrapper/section.rb +0 -118
  75. data/lib/natty-ui/wrapper/table.rb +0 -550
  76. data/lib/natty-ui/wrapper/task.rb +0 -55
  77. data/lib/natty-ui/wrapper.rb +0 -239
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7b5e669e50f25432d17c55b8cbcc0e9a1c2c181982c08771b03160180586673
4
- data.tar.gz: da124f705a984042e805c83b33565bc5c43e1a97c891ad95abccc5d2e8c62e62
3
+ metadata.gz: 23eed1ba95aaecb2555dfeed5a6fedbcd827299d1e4a64c91952953b3d36d787
4
+ data.tar.gz: 53380e5ebe647a96abbc24baecd1f24a7a3290544ac10e34e3aa8b1e8dba1e17
5
5
  SHA512:
6
- metadata.gz: 4be6c711b6b5cc7d3b6b6800f35e9e5450c44f6b57d139325a4afeeec3b350f26f0719a8909ee9d5d335e26803761bf3d2b31bbd672f47656d70b86ee2dbc465
7
- data.tar.gz: 5b889460d57e3d92bb6bed0ce83fd8c4c6e7fecd8001fcd70674c6f7210550b259fcb4299d61d6a1a1ea376e96704670984a27c8471e07cb427a7fb62059de44
6
+ metadata.gz: 56c829ee249c7cecce24bb9b88c131e8fdaaec20aff2f0340b16d701c77907805f7595d38cfe0e122d4f7365d6ae6babfccdd680b9754de283c7e63c944e78ea
7
+ data.tar.gz: 9964afa255fe3a76d59727f13edcafa31429768729e3b14408f6142f6af17236c7831836857897a0e860044732ad5a347c6bc4efb06ef277412d73d67167519d
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2017-2021, Mike Blumtritt. All rights reserved.
3
+ Copyright (c) 2017-2025, Mike Blumtritt. All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
6
6
  modification, are permitted provided that the following conditions are met:
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # NattyUI ![version](https://img.shields.io/gem/v/natty-ui?label=)
1
+ # NattyUI ​ᓚᕠᗢ ![version](https://img.shields.io/gem/v/natty-ui?label=)
2
2
 
3
3
  This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely, natty user interface you like to have for your command line applications. It contains elegant, simple and beautiful tools that enhance your command line interfaces functionally and aesthetically.
4
4
 
@@ -6,28 +6,24 @@ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely, nat
6
6
  - Source: [github.com](https://github.com/mblumtritt/natty-ui)
7
7
  - Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/NattyUI)
8
8
 
9
- ## Description
10
-
11
- Here you find elegant, simple and beautiful tools that enhance your command line application functionally and look.
12
-
13
- You can style your text using a [BBCode](https://en.wikipedia.org/wiki/BBCode)-like syntax
14
-
15
- ```ruby
16
- ui.puts '[b]Hello World![/b]' # bold
17
- ui.puts '[i]Hello World![/i]' # italic
18
- ui.puts '[u]Hello World![/u]' # underline
19
- ui.puts '[yellow on_blue]Hello World![/]'
20
- ```
21
-
22
- which supports all ANSI attributes, colors in 3/4-bit, 8-bit and Truecolor. There are headers, rulers, diverse message types, framed blocks and tables to layout your text. You can organize the output of tasks, use progress bars and request and handle user input. And there are text animations for fame and fun!
23
-
24
- 🚀 Have a look at the [features](https://rubydoc.info/gems/natty-ui/NattyUI/Features) or check the code [examples](./examples/)!
25
-
26
- ![illustration](https://raw.githubusercontent.com/mblumtritt/natty-ui/main/examples/illustration.png)
27
-
28
- ## NO_COLOR Convention
29
-
30
- NattyUI follows the [NO_COLOR convention](https://no-color.org).
9
+ ## Features
10
+
11
+ ![illustration](./examples/illustration.png)
12
+
13
+ - automatic line break of all text output
14
+ - markup of text attributes and colors using a [BBCode](https://en.wikipedia.org/wiki/BBCode) like syntax
15
+ - automatic detection if ANSI is available
16
+ - support of [NO_COLOR convention](https://no-color.org)
17
+ - support of [CSIu input protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol)
18
+ - headings
19
+ - text separators
20
+ - lists
21
+ - various types of text blocks with automatic alignment
22
+ - text columns
23
+ - tables
24
+ - task lists
25
+ - progress indicators
26
+ - and more!
31
27
 
32
28
  ## Help
33
29
 
@@ -35,16 +31,16 @@ NattyUI follows the [NO_COLOR convention](https://no-color.org).
35
31
 
36
32
  ### Run Examples
37
33
 
38
- You can execute the examples by
34
+ You can execute all examples by
39
35
 
40
36
  ```sh
41
- ruby ./examples/demo.rb
37
+ ruby ./examples/examples.rb
42
38
  ```
43
39
 
44
40
  or see the non-ANSI version
45
41
 
46
42
  ```sh
47
- NO_COLOR=1 ruby ./examples/demo.rb
43
+ NO_COLOR=1 ruby ./examples/examples.rb
48
44
  ```
49
45
 
50
46
  ## Installation
@@ -2,16 +2,13 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.h1 'NattyUI: 24-bit Color Support', space: 2
6
-
7
- ui.section do
8
- bar = '█' * ui.available_width
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]24-bit Color Support[/]' do
6
+ ui.space
7
+ bar = '█' * ui.columns
9
8
  rainbow =
10
9
  (7..17).map do |i|
11
- NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequence: i / 100.0)
10
+ NattyUI::Ansi.rainbow(bar, seed: 3, spread: 3.25, frequency: i / 100.0)
12
11
  end
13
12
 
14
13
  ui.puts(*rainbow)
15
14
  end
16
-
17
- ui.space
@@ -2,11 +2,33 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.h1 'NattyUI: 3/4-bit Color Support', space: 2
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]3/4bit Color Support[/]' do
6
+ ui.space
7
+ ui.puts <<~INFO, ignore_newline: true
8
+ Terminals may support colors. You can colorize foreground text and
9
+ background. The very basic color palette consists of eight colors and may
10
+ be extended with eight colors which are much brighter.
11
+ INFO
6
12
 
7
- color = ->(n, j) { "[#{n}]#{n.ljust(j)}[/] [on_#{n}] sample text [/]" }
8
- %w[black red green yellow blue magenta cyan white].each do |name|
9
- ui.puts "#{color[name, 7]} #{color["bright_#{name}", 14]}"
13
+ ui.space
14
+ ui.ls(
15
+ %w[
16
+ black
17
+ red
18
+ green
19
+ yellow
20
+ blue
21
+ magenta
22
+ cyan
23
+ white
24
+ bright_black
25
+ bright_red
26
+ bright_green
27
+ bright_yellow
28
+ bright_blue
29
+ bright_magenta
30
+ bright_cyan
31
+ bright_white
32
+ ].map { |name| "[bg_#{name}]  [/bg] [#{name}]#{name}[/fg]" }
33
+ )
10
34
  end
11
-
12
- ui.space
@@ -2,32 +2,29 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.h1 'NattyUI: 8-bit Color Support', space: 2
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]8bit Color Support[/]' do
6
+ color = ->(i) { "[bg#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
6
7
 
7
- color = ->(i) { "[bg#{i = i.to_s(16).rjust(2, '0')}] #{i} " }
8
- ui.msg 'System Colors' do
9
- ui.puts <<~COLORS
8
+ ui.space
9
+ ui.message('System Colors', <<~COLORS.chomp)
10
10
  [#ff]#{0.upto(7).map(&color).join}
11
11
  [#00]#{8.upto(15).map(&color).join}
12
-
13
12
  COLORS
14
- end
15
13
 
16
- ui.msg '6x6x6 Color Cube' do
17
- [16, 22, 28].each do |b|
18
- b.step(b + 185, by: 36) do |i|
19
- left = i.upto(i + 5).map(&color).join
20
- right = (i + 18).upto(i + 23).map(&color).join
21
- ui.puts "[#ff]#{left}[bg_default] #{right}"
14
+ ui.space
15
+ ui.message('Grayscale', <<~GRAYSCALE.chomp)
16
+ [#ff]#{0xe8.upto(0xf3).map(&color).join}
17
+ [#ff]#{0xf4.upto(0xff).map(&color).join}
18
+ GRAYSCALE
19
+
20
+ ui.space
21
+ ui.message '6x6x6 Color Cube' do
22
+ [16, 22, 28].each do |b|
23
+ b.step(b + 185, by: 36) do |i|
24
+ left = i.upto(i + 5).map(&color).join
25
+ right = (i + 18).upto(i + 23).map(&color).join
26
+ ui.puts "[#ff]#{left}[bg_default]#{right}"
27
+ end
22
28
  end
23
- ui.space
24
29
  end
25
30
  end
26
-
27
- ui.msg 'Grayscale' do
28
- ui.puts <<~GRAYSCALE
29
- [#ff]#{232.upto(243).map(&color).join}
30
- [#ff]#{244.upto(255).map(&color).join}
31
-
32
- GRAYSCALE
33
- end
@@ -2,25 +2,33 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.h2 'NattyUI: ANSI Attributes', space: 2
6
-
7
- ui.puts <<~PARA1.tr("\n", ' ')
8
- Some attributes are widely supported, such as [b]bold[/b],
9
- [i]italic[/i], [u]underline[/u], [bl]blink[/bl], [inv]invert[/inv] and
10
- [s]strike[/s], while others are rarely complete or correctly implemented, like
11
- [faint]faint[/faint], [double_underline]double underline[/],
12
- [curly_underline]curly underline[/], [dotted_underline]dotted underline[/],
13
- [dashed_underline]dashed underline[/], [rapid_blink]rapid_blink[/],
14
- [framed]framed[/], [encircled]encircled[/], [overlined]overlined[/] and
15
- [proportional]proportional[/].
16
- PARA1
17
-
18
- ui.puts <<~PARA2.tr("\n", ' ')
19
- Alternative fonts are mostly completely ignored:
20
- [primary_font]primary_font[/], [fraktur]fraktur[/],
21
- [font1]font1[/], [font2]font2[/], [font3]font3[/],
22
- [font4]font4[/], [font5]font5[/], [font6]font6[/],
23
- [font7]font7[/], [font8]font8[/], [font9]font9[/].
24
- PARA2
25
-
26
- ui.space
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]ANSI Attributes[/]' do
6
+ ui.space
7
+ ui.puts <<~INFO_1, <<~INFO_2, ignore_newline: true
8
+ NattyUI supports all well known attributes like
9
+ [b]bold[/b],
10
+ [i]italic[/i],
11
+ [u]underline[/u],
12
+ [blink]blink[/blink],
13
+ [inv]invert[/inv]
14
+ and [strike]strike[/strike].
15
+ Other attributes like
16
+ [faint]faint[/faint],
17
+ [double_underline]double underline[/],
18
+ [curly_underline]curly underline[/],
19
+ [dotted_underline]dotted underline[/],
20
+ [dashed_underline]dashed underline[/],
21
+ [rapid_blink]rapid_blink[/],
22
+ [framed]framed[/],
23
+ [encircled]encircled[/],
24
+ [overlined]overlined[/]
25
+ and [proportional]proportional[/]
26
+ are not widely used but also supported.
27
+ INFO_1
28
+ Alternative fonts are mostly completely ignored:
29
+ [primary_font]primary_font[/], [fraktur]fraktur[/],
30
+ [font1]font1[/], [font2]font2[/], [font3]font3[/],
31
+ [font4]font4[/], [font5]font5[/], [font6]font6[/],
32
+ [font7]font7[/], [font8]font8[/], [font9]font9[/].
33
+ INFO_2
34
+ end
data/examples/cols.rb ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Columns[/]' do
6
+ ui.space
7
+ ui.cols(
8
+ 'Here we',
9
+ 'have some',
10
+ 'columns',
11
+ 'which are',
12
+ 'arranged',
13
+ 'and centered',
14
+ align: :centered,
15
+ border: :default
16
+ )
17
+
18
+ ui.space
19
+ ui.cols do |cc|
20
+ cc.add(
21
+ "This is a left aligned blue column with some text but also with with\n" \
22
+ 'a forced line break.',
23
+ style: 'bright_white on_blue',
24
+ align: :left
25
+ )
26
+ cc.add(
27
+ 'This is the middle red column.',
28
+ style: 'bright_white on_red',
29
+ align: :centered,
30
+ vertical: :middle
31
+ )
32
+ cc.add(
33
+ 'This is a right aligned blue column vertically bottom aligned.',
34
+ style: 'bright_white on_blue',
35
+ align: :right,
36
+ vertical: :bottom
37
+ )
38
+ cc.padding = [1, 2]
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Simple Elements[/]' do
6
+ ui.space
7
+ ui.h1('This is a [b]H1[/b] heading element')
8
+
9
+ ui.space
10
+ ui.h2('This is a [b]H2[/b] heading element')
11
+
12
+ ui.space
13
+ ui.quote "This is a\nmulti-line quotation"
14
+
15
+ ui.space
16
+ ui.h3('This is a [b]H3[/b] heading element')
17
+ ui.mark(
18
+ 'This is a multi-line message',
19
+ 'with a leading checkmark.',
20
+ mark: :checkmark
21
+ )
22
+
23
+ ui.space
24
+ ui.h4('This is a [b]H4[/b] heading element')
25
+
26
+ ui.space
27
+ ui.h5('This is a [b]H5[/b] heading element')
28
+
29
+ ui.space
30
+ ui.h6('This is a [b]H6[/b] heading element')
31
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ EXAMPLES = {
6
+ 'attributes' => 'ANSI Attributes',
7
+ '3bit-colors' => '3/4bit Color Support',
8
+ '8bit-colors' => '8bit Color Support',
9
+ '24bit-colors' => '24bit Color Support',
10
+ 'named-colors' => 'Named Colors Support',
11
+ 'elements' => 'Simple Elements',
12
+ 'ls' => 'Print Lists',
13
+ 'tables' => 'Print Tables',
14
+ 'cols' => 'Print Columns',
15
+ 'sections' => 'Sections',
16
+ 'tasks' => 'Tasks'
17
+ }.freeze
18
+
19
+ DEFAULT_MODE = NattyUI.input_mode == :default
20
+
21
+ ui.space
22
+
23
+ while true
24
+ selected =
25
+ ui.choice(**EXAMPLES, abortable: true) do
26
+ ui.cols(
27
+ "[red] /\\_/\\\n( o.o )\n > ^ <",
28
+ '[bright_green b]Select a natty example:',
29
+ width: 8
30
+ )
31
+ ui.div('[faint](Abort with [\\ESC])', padding: [1, 0, 1])
32
+ end
33
+
34
+ ui.space unless DEFAULT_MODE
35
+ break unless selected
36
+
37
+ ui.temporary do
38
+ load("#{__dir__}/#{selected}.rb")
39
+ if DEFAULT_MODE
40
+ ui.await { ui.puts '[faint][\\Press ENTER to continue...]' }
41
+ else
42
+ ui.space
43
+ end
44
+ end
45
+ end
@@ -2,58 +2,60 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.space
6
-
7
- ui.table(type: :undecorated) do |table|
8
- table.add(
9
- 'Styles',
10
- "Support of all ANSI styles like #{
11
- %w[
12
- bold
13
- italic
14
- underline
15
- invert
16
- strike
17
- faint
18
- double_underline
19
- curly_underline
20
- dotted_underline
21
- dashed_underline
22
- blink
23
- ].map { "[#{_1}]#{_1.tr('_', ' ')}[/]" }.join(', ')
24
- }, and even rarely supported like [fraktur]fraktur[/fraktur]."
25
- )
26
-
27
- table.add('Colors', <<~TEXT)
28
- ✓ [green]3/4-bit color[/] ✓ [ff7f50]Truecolor (16.7 million)
29
- ✓ [1b]8-bit color[/] ✓ [bright_yellow]Dumb terminals
30
- ✓ [bright_blue]NO_COLOR convention
31
- TEXT
32
-
33
- table.add(
34
- 'Markup',
35
- '[0c]You can style your text using a [i]BBCode[/i]-like syntax.'
36
- )
37
-
38
- table.add('Layout', <<~TEXT)
39
- 🎩 heading elements 📏 horizontal rulers
40
- 📝 messages [yellow]🄵[/] framed blocks
41
- [blue]┼┼[/] tables
42
- TEXT
43
-
44
- table.add('Tools', <<~TEXT)
45
- ✅ tasks [bold green]…[/] progress bars
46
- [bold bright_white]>[bright_red]_[/] user input 🔦 text animation
47
- TEXT
48
-
49
- table.add("Asian\nlanguage\nsupport", <<~TEXT)
50
- [0a]🇨🇳 该库支持中文,日文和韩文文本!
51
- [0a]🇯🇵 ライブラリは中国語、日本語、韓国語のテキストをサポートしています
52
- [0a]🇰🇷 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다
53
- TEXT
54
-
55
- table.align_column(0, :center)
56
- table.style_column(0, :red)
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b]' do
6
+ ui.table(border: :defaulth, border_style: 'bright_blue') do |table|
7
+ table.add do |row|
8
+ row.add 'Styles'
9
+ row.add <<~TEXT.tr("\n", ' ')
10
+ Support of all ANSI styles like
11
+ [bold]bold[/bold],
12
+ [italic]italic[/italic],
13
+ [underline]underline[/underline],
14
+ [invert]invert[/invert],
15
+ [strike]strike[/strike],
16
+ [faint]faint[/faint],
17
+ [double_underline]double underline[/double_underline],
18
+ [curly_underline]curly underline[/curly_underline],
19
+ [dotted_underline]dotted underline[/dotted_underline],
20
+ [dashed_underline]dashed underline[/dashed_underline]
21
+ and even rarely supported like [fraktur]fraktur[/fraktur].
22
+ TEXT
23
+ end
24
+
25
+ table.add do |row|
26
+ row.add 'Colors'
27
+ row.add <<~TEXT.chomp
28
+ ✓ [palegreen]3/4-bit color[/fg]         ✓ [ff7f50]Truecolor (16.7 million)
29
+ ✓ [skyblue]8-bit color[/fg]           ✓ [gold]Dumb terminals
30
+ ✓ [tan1]NO_COLOR convention
31
+ TEXT
32
+ end
33
+
34
+ table.add do |row|
35
+ row.add 'Markup'
36
+ row.add '[0c]You can style your text using a [i]BBCode[/i]-like syntax.'
37
+ end
38
+
39
+ table.add do |row|
40
+ row.add 'Layout'
41
+ row.add <<~TEXT.chomp
42
+ 🎩 heading elements     📝 messages
43
+ 📏 horizontal rulers    [blue]┼┼[/] tables
44
+ 📋 lists                [b green]✓✓[/] tasks
45
+ TEXT
46
+ end
47
+
48
+ table.add do |row|
49
+ row.add 'Asian', 'language', 'support'
50
+ row.add <<~TEXT.chomp
51
+ [bright_green]🇨🇳 该库支持中文,日文和韩文文本!
52
+ [bright_green]🇯🇵 ライブラリは中国語、日本語、韓国語のテキストをサポートしています
53
+ [bright_green]🇰🇷 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다
54
+ TEXT
55
+ end
56
+
57
+ table.columns[0].style = 'bold red'
58
+ table.columns[0].width = 10
59
+ table.columns[1].padding_right = 2
60
+ end
57
61
  end
58
-
59
- ui.space
data/examples/ls.rb CHANGED
@@ -2,19 +2,17 @@
2
2
 
3
3
  require_relative '../lib/natty-ui'
4
4
 
5
- ui.h1 'NattyUI: Print In Columns', space: 2
6
-
7
- LOREM = <<~IPSUM.lines(chomp: true)
8
- Lorem ipsum dolor sit
9
- amet, consectetur adipisicing
10
- elit, sed do eiusmod tempor
5
+ lorem = <<~IPSUM.lines(chomp: true)
6
+ Lorem ipsum dolor sit amet,
7
+ consectetur adipisicing elit,
8
+ sed do eiusmod tempor
11
9
  incididunt ut labore et
12
- dolore [red]magna[/] aliqua. Ut
13
- enim ad minim veniam, quis
10
+ dolore [red]magna[/] aliqua.
11
+ Ut enim ad minim veniam, quis
14
12
  nostrud exercitation ullamco
15
13
  laboris nisi ut aliquip ex
16
- ea commodo [b]consequat[/b]. Duis
17
- aute irure [bold green]dolor[/fg] in[/]
14
+ ea commodo [b]consequat[/b].
15
+ Duis aute irure [bold green]dolor[/fg] in[/]
18
16
  reprehenderit in voluptate
19
17
  velit [underline]esse cillum[/] dolore eu
20
18
  fugiat nulla pariatur.
@@ -25,10 +23,12 @@ LOREM = <<~IPSUM.lines(chomp: true)
25
23
  est laborum.
26
24
  IPSUM
27
25
 
28
- ui.h2 'Compact Display'
29
- ui.ls LOREM, glyph: 1
30
- ui.space
26
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Lists[/]' do
27
+ ui.space
28
+ ui.h2 'Traditional Display'
29
+ ui.ls lorem, glyph: 1, compact: false
31
30
 
32
- ui.h2 'Traditional Display'
33
- ui.ls LOREM, glyph: 1, compact: false
34
- ui.space
31
+ ui.space
32
+ ui.h2 'Compact Display'
33
+ ui.ls lorem, glyph: 1
34
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Named Colors Support[/]' do
6
+ ui.puts <<~INFO
7
+
8
+ NattyUI supports a series of named color values, such as those supported by Kitty.
9
+
10
+ INFO
11
+
12
+ ui.information('Note') do
13
+ ui.puts('Not all terminal emulators support true-colors.')
14
+ end
15
+
16
+ ui.space
17
+ ui.ls(
18
+ NattyUI::Ansi
19
+ .named_colors
20
+ .delete_if { /\d/.match?(_1) }
21
+ .map! { "[bg_#{_1}] [/bg] [#{_1}]#{_1.to_s.ljust(22)}[/fg]" }
22
+ )
23
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Sections[/]' do
6
+ ui.space
7
+ ui.information 'Informative Message' do
8
+ ui.puts <<~TEXT, ignore_newline: true
9
+ Sections and messages are elements which support any other feature. This
10
+ means they may contain text, other sections, titles, horizontal rules,
11
+ lists, progress bars and much more!
12
+ TEXT
13
+ end
14
+
15
+ ui.space
16
+ ui.warning 'Warning', 'This is a warning message example.'
17
+
18
+ ui.space
19
+ ui.error 'Error Message' do
20
+ ui.space
21
+ ui.cols do |cc|
22
+ cc.add "()-()\n \\\"/\n  `", width: 6, style: :yellow
23
+ cc.add 'You can add all other elements to a section.', vertical: :middle
24
+ end
25
+ end
26
+
27
+ ui.space
28
+ ui.failed "Fail Message\nA sad failure message."
29
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/natty-ui'
4
+
5
+ ui.message '[b]​ᓚᕠᗢ NattyUI[/b] [i green]Print Tables[/]' do
6
+ ui.space
7
+ ui.table(border: :rounded, border_around: true) do |table|
8
+ table.add(
9
+ 'Header Col 0',
10
+ 'Header Col 1',
11
+ 'Header Col 2',
12
+ align: :centered,
13
+ style: %i[bold red]
14
+ )
15
+
16
+ table.add do |row|
17
+ row.add '[blue]Row 1 Col 0', align: :left, vertical: :middle
18
+ row.add '[blue]Row 1 Col 1', "Line 2\nLine 3", align: :right
19
+ row.add '[blue]Row 1 Col 2', align: :centered, vertical: :bottom
20
+ row.padding = [0, 2]
21
+ end
22
+
23
+ filler_text = <<~FILLER.tr("\n", ' ')
24
+ This is some filler text to demonstrate word-wise line breaks inside
25
+ a table cell. Please, just ignore this nonsense-text gently.
26
+ FILLER
27
+ table.add do |row|
28
+ row.add '[blue]Row 2 Col 0', filler_text, align: :right
29
+ row.add '[blue]Row 2 Col 1', filler_text, align: :centered
30
+ row.add '[blue]Row 2 Col 2', filler_text, align: :left
31
+ row.padding = [1, 2]
32
+ end
33
+ end
34
+
35
+ ui.space
36
+ ui.table(border_style: :bright_blue, border: :default) do |table|
37
+ table.add(*('A'..'Z').each_slice(2).map(&:join))
38
+ table.add(*('😀'..'😌'))
39
+ table.add(*(3..15).map { _1.to_s(3) })
40
+ table.each do |row|
41
+ row.align = :centered
42
+ row.style = :bright_yellow
43
+ end
44
+ end
45
+
46
+ ui.space
47
+ ui.table do |table|
48
+ table.add do |row|
49
+ row.add 'green', style: :on_green
50
+ row.add 'blue', style: :on_blue
51
+ row.add 'red', style: :on_red
52
+ row.width = 15
53
+ row.align = :centered
54
+ end
55
+ table.add do |row|
56
+ row.add 'yellow', style: :on_yellow
57
+ row.add 'magenta', style: :on_magenta
58
+ row.add 'cyan', style: :on_cyan
59
+ row.align = :centered
60
+ end
61
+ end
62
+ end