r2ui 0.1.0 → 0.2.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +64 -0
  3. data/README.md +79 -0
  4. data/lib/r2ui/app.rb +311 -34
  5. data/lib/r2ui/canvas.rb +135 -14
  6. data/lib/r2ui/cli/builder.rb +72 -0
  7. data/lib/r2ui/cli/context.rb +45 -0
  8. data/lib/r2ui/cli/definition.rb +174 -0
  9. data/lib/r2ui/cli/ext/ask.rb +133 -0
  10. data/lib/r2ui/cli/ext/box.rb +112 -0
  11. data/lib/r2ui/cli/ext/choose.rb +162 -0
  12. data/lib/r2ui/cli/ext/choose_many.rb +241 -0
  13. data/lib/r2ui/cli/ext/color_option.rb +64 -0
  14. data/lib/r2ui/cli/ext/completion.rb +520 -0
  15. data/lib/r2ui/cli/ext/config.rb +179 -0
  16. data/lib/r2ui/cli/ext/confirm.rb +110 -0
  17. data/lib/r2ui/cli/ext/dashboard.rb +105 -0
  18. data/lib/r2ui/cli/ext/diff.rb +195 -0
  19. data/lib/r2ui/cli/ext/editor.rb +94 -0
  20. data/lib/r2ui/cli/ext/env.rb +108 -0
  21. data/lib/r2ui/cli/ext/examples.rb +62 -0
  22. data/lib/r2ui/cli/ext/filter.rb +269 -0
  23. data/lib/r2ui/cli/ext/format.rb +104 -0
  24. data/lib/r2ui/cli/ext/list.rb +117 -0
  25. data/lib/r2ui/cli/ext/log.rb +89 -0
  26. data/lib/r2ui/cli/ext/pager.rb +97 -0
  27. data/lib/r2ui/cli/ext/pairs.rb +62 -0
  28. data/lib/r2ui/cli/ext/parallel.rb +274 -0
  29. data/lib/r2ui/cli/ext/password.rb +158 -0
  30. data/lib/r2ui/cli/ext/progress.rb +330 -0
  31. data/lib/r2ui/cli/ext/reference.rb +129 -0
  32. data/lib/r2ui/cli/ext/spinner.rb +165 -0
  33. data/lib/r2ui/cli/ext/summary.rb +63 -0
  34. data/lib/r2ui/cli/ext/table.rb +141 -0
  35. data/lib/r2ui/cli/ext/tasks.rb +216 -0
  36. data/lib/r2ui/cli/ext/trace.rb +64 -0
  37. data/lib/r2ui/cli/ext/tree.rb +114 -0
  38. data/lib/r2ui/cli/ext/version.rb +67 -0
  39. data/lib/r2ui/cli/extension.rb +129 -0
  40. data/lib/r2ui/cli/help.rb +115 -0
  41. data/lib/r2ui/cli/helpers.rb +20 -0
  42. data/lib/r2ui/cli/live.rb +150 -0
  43. data/lib/r2ui/cli/parser.rb +165 -0
  44. data/lib/r2ui/cli/prompt.rb +133 -0
  45. data/lib/r2ui/cli/runner.rb +86 -0
  46. data/lib/r2ui/cli/shell.rb +185 -0
  47. data/lib/r2ui/cli/testing.rb +49 -0
  48. data/lib/r2ui/cli.rb +129 -0
  49. data/lib/r2ui/compat/bubbletea/LICENSE-bubbletea.txt +21 -0
  50. data/lib/r2ui/compat/bubbletea/ansi.rb +424 -0
  51. data/lib/r2ui/compat/bubbletea/commands.rb +143 -0
  52. data/lib/r2ui/compat/bubbletea/input.rb +269 -0
  53. data/lib/r2ui/compat/bubbletea/input_reader.rb +66 -0
  54. data/lib/r2ui/compat/bubbletea/messages.rb +251 -0
  55. data/lib/r2ui/compat/bubbletea/model.rb +65 -0
  56. data/lib/r2ui/compat/bubbletea/native.rb +254 -0
  57. data/lib/r2ui/compat/bubbletea/renderer.rb +192 -0
  58. data/lib/r2ui/compat/bubbletea/runner.rb +425 -0
  59. data/lib/r2ui/compat/bubbletea/terminal.rb +230 -0
  60. data/lib/r2ui/compat/bubbletea/version.rb +8 -0
  61. data/lib/r2ui/compat/bubbletea/width_table.rb +228 -0
  62. data/lib/r2ui/compat/bubbletea.rb +16 -0
  63. data/lib/r2ui/compat/lipgloss/border.rb +17 -0
  64. data/lib/r2ui/compat/lipgloss/color.rb +78 -0
  65. data/lib/r2ui/compat/lipgloss/color_blend.rb +166 -0
  66. data/lib/r2ui/compat/lipgloss/colorful.rb +585 -0
  67. data/lib/r2ui/compat/lipgloss/layout.rb +461 -0
  68. data/lib/r2ui/compat/lipgloss/list.rb +85 -0
  69. data/lib/r2ui/compat/lipgloss/position.rb +30 -0
  70. data/lib/r2ui/compat/lipgloss/style/border.rb +134 -0
  71. data/lib/r2ui/compat/lipgloss/style.rb +1062 -0
  72. data/lib/r2ui/compat/lipgloss/table/render.rb +518 -0
  73. data/lib/r2ui/compat/lipgloss/table.rb +185 -0
  74. data/lib/r2ui/compat/lipgloss/termenv.rb +768 -0
  75. data/lib/r2ui/compat/lipgloss/text/unicode_tables.rb +428 -0
  76. data/lib/r2ui/compat/lipgloss/text.rb +1555 -0
  77. data/lib/r2ui/compat/lipgloss/tree/go_tree.rb +243 -0
  78. data/lib/r2ui/compat/lipgloss/tree.rb +105 -0
  79. data/lib/r2ui/compat/lipgloss/version.rb +15 -0
  80. data/lib/r2ui/compat/lipgloss.rb +64 -0
  81. data/lib/r2ui/compat/load_path/bubbletea.rb +4 -0
  82. data/lib/r2ui/compat/load_path/lipgloss.rb +4 -0
  83. data/lib/r2ui/component.rb +67 -0
  84. data/lib/r2ui/context.rb +87 -0
  85. data/lib/r2ui/drop_in.rb +16 -0
  86. data/lib/r2ui/dsl/column.rb +11 -3
  87. data/lib/r2ui/dsl/dashboard.rb +45 -9
  88. data/lib/r2ui/dsl/resource.rb +12 -0
  89. data/lib/r2ui/ext/after.rb +54 -0
  90. data/lib/r2ui/ext/async.rb +81 -0
  91. data/lib/r2ui/ext/batch_sequence.rb +54 -0
  92. data/lib/r2ui/ext/countdown.rb +52 -0
  93. data/lib/r2ui/ext/data_table.rb +71 -0
  94. data/lib/r2ui/ext/every.rb +66 -0
  95. data/lib/r2ui/ext/exec.rb +116 -0
  96. data/lib/r2ui/ext/file_picker.rb +78 -0
  97. data/lib/r2ui/ext/focus_report.rb +69 -0
  98. data/lib/r2ui/ext/help.rb +62 -0
  99. data/lib/r2ui/ext/keys.rb +64 -0
  100. data/lib/r2ui/ext/list.rb +145 -0
  101. data/lib/r2ui/ext/messages.rb +87 -0
  102. data/lib/r2ui/ext/mouse.rb +134 -0
  103. data/lib/r2ui/ext/paginator.rb +86 -0
  104. data/lib/r2ui/ext/paste.rb +86 -0
  105. data/lib/r2ui/ext/println.rb +21 -0
  106. data/lib/r2ui/ext/progress.rb +85 -0
  107. data/lib/r2ui/ext/refresh.rb +56 -0
  108. data/lib/r2ui/ext/resize.rb +62 -0
  109. data/lib/r2ui/ext/screen.rb +47 -0
  110. data/lib/r2ui/ext/screen_mode.rb +63 -0
  111. data/lib/r2ui/ext/spinner.rb +59 -0
  112. data/lib/r2ui/ext/state.rb +45 -0
  113. data/lib/r2ui/ext/stopwatch.rb +67 -0
  114. data/lib/r2ui/ext/suspend.rb +56 -0
  115. data/lib/r2ui/ext/text_area.rb +73 -0
  116. data/lib/r2ui/ext/text_input.rb +83 -0
  117. data/lib/r2ui/ext/theme.rb +112 -0
  118. data/lib/r2ui/ext/view.rb +37 -0
  119. data/lib/r2ui/ext/viewport.rb +92 -0
  120. data/lib/r2ui/ext/window_title.rb +51 -0
  121. data/lib/r2ui/extension.rb +199 -0
  122. data/lib/r2ui/history.rb +4 -1
  123. data/lib/r2ui/keys.rb +35 -8
  124. data/lib/r2ui/motion.rb +169 -0
  125. data/lib/r2ui/panel_state.rb +46 -2
  126. data/lib/r2ui/renderer.rb +87 -22
  127. data/lib/r2ui/version.rb +1 -1
  128. data/lib/r2ui/widgets/box.rb +6 -3
  129. data/lib/r2ui/widgets/glyphs.rb +149 -0
  130. data/lib/r2ui/widgets/table.rb +109 -25
  131. data/lib/r2ui.rb +12 -1
  132. metadata +119 -4
  133. data/lib/r2ui/terminal.rb +0 -53
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Border definitions: lipgloss v1.1.0 borders.go (the Border struct and its predefined borders), plus
4
+ # the border-type conversion the lipgloss gem 0.2.2 C extension does (style_border.c
5
+ # symbol_to_border_type and go/style_border.go).
6
+ module R2UI
7
+ module Compat
8
+ module Gloss
9
+ # lipgloss.Border, fields snake_cased. Unset (nil) fields count as "" (Go's zero value).
10
+ BorderDef = Struct.new(
11
+ :top, :bottom, :left, :right,
12
+ :top_left, :top_right, :bottom_left, :bottom_right,
13
+ :middle_left, :middle_right, :middle,
14
+ :middle_top, :middle_bottom
15
+ ) do
16
+ # A copy with every nil field turned into "" (Go's zero-value string).
17
+ def normalized
18
+ self.class.new(*to_a.map { |v| v.nil? ? "" : v.to_s })
19
+ end
20
+
21
+ # Border.GetTopSize etc.
22
+ def top_size = Borders.edge_width(top_left, top, top_right)
23
+ def right_size = Borders.edge_width(top_right, right, bottom_right)
24
+ def bottom_size = Borders.edge_width(bottom_left, bottom, bottom_right)
25
+ def left_size = Borders.edge_width(top_left, left, bottom_left)
26
+ end
27
+
28
+ module Borders
29
+ def self.define(**fields)
30
+ BorderDef.new(**BorderDef.members.to_h { |m| [m, ""] }.merge(fields)).freeze
31
+ end
32
+ private_class_method :define
33
+
34
+ NO_BORDER = define
35
+
36
+ NORMAL = define(
37
+ top: "─", bottom: "─", left: "│", right: "│",
38
+ top_left: "┌", top_right: "┐", bottom_left: "└", bottom_right: "┘",
39
+ middle_left: "├", middle_right: "┤", middle: "┼", middle_top: "┬", middle_bottom: "┴"
40
+ )
41
+
42
+ ROUNDED = define(
43
+ top: "─", bottom: "─", left: "│", right: "│",
44
+ top_left: "╭", top_right: "╮", bottom_left: "╰", bottom_right: "╯",
45
+ middle_left: "├", middle_right: "┤", middle: "┼", middle_top: "┬", middle_bottom: "┴"
46
+ )
47
+
48
+ BLOCK = define(
49
+ top: "█", bottom: "█", left: "█", right: "█",
50
+ top_left: "█", top_right: "█", bottom_left: "█", bottom_right: "█",
51
+ middle_left: "█", middle_right: "█", middle: "█", middle_top: "█", middle_bottom: "█"
52
+ )
53
+
54
+ OUTER_HALF_BLOCK = define(
55
+ top: "▀", bottom: "▄", left: "▌", right: "▐",
56
+ top_left: "▛", top_right: "▜", bottom_left: "▙", bottom_right: "▟"
57
+ )
58
+
59
+ INNER_HALF_BLOCK = define(
60
+ top: "▄", bottom: "▀", left: "▐", right: "▌",
61
+ top_left: "▗", top_right: "▖", bottom_left: "▝", bottom_right: "▘"
62
+ )
63
+
64
+ THICK = define(
65
+ top: "━", bottom: "━", left: "┃", right: "┃",
66
+ top_left: "┏", top_right: "┓", bottom_left: "┗", bottom_right: "┛",
67
+ middle_left: "┣", middle_right: "┫", middle: "╋", middle_top: "┳", middle_bottom: "┻"
68
+ )
69
+
70
+ DOUBLE = define(
71
+ top: "═", bottom: "═", left: "║", right: "║",
72
+ top_left: "╔", top_right: "╗", bottom_left: "╚", bottom_right: "╝",
73
+ middle_left: "╠", middle_right: "╣", middle: "╬", middle_top: "╦", middle_bottom: "╩"
74
+ )
75
+
76
+ HIDDEN = define(
77
+ top: " ", bottom: " ", left: " ", right: " ",
78
+ top_left: " ", top_right: " ", bottom_left: " ", bottom_right: " ",
79
+ middle_left: " ", middle_right: " ", middle: " ", middle_top: " ", middle_bottom: " "
80
+ )
81
+
82
+ MARKDOWN = define(
83
+ top: "-", bottom: "-", left: "|", right: "|",
84
+ top_left: "|", top_right: "|", bottom_left: "|", bottom_right: "|",
85
+ middle_left: "|", middle_right: "|", middle: "|", middle_top: "|", middle_bottom: "|"
86
+ )
87
+
88
+ ASCII = define(
89
+ top: "-", bottom: "-", left: "|", right: "|",
90
+ top_left: "+", top_right: "+", bottom_left: "+", bottom_right: "+",
91
+ middle_left: "+", middle_right: "+", middle: "+", middle_top: "+", middle_bottom: "+"
92
+ )
93
+
94
+ BY_NAME = {
95
+ normal: NORMAL, rounded: ROUNDED, block: BLOCK, outer_half_block: OUTER_HALF_BLOCK,
96
+ inner_half_block: INNER_HALF_BLOCK, thick: THICK, double: DOUBLE, hidden: HIDDEN,
97
+ markdown: MARKDOWN, ascii: ASCII
98
+ }.freeze
99
+
100
+ # The border types the gem's C extension recognizes (no :markdown there).
101
+ GEM_TYPES = %i[normal rounded thick double hidden block outer_half_block inner_half_block ascii].freeze
102
+
103
+ class << self
104
+ # NormalBorder(), RoundedBorder(), ... by name.
105
+ def fetch(name)
106
+ BY_NAME.fetch(name.to_sym) { raise KeyError, "unknown border #{name.inspect}" }
107
+ end
108
+
109
+ # What the C extension does with a border-type argument: one of its nine exact Symbols, or
110
+ # the normal border for anything else (strings, nil, :markdown, unknown symbols).
111
+ def resolve(value)
112
+ value.is_a?(Symbol) && GEM_TYPES.include?(value) ? BY_NAME.fetch(value) : NORMAL
113
+ end
114
+
115
+ # getBorderEdgeWidth
116
+ def edge_width(*parts)
117
+ parts.map { |piece| max_rune_width(piece.to_s) }.max || 0
118
+ end
119
+
120
+ # borders.go maxRuneWidth: the widest grapheme cluster.
121
+ def max_rune_width(str)
122
+ width = 0
123
+ state = -1
124
+ until str.empty?
125
+ _cluster, str, w, state = Text.first_grapheme_cluster_in_string(str, state)
126
+ width = w if w > width
127
+ end
128
+ width
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end