terminal_rb 0.20.0 → 1.0.3

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: e58a29a2a4369fa40b287a370939d976ecf75881a97478ce40056accc04459d0
4
- data.tar.gz: 5629db5a425e272daf44a7474bd3ea871d9c458b8e263a6c933aaf596865711a
3
+ metadata.gz: 950ff3a6bfe6d9279970ab7e3c6c26f8a7f579bf8e9b90bfc14237d8897be8dc
4
+ data.tar.gz: 9f9d09af40138149c9009f17424347b30f7ec4f256260a9eeac570c9f917fd68
5
5
  SHA512:
6
- metadata.gz: 2023c65d76e3a28c0b1047ed62390f6e7bfacd8d45a9a6c204323f72e97bb8b52f37f682b0228c8d2574de9d86bddc689ff5b7592350636e303e5bb8fdea53cd
7
- data.tar.gz: f5126d27a8c8ad09ed4a0da5c7e2f95f706bc6215bdcc259e757caa600c476d4e45c2f9999fb54063a8c0e9d71037ce5928f5a97ec499d1ca1e7b97864e4d2cd
6
+ metadata.gz: 50e39a6ef2f1fc630d5aa2e24fd357840cc18cda699502cf45579e2ba4fa442313753af5dd065ac7c65600f277383b25741c82d94ce7d67d32ab55ee85f8f406
7
+ data.tar.gz: '09af3aa1c7df3a9a851dfd5c39e1a463ac502dc038c4031957373db1f9c2a3af1970cb90a4323bd9fbc097d9623e54d70763fd92d30235ca42c0b258fac67030'
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Terminal.rb ![version](https://img.shields.io/gem/v/terminal_rb?label=)
1
+ # Terminal.rb v1.0.3
2
2
 
3
3
  Terminal.rb supports you with input and output on your terminal. Simple [BBCode](https://en.wikipedia.org/wiki/BBCode)-like markup for attributes and coloring, word-wise line breaks, correct special key recognition and mouse event reporting enable you to implement your CLI app quickly and easily.
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/terminal_rb)
6
6
  - Source: [codeberg.org](https://codeberg.org/mblumtritt/Terminal.rb)
7
- - Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/0.20.0/Terminal)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/terminal_rb/1.0.3/Terminal)
8
8
 
9
9
  ## Features
10
10
 
@@ -14,9 +14,10 @@ Terminal.rb supports you with input and output on your terminal. Simple [BBCode]
14
14
  - [NO_COLOR convention](https://no-color.org) support
15
15
  - markup of text attributes and colors using a [BBCode](https://en.wikipedia.org/wiki/BBCode)-like syntax
16
16
  - calculation for correct display width of strings containing Unicdode chars inclusive emojis
17
- - word-wise line break generator
18
17
  - supports [CSIu protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol)
19
18
  - mouse events
19
+ - text formatter with word-wise line break support
20
+ - screen viewer component
20
21
 
21
22
  ## Examples
22
23
 
@@ -47,7 +48,7 @@ Terminal::Text.width('ライブラリは中国語、日本語、韓国語のテ
47
48
  ### Split text word-by-word and limit line width to 30 chars
48
49
 
49
50
  ```ruby
50
- Terminal::Text.each_line(<<~TEXT, limit: 30).to_a
51
+ Terminal::Text.lines(<<~TEXT, width: 30)
51
52
  [b]Hello Ruby World![/]
52
53
  This gem provides terminal access with support for [i]ANSI[/] control codes
53
54
  and [i]BBCode-like[/] embedded text attribute syntax.
data/bin/bbcode CHANGED
@@ -1,21 +1,20 @@
1
1
  #!/usr/bin/env ruby --disable-all
2
2
  # frozen_string_literal: true
3
3
 
4
- def me = File.basename(Process.argv0)
5
- puts(<<~HELP) || exit if ARGV.delete('-h') || ARGV.delete('--help')
6
- usage: #{me} [OPTION] [FILE, ...]
7
-
8
- Interprete BBCode of given files or stdin and print to stdout.
4
+ begin
5
+ puts(<<~HELP) || exit if ARGV.delete('-h') || ARGV.delete('--help')
6
+ usage: bbcode [OPTION] [FILE, ...]
9
7
 
10
- Options:
11
- -A, --no-ansi remove ANSI control codes
12
- -B, --no-bbcode remove BBCodes
13
- HELP
8
+ Interprete BBCode of given files or input of stdin and print to stdout.
14
9
 
15
- begin
10
+ Options:
11
+ -A, --no-ansi remove ANSI control codes
12
+ -B, --no-bbcode remove BBCodes
13
+ HELP
16
14
  case ARGV[0]
17
15
  when '-v', '--version'
18
- puts("#{me} v1.0") || exit if ARGV.size == 1
16
+ require_relative('../lib/terminal/version')
17
+ puts("bbcode v#{Terminal::VERSION}") || exit
19
18
  when '-A', '--no-ansi'
20
19
  no_ansi = ARGV.shift
21
20
  when '-B', '--no-bbcode'
@@ -23,23 +22,28 @@ begin
23
22
  when '-AB', '-BA'
24
23
  no_ansi = no_bbcode = ARGV.shift
25
24
  when '--auto'
26
- ARGV.shift
27
- require_relative('../lib/terminal')
28
- no_ansi = no_bbcode = true unless Terminal.ansi?
25
+ ARGV.shift && require_relative('../lib/terminal')
26
+ no_ansi = no_bbcode = !Terminal.ansi?
29
27
  end
30
28
  require_relative('../lib/terminal/ansi')
31
- $stdout.write(
32
- Terminal::Ansi.send(
29
+ ansi = Terminal::Ansi
30
+ ARGF.each_line(
31
+ &(
33
32
  if no_ansi
34
- no_bbcode ? :plain : :undecorate
33
+ if no_bbcode
34
+ ->(l) { $stdout.write(ansi.plain(l)) }
35
+ else
36
+ ->(l) { $stdout.write(ansi.bbcode(ansi.undecorate(l))) }
37
+ end
38
+ elsif no_bbcode
39
+ ->(l) { $stdout.write(ansi.unbbcode(l)) }
35
40
  else
36
- no_bbcode ? :unbbcode : :bbcode
37
- end,
38
- ARGF.read
41
+ ->(l) { $stdout.write(ansi.bbcode(l)) }
42
+ end
39
43
  )
40
44
  )
41
45
  rescue IOError, SystemCallError => e
42
- $stderr.puts "#{me}-error: #{e.message.gsub(/@ \w+ /, '')}"
46
+ $stderr.puts("bbcode-error: #{e.message.gsub(/@ \w+ /, '')}")
43
47
  exit 1
44
48
  rescue Interrupt
45
49
  exit 130
@@ -5,13 +5,13 @@ require_relative '../lib/terminal'
5
5
  Terminal.puts(
6
6
  <<~TEXT,
7
7
 
8
- ✅ [b bright_green]Terminal.rb[/b] — 24bit-Colors:[/]
8
+ ✅ [b bright_green]Terminal.rb[/b] — 24bit-Colors:[/fg]
9
9
 
10
10
  TEXT
11
11
  Terminal::Ansi
12
12
  .named_colors
13
- .delete_if { /\d/.match?(_1) }
14
- .map! { "[on_#{_1}] [/] [#{_1}]#{_1.to_s.ljust(22)}[/]" }
13
+ .delete_if { /\d/.match?(it) }
14
+ .map! { "[on_#{it}] [/bg] [#{it}]#{it.to_s.ljust(21)}[/fg]" }
15
15
  .each_slice(3)
16
16
  .map(&:join)
17
17
  .join("\n"),
@@ -4,15 +4,15 @@ require_relative '../lib/terminal'
4
4
 
5
5
  Terminal.puts <<~TEXT
6
6
 
7
- ✅ [b bright_green]Terminal.rb[/b] — 3/4bit-Colors:[/]
7
+ ✅ [b bright_green]Terminal.rb[/b] — 3/4bit-Colors:[/fg]
8
8
 
9
- [on_black] [/] [black]black[/] [on_bright_black] [/] [bright_black]bright_black[/]
10
- [on_red] [/] [red]red[/] [on_bright_red] [/] [bright_red]bright_red[/]
11
- [on_green] [/] [green]green[/] [on_bright_green] [/] [bright_green]bright_green[/]
12
- [on_yellow] [/] [yellow]yellow[/] [on_bright_yellow] [/] [bright_yellow]bright_yellow[/]
13
- [on_blue] [/] [blue]blue[/] [on_bright_blue] [/] [bright_blue]bright_blue[/]
14
- [on_magenta] [/] [magenta]magenta[/] [on_bright_magenta] [/] [bright_magenta]bright_magenta[/]
15
- [on_cyan] [/] [cyan]cyan[/] [on_bright_cyan] [/] [bright_cyan]bright_cyan[/]
16
- [on_white] [/] [white]white[/] [on_bright_white] [/] [bright_white]bright_white[/]
9
+ [on_black] [/bg] [black]black[/fg] [on_bright_black] [/bg] [bright_black]bright_black[/fg]
10
+ [on_red] [/bg] [red]red[/fg] [on_bright_red] [/bg] [bright_red]bright_red[/fg]
11
+ [on_green] [/bg] [green]green[/fg] [on_bright_green] [/bg] [bright_green]bright_green[/fg]
12
+ [on_yellow] [/bg] [yellow]yellow[/fg] [on_bright_yellow] [/bg] [bright_yellow]bright_yellow[/fg]
13
+ [on_blue] [/bg] [blue]blue[/fg] [on_bright_blue] [/bg] [bright_blue]bright_blue[/fg]
14
+ [on_magenta] [/bg] [magenta]magenta[/fg] [on_bright_magenta] [/bg] [bright_magenta]bright_magenta[/fg]
15
+ [on_cyan] [/bg] [cyan]cyan[/fg] [on_bright_cyan] [/bg] [bright_cyan]bright_cyan[/fg]
16
+ [on_white] [/bg] [white]white[/fg] [on_bright_white] [/bg] [bright_white]bright_white[/fg]
17
17
 
18
18
  TEXT
@@ -4,29 +4,29 @@ require_relative '../lib/terminal'
4
4
 
5
5
  Terminal.puts <<~TEXT
6
6
 
7
- ✅ [b bright_green]Terminal.rb[/b] — 8bit-Colors:[/]
7
+ ✅ [b bright_green]Terminal.rb[/b] — 8bit-Colors:[/fg]
8
8
 
9
9
  System Colors
10
- [on_0] 00 [on_1] 01 [on_2] 02 [on_3] 03 [on_4] 04 [on_5] 05 [on_6] 06 [on_7] 07 [/]
11
- [on_8] 08 [on_9] 09 [on_a] 0a [on_b] 0b [on_c] 0c [on_d] 0d [on_e] 0e [on_e] 0f [/]
10
+ [on_0] 00 [on_1] 01 [on_2] 02 [on_3] 03 [on_4] 04 [on_5] 05 [on_6] 06 [on_7] 07 [/bg]
11
+ [on_8] 08 [on_9] 09 [on_a] 0a [on_b] 0b [on_c] 0c [on_d] 0d [on_e] 0e [on_e] 0f [/bg]
12
12
 
13
13
  Grayscale
14
- [on_e8] e8 [on_e9] e9 [on_ea] ea [on_eb] eb [on_ec] ec [on_ed] ed [on_ee] ee [on_ef] ef [on_f0] f0 [on_f1] f1 [on_f2] f2 [on_f3] f3 [/]
15
- [on_f4] f4 [on_f5] f5 [on_f6] f6 [on_f7] f7 [on_f8] f8 [on_f9] f9 [on_fa] fa [on_fb] fb [on_fc] fc [on_fd] fd [on_fe] fe [on_ff] ff [/]
14
+ [on_e8] e8 [on_e9] e9 [on_ea] ea [on_eb] eb [on_ec] ec [on_ed] ed [on_ee] ee [on_ef] ef [on_f0] f0 [on_f1] f1 [on_f2] f2 [on_f3] f3 [/bg]
15
+ [on_f4] f4 [on_f5] f5 [on_f6] f6 [on_f7] f7 [on_f8] f8 [on_f9] f9 [on_fa] fa [on_fb] fb [on_fc] fc [on_fd] fd [on_fe] fe [on_ff] ff [/bg]
16
16
 
17
17
  6x6 Color Cubes
18
- [on_10] 10 [on_11] 11 [on_12] 12 [on_13] 13 [on_14] 14 [on_15] 15 [/] [on_16] 16 [on_17] 17 [on_18] 18 [on_19] 19 [on_1a] 1a [on_1b] 1b [/] [on_1c] 1c [on_1d] 1d [on_1e] 1e [on_1f] 1f [on_20] 20 [on_21] 21 [/]
19
- [on_34] 34 [on_35] 35 [on_36] 36 [on_37] 37 [on_38] 38 [on_39] 39 [/] [on_3a] 3a [on_3b] 3b [on_3c] 3c [on_3d] 3d [on_3e] 3e [on_3f] 3f [/] [on_40] 40 [on_41] 41 [on_42] 42 [on_43] 43 [on_44] 44 [on_45] 45 [/]
20
- [on_58] 58 [on_59] 59 [on_5a] 5a [on_5b] 5b [on_5c] 5c [on_5d] 5d [/] [on_5e] 5e [on_5f] 5f [on_60] 60 [on_61] 61 [on_62] 62 [on_63] 63 [/] [on_64] 64 [on_65] 65 [on_66] 66 [on_67] 67 [on_68] 68 [on_69] 69 [/]
21
- [on_7c] 7c [on_7d] 7d [on_7e] 7e [on_7f] 7f [on_80] 80 [on_81] 81 [/] [on_82] 82 [on_83] 83 [on_84] 84 [on_85] 85 [on_86] 86 [on_87] 87 [/] [on_88] 88 [on_89] 89 [on_8a] 8a [on_8b] 8b [on_8c] 8c [on_8d] 8d [/]
22
- [on_a0] a0 [on_a1] a1 [on_a2] a2 [on_a3] a3 [on_a4] a4 [on_a5] a5 [/] [on_a6] a6 [on_a7] a7 [on_a8] a8 [on_a9] a9 [on_aa] aa [on_ab] ab [/] [on_ac] ac [on_ad] ad [on_ae] ae [on_af] af [on_b0] b0 [on_b1] b1 [/]
23
- [on_c4] c4 [on_c5] c5 [on_c6] c6 [on_c7] c7 [on_c8] c8 [on_c9] c9 [/] [on_ca] ca [on_cb] cb [on_cc] cc [on_cd] cd [on_ce] ce [on_cf] cf [/] [on_d0] d0 [on_d1] d1 [on_d2] d2 [on_d3] d3 [on_d4] d4 [on_d5] d5 [/]
24
-
25
- [on_22] 22 [on_23] 23 [on_24] 24 [on_25] 25 [on_26] 26 [on_27] 27 [/] [on_28] 28 [on_29] 29 [on_2a] 2a [on_2b] 2b [on_2c] 2c [on_2d] 2d [/] [on_2e] 2e [on_2f] 2f [on_30] 30 [on_31] 31 [on_32] 32 [on_33] 33 [/]
26
- [on_46] 46 [on_47] 47 [on_48] 48 [on_49] 49 [on_4a] 4a [on_4b] 4b [/] [on_4c] 4c [on_4d] 4d [on_4e] 4e [on_4f] 4f [on_50] 50 [on_51] 51 [/] [on_52] 52 [on_53] 53 [on_54] 54 [on_55] 55 [on_56] 56 [on_57] 57 [/]
27
- [on_6a] 6a [on_6b] 6b [on_6c] 6c [on_6d] 6d [on_6e] 6e [on_6f] 6f [/] [on_70] 70 [on_71] 71 [on_72] 72 [on_73] 73 [on_74] 74 [on_75] 75 [/] [on_76] 76 [on_77] 77 [on_78] 78 [on_79] 79 [on_7a] 7a [on_7b] 7b [/]
28
- [on_8e] 8e [on_8f] 8f [on_90] 90 [on_91] 91 [on_92] 92 [on_93] 93 [/] [on_94] 94 [on_95] 95 [on_96] 96 [on_97] 97 [on_98] 98 [on_99] 99 [/] [on_9a] 9a [on_9b] 9b [on_9c] 9c [on_9d] 9d [on_9e] 9e [on_9f] 9f [/]
29
- [on_b2] b2 [on_b3] b3 [on_b4] b4 [on_b5] b5 [on_b6] b6 [on_b7] b7 [/] [on_b8] b8 [on_b9] b9 [on_ba] ba [on_bb] bb [on_bc] bc [on_bd] bd [/] [on_be] be [on_bf] bf [on_c0] c0 [on_c1] c1 [on_c2] c2 [on_c3] c3 [/]
30
- [on_d6] d6 [on_d7] d7 [on_d8] d8 [on_d9] d9 [on_da] da [on_db] db [/] [on_dc] dc [on_dd] dd [on_de] de [on_df] df [on_e0] e0 [on_e1] e1 [/] [on_e2] e2 [on_e3] e3 [on_e4] e4 [on_e5] e5 [on_e6] e6 [on_e7] e7 [/]
18
+ [on_10] 10 [on_11] 11 [on_12] 12 [on_13] 13 [on_14] 14 [on_15] 15 [/bg] [on_16] 16 [on_17] 17 [on_18] 18 [on_19] 19 [on_1a] 1a [on_1b] 1b [/] [on_1c] 1c [on_1d] 1d [on_1e] 1e [on_1f] 1f [on_20] 20 [on_21] 21 [/bg]
19
+ [on_34] 34 [on_35] 35 [on_36] 36 [on_37] 37 [on_38] 38 [on_39] 39 [/bg] [on_3a] 3a [on_3b] 3b [on_3c] 3c [on_3d] 3d [on_3e] 3e [on_3f] 3f [/] [on_40] 40 [on_41] 41 [on_42] 42 [on_43] 43 [on_44] 44 [on_45] 45 [/bg]
20
+ [on_58] 58 [on_59] 59 [on_5a] 5a [on_5b] 5b [on_5c] 5c [on_5d] 5d [/bg] [on_5e] 5e [on_5f] 5f [on_60] 60 [on_61] 61 [on_62] 62 [on_63] 63 [/] [on_64] 64 [on_65] 65 [on_66] 66 [on_67] 67 [on_68] 68 [on_69] 69 [/bg]
21
+ [on_7c] 7c [on_7d] 7d [on_7e] 7e [on_7f] 7f [on_80] 80 [on_81] 81 [/bg] [on_82] 82 [on_83] 83 [on_84] 84 [on_85] 85 [on_86] 86 [on_87] 87 [/] [on_88] 88 [on_89] 89 [on_8a] 8a [on_8b] 8b [on_8c] 8c [on_8d] 8d [/bg]
22
+ [on_a0] a0 [on_a1] a1 [on_a2] a2 [on_a3] a3 [on_a4] a4 [on_a5] a5 [/bg] [on_a6] a6 [on_a7] a7 [on_a8] a8 [on_a9] a9 [on_aa] aa [on_ab] ab [/] [on_ac] ac [on_ad] ad [on_ae] ae [on_af] af [on_b0] b0 [on_b1] b1 [/bg]
23
+ [on_c4] c4 [on_c5] c5 [on_c6] c6 [on_c7] c7 [on_c8] c8 [on_c9] c9 [/bg] [on_ca] ca [on_cb] cb [on_cc] cc [on_cd] cd [on_ce] ce [on_cf] cf [/] [on_d0] d0 [on_d1] d1 [on_d2] d2 [on_d3] d3 [on_d4] d4 [on_d5] d5 [/bg]
24
+
25
+ [on_22] 22 [on_23] 23 [on_24] 24 [on_25] 25 [on_26] 26 [on_27] 27 [/] [on_28] 28 [on_29] 29 [on_2a] 2a [on_2b] 2b [on_2c] 2c [on_2d] 2d [/bg] [on_2e] 2e [on_2f] 2f [on_30] 30 [on_31] 31 [on_32] 32 [on_33] 33 [/bg]
26
+ [on_46] 46 [on_47] 47 [on_48] 48 [on_49] 49 [on_4a] 4a [on_4b] 4b [/] [on_4c] 4c [on_4d] 4d [on_4e] 4e [on_4f] 4f [on_50] 50 [on_51] 51 [/bg] [on_52] 52 [on_53] 53 [on_54] 54 [on_55] 55 [on_56] 56 [on_57] 57 [/bg]
27
+ [on_6a] 6a [on_6b] 6b [on_6c] 6c [on_6d] 6d [on_6e] 6e [on_6f] 6f [/] [on_70] 70 [on_71] 71 [on_72] 72 [on_73] 73 [on_74] 74 [on_75] 75 [/bg] [on_76] 76 [on_77] 77 [on_78] 78 [on_79] 79 [on_7a] 7a [on_7b] 7b [/bg]
28
+ [on_8e] 8e [on_8f] 8f [on_90] 90 [on_91] 91 [on_92] 92 [on_93] 93 [/] [on_94] 94 [on_95] 95 [on_96] 96 [on_97] 97 [on_98] 98 [on_99] 99 [/bg] [on_9a] 9a [on_9b] 9b [on_9c] 9c [on_9d] 9d [on_9e] 9e [on_9f] 9f [/bg]
29
+ [on_b2] b2 [on_b3] b3 [on_b4] b4 [on_b5] b5 [on_b6] b6 [on_b7] b7 [/] [on_b8] b8 [on_b9] b9 [on_ba] ba [on_bb] bb [on_bc] bc [on_bd] bd [/bg] [on_be] be [on_bf] bf [on_c0] c0 [on_c1] c1 [on_c2] c2 [on_c3] c3 [/bg]
30
+ [on_d6] d6 [on_d7] d7 [on_d8] d8 [on_d9] d9 [on_da] da [on_db] db [/] [on_dc] dc [on_dd] dd [on_de] de [on_df] df [on_e0] e0 [on_e1] e1 [/bg] [on_e2] e2 [on_e3] e3 [on_e4] e4 [on_e5] e5 [on_e6] e6 [on_e7] e7 [/bg]
31
31
 
32
32
  TEXT
@@ -2,13 +2,27 @@
2
2
 
3
3
  require_relative '../lib/terminal'
4
4
 
5
- Terminal.puts <<~TEXT
6
-
7
- ✅ [b bright_green]Terminal.rb[/b] — Attributes:[/]
8
-
9
- Terminal.rb supports all well known attributes like [b]bold[/b], [i]italic[/i], [u]underline[/u],
10
- [blink]blink[/blink], [inv]invert[/inv] and [strike]strike[/strike]. Other attributes like [faint]faint[/faint], [double_underline]double underline[/], [curly_underline]curly
11
- underline[/], [dotted_underline]dotted underline[/], [dashed_underline]dashed underline[/], etc. and alternative fonts like
12
- [fraktur]fraktur[/] are not widely used by terminal emulators but supported by Terminal.rb.
13
-
14
- TEXT
5
+ Terminal.fputs(
6
+ '✅ [b bright_green]Terminal.rb[/b] — Attributes:[/fg]',
7
+ nil,
8
+ <<~TEXT,
9
+ Terminal.rb supports all well known attributes like
10
+ [b]bold[/b],
11
+ [i]italic[/i],
12
+ [u]underline[/u],
13
+ [blink]blink[/blink],
14
+ [inv]invert[/inv] and
15
+ [strike]strike[/strike].
16
+ Other attributes like
17
+ [faint]faint[/faint],
18
+ [double_underline]double underline[/],
19
+ [curly_underline]curly underline[/],
20
+ [dotted_underline]dotted underline[/],
21
+ [dashed_underline]dashed underline[/],
22
+ etc. and alternative fonts like
23
+ [fraktur]fraktur[/]
24
+ are not widely used by terminal emulators but supported by Terminal.rb.
25
+ TEXT
26
+ eol: false,
27
+ padding: [1, 0]
28
+ )
data/examples/bbcode.rb CHANGED
@@ -6,24 +6,28 @@ Terminal.puts <<~TEXT
6
6
 
7
7
  ✅ [b bright_green]Terminal.rb::Ansi[/b] — BBCode:[/]
8
8
 
9
- [b]Bold[/b] [\\b]...[\\/b] or [\\bold]...[\\/bold]
10
- [dim]Dim[/dim] [\\d]...[\\/d] or [\\dim]...[\\/dim]
11
- [i]Italic[/i] [\\i]...[\\/i] or [\\italic]...[\\/italic]
12
- [u]Underline[/u] [\\u]...[\\/u] or [\\|undeline]...[\\/undeline]
13
- [inv]Invert[/inv] [\\inv]...[\\/inv] or [\\invert]...[\\/invert]
14
- [h]Hide[/h] [\\h]...[\\/h] or [\\hide]...[\\/hide] or [\\conceal]...[\\/conceal]
15
- [strike]Strike[/strike] [\\strike]...[\\/strike]
16
- [blink]Blink[/blink] [\\blink]...[\\/blink]
17
- [u]Underline[/u] [\\u]...[\\/u] or [\\underline]...[\\/underline]
18
- [uu]Double underline[/uu] [\\uu]...[\\/uu] or [\\double_underline]...[\\/double_underline]
19
- [cu]Curly underline[/cu] [\\cu]...[\\/cu] or [\\curly_underline]...[\\/curly_underline]
20
- [dau]Dashed underline[/dau] [\\dau]...[\\/dau] or [\\dashed_underline]...[\\/dashed_underline]
21
- [dou]Dotted underline[/dou] [\\dou]...[\\/dou] or [\\dotted_underline]...[\\/dotted_underline]
22
- [fraktur]Fraktur[/fraktur] [\\fraktur]...[\\/fraktur]
23
- [framed]Framed[/framed] [\\framed]...[\\/framed]
24
- [encircled]Encircled[/encircled] [\\encircled]...[\\/encircled]
25
- [ovr]Overlined[/ovr] [\\ovr]...[\\/ovr] or [\\overlined]...[\\/overlined]
26
- [sub]Subscript[/sub] [\\sub]...[\\/sub] or [\\subscript]...[\\/subscript]
27
- [sup]Superscript[/sup] [\\sup]...[\\/sup] or [\\superscript]...[\\/superscript]
9
+ [b]Bold[/b] [\\b][d]...[/d][\\/b] [\\bold][d] ... [/d][\\/bold]
10
+ [dim]Dim[/dim] [\\d][d]...[/d][\\/d] [\\dim][d] ... [/d][\\/dim]
11
+ [i]Italic[/i] [\\i][d]...[/d][\\/i] [\\italic][d] ... [/d][\\/italic]
12
+ [u]Underline[/u] [\\u][d]...[/d][\\/u] [\\underline][d]...[/d][\\/underline]
13
+ [h]Hide[/h] [\\h][d]...[/d][\\/h] [\\hide][d] ... [/d][\\/hide]
14
+
15
+ [inv]Invert[/inv] [\\inv][d] ... [/d][\\/inv] [\\invert][d]...[/d][\\/invert]
16
+ [strike]Strike[/strike] [\\strike][d]...[/d][\\/strike]
17
+ [blink]Blink[/blink] [\\blink][d] ...[/d][\\/blink]
18
+
19
+ [u]Underline[/u] [\\u][d] ... [/d][\\/u] [\\underline][d] ... [/d][\\/underline]
20
+ [uu]Double underline[/uu] [\\uu][d] ...[/d][\\/uu] [\\double_underline][d]...[/d][\\/double_underline]
21
+ [cu]Curly underline[/cu] [\\cu][d] ...[/d][\\/cu] [\\curly_underline][d] ...[/d][\\/curly_underline]
22
+ [dau]Dashed underline[/dau] [\\dau][d]...[/d][\\/dau] [\\dashed_underline][d]...[/d][\\/dashed_underline]
23
+ [dou]Dotted underline[/dou] [\\dou][d]...[/d][\\/dou] [\\dotted_underline][d]...[/d][\\/dotted_underline]
24
+
25
+ [fraktur]Fraktur[/fraktur] [\\fraktur][d] ... [/d][\\/fraktur]
26
+ [framed]Framed[/framed] [\\framed][d] ... [/d][\\/framed]
27
+ [encircled]Encircled[/encircled] [\\encircled][d]...[/d][\\/encircled]
28
+
29
+ [ovr]Overlined[/ovr] [\\ovr][d]...[/d][\\/ovr] [\\overlined][d] ... [/d][\\/overlined]
30
+ [sub]Subscript[/sub] [\\sub][d]...[/d][\\/sub] [\\subscript][d] ... [/d][\\/subscript]
31
+ [sup]Superscript[/sup] [\\sup][d]...[/d][\\/sup] [\\superscript][d]...[/d][\\/superscript]
28
32
 
29
33
  TEXT
data/examples/info.rb CHANGED
@@ -4,14 +4,14 @@ require_relative '../lib/terminal'
4
4
 
5
5
  Terminal.puts <<~TEXT
6
6
 
7
- ✅ [b bright_green]Terminal.rb[/b] — Terminal Info:[/]
7
+ ✅ [b bright_green]Terminal.rb[/b] — Terminal Info:[/fg]
8
8
 
9
- Ansi mode: #{Terminal.ansi? ? '[b bright_green]✓' : '[b bright_red]𐄂'}[/]
10
9
  Application: [b bright_blue]#{Terminal.application}[/]
11
- Supported Colors: [b]#{Terminal.colors}#{Terminal::Ansi.rainbow(' (truecolor)') if Terminal.true_color?}[/]
12
- Terminal Size: [b]#{Terminal.size.join(' x ')}[/]
13
- Cursor Position: [b]#{Terminal.pos&.join(', ')}[/]
14
- Input Mode: [b]#{Terminal.input_mode}[/]
15
- Link Support: [b]#{Terminal::Ansi.link('https://codeberg.org/mblumtritt/Terminal.rb', 'Link')}[/]
10
+ Ansi mode: #{Terminal.ansi? ? '[b bright_green]✓' : '[b bright_red]𐄂'}[/]
11
+ Supported Colors: [b]#{Terminal.colors}#{Terminal::Ansi.rainbow(' (truecolor)') if Terminal.true_color?}[/b]
12
+ Terminal Size: [b]#{Terminal.size.join(' x ')}[/b]
13
+ Cursor Position: [b]#{Terminal.pos&.join(', ')}[/b]
14
+ Input Mode: [b]#{Terminal.input_mode}[/b]
15
+ Link Support: [b]#{Terminal::Ansi.link('https://codeberg.org/mblumtritt/Terminal.rb', 'Link')}[/b]
16
16
 
17
17
  TEXT
@@ -4,7 +4,7 @@ require_relative '../lib/terminal'
4
4
 
5
5
  Terminal.puts <<~TEXT
6
6
 
7
- ✅ [b bright_green]Terminal.rb[/b] — Key Codes:[/]
7
+ ✅ [b bright_green]Terminal.rb[/b] — Key Codes:[/fg]
8
8
  Press any key to display it's control code and name.
9
9
  [bright_black]([b]#{Terminal.input_mode}[/b] mode - exit with ESC)[/fg]
10
10
 
@@ -13,10 +13,10 @@ TEXT
13
13
  # if you like to have mouse position changes reported then use
14
14
  # 'mouse_move: true' in next line
15
15
  Terminal.on_key_event(mouse: true, focus: true, mouse_move: false) do |event|
16
- str = "[blue]: [yellow]#{event.raw.inspect}"
16
+ str = "[blue]: [yellow]#{event.raw.inspect}[/fg]"
17
17
  str << " [bold bright_green]#{event.name}[/]" unless event.simple?
18
- str << " [dim]#{event.position.inspect}[/]" if event.position
18
+ str << " [dim]#{event.position.inspect}[/dim]" if event.position
19
19
  Terminal.puts(str)
20
- event.name != 'Esc'
20
+ break if event.name == 'Esc'
21
21
  end
22
22
  puts
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/terminal'
4
+
5
+ unless Terminal.tui?
6
+ Terminal.puts <<~TEXT
7
+ ✅ [b bright_green]Terminal.rb[/b] — Ansi::ScreenViewer:[/fg]
8
+
9
+ Your Terminal must support ANSI control codes for input and output to
10
+ show this example.
11
+
12
+ TEXT
13
+ exit
14
+ end
15
+
16
+ HELP = <<~HELP
17
+ ✅ [b bright_green]Terminal.rb[/b] — Ansi::ScreenViewer:[/fg]
18
+
19
+ This is an example to demonstrate the interaction of several components of this gem. The demonstrated viewer is a combination of
20
+
21
+ • [yellow i]Terminal::Text::Formatter
22
+ • [yellow i]Terminal::Ansi::ScreenViewer
23
+ • the BBCode interpreter of [yellow i]Terminal::Ansi
24
+ • several tool functions of [yellow i]Terminal
25
+ • especially [yellow i]Terminal.on_key_event
26
+
27
+ To navigate the text this keys are defined:
28
+
29
+ [b][Up][/] one line up
30
+ [b][Shift] [Up][/] half a screen up
31
+ [b][PageUp][/] screen up
32
+ [b][Home][/] top of text
33
+ [b][Down][/] one line down
34
+ [b][Shift] [Down][/] half screen down
35
+ [b][PageDown][/] screen down
36
+ [b][End][/] end of text
37
+
38
+ [b][\\F2][/] redraw
39
+ [b][Esc][/] exit program
40
+
41
+ [i]The text below is just filltext to demonstrate the viewer's aspects.
42
+
43
+ HELP
44
+
45
+ LOREM = File.readlines("#{__dir__}/lorem_ipsum.ansi")
46
+
47
+ Terminal.hide_cursor
48
+ Terminal.show_alt_screen
49
+ begin
50
+ viewer = Terminal::Ansi::ScreenViewer.new(HELP.lines.concat(LOREM, LOREM))
51
+ viewer.draw
52
+ Terminal.on_resize { viewer.resize_to_screen }
53
+ Terminal.on_key_event do |event|
54
+ case event.name
55
+ when 'Up'
56
+ viewer.up
57
+ when 'Shift+Up'
58
+ viewer.half_up
59
+ when 'PageUp'
60
+ viewer.page_up
61
+ when 'Home'
62
+ viewer.begin
63
+ when 'Down'
64
+ viewer.down
65
+ when 'Shift+Down'
66
+ viewer.half_down
67
+ when 'PageDown'
68
+ viewer.page_down
69
+ when 'End'
70
+ viewer.end
71
+ when 'F2'
72
+ viewer.draw
73
+ when 'Shift+F2'
74
+ viewer.resize_to_screen
75
+ when 'Esc'
76
+ break Terminal.on_resize
77
+ end
78
+ end
79
+ ensure
80
+ Terminal.hide_alt_screen
81
+ Terminal.show_cursor
82
+ end
data/examples/text.rb CHANGED
@@ -2,31 +2,15 @@
2
2
 
3
3
  require_relative '../lib/terminal'
4
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)
5
+ LOREM = File.readlines("#{__dir__}/lorem_ipsum.ansi") * 4
6
+
7
+ # Print text fitting the screen:
8
+ Terminal.fputs(
9
+ LOREM,
10
+ width: Terminal.columns - 2,
11
+ height: Terminal.rows - 1,
12
+ align: :left,
13
+ prefix: '│',
14
+ suffix: '│',
15
+ padding: [0, 2]
16
+ )
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Terminal
4
4
  module Ansi
5
+ # @private
5
6
  NAMED_COLORS = {
6
7
  'aliceblue' => '2;240;248;255',
7
8
  'antiquewhite' => '2;250;235;215',