natty-ui 0.35.0 → 1.0.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -6
  3. data/examples/24bit-colors.rb +9 -5
  4. data/examples/3bit-colors.rb +7 -7
  5. data/examples/8bit-colors.rb +5 -7
  6. data/examples/attributes.rb +2 -3
  7. data/examples/elements.rb +9 -6
  8. data/examples/examples.rb +9 -9
  9. data/examples/frames.rb +31 -0
  10. data/examples/hbars.rb +6 -3
  11. data/examples/info.rb +13 -10
  12. data/examples/key-codes.rb +8 -9
  13. data/examples/ls.rb +24 -22
  14. data/examples/named-colors.rb +4 -3
  15. data/examples/sections.rb +26 -24
  16. data/examples/select.rb +28 -0
  17. data/examples/sh.rb +25 -7
  18. data/examples/tables.rb +19 -37
  19. data/examples/tasks.rb +32 -22
  20. data/examples/vbars.rb +5 -3
  21. data/lib/natty-ui/dumb_progress.rb +68 -0
  22. data/lib/natty-ui/element.rb +61 -70
  23. data/lib/natty-ui/features.rb +771 -949
  24. data/lib/natty-ui/frame.rb +87 -0
  25. data/lib/natty-ui/helper/table.rb +1376 -0
  26. data/lib/natty-ui/margin.rb +83 -0
  27. data/lib/natty-ui/progress.rb +116 -152
  28. data/lib/natty-ui/renderer/bars.rb +93 -0
  29. data/lib/natty-ui/renderer/choice.rb +56 -0
  30. data/lib/natty-ui/renderer/dumb_choice.rb +34 -0
  31. data/lib/natty-ui/renderer/dumb_select.rb +60 -0
  32. data/lib/natty-ui/renderer/dumb_shell_runner.rb +19 -0
  33. data/lib/natty-ui/renderer/heading.rb +26 -0
  34. data/lib/natty-ui/renderer/horizontal_rule.rb +32 -0
  35. data/lib/natty-ui/{ls_renderer.rb → renderer/ls.rb} +15 -27
  36. data/lib/natty-ui/renderer/mark.rb +13 -0
  37. data/lib/natty-ui/renderer/quote.rb +13 -0
  38. data/lib/natty-ui/renderer/select.rb +63 -0
  39. data/lib/natty-ui/renderer/shell.rb +15 -0
  40. data/lib/natty-ui/renderer/shell_runner.rb +29 -0
  41. data/lib/natty-ui/renderer/table_renderer.rb +429 -0
  42. data/lib/natty-ui/section.rb +144 -32
  43. data/lib/natty-ui/task.rb +38 -25
  44. data/lib/natty-ui/temporary.rb +27 -14
  45. data/lib/natty-ui/utils/border.rb +139 -0
  46. data/lib/natty-ui/utils/str_const.rb +62 -0
  47. data/lib/natty-ui/utils/utils.rb +47 -0
  48. data/lib/natty-ui/version.rb +1 -1
  49. data/lib/natty-ui.rb +76 -35
  50. metadata +31 -28
  51. data/examples/cols.rb +0 -38
  52. data/examples/illustration.rb +0 -60
  53. data/examples/options.rb +0 -28
  54. data/examples/themes.rb +0 -51
  55. data/lib/natty-ui/attributes.rb +0 -593
  56. data/lib/natty-ui/choice.rb +0 -67
  57. data/lib/natty-ui/dumb_choice.rb +0 -47
  58. data/lib/natty-ui/dumb_options.rb +0 -64
  59. data/lib/natty-ui/framed.rb +0 -50
  60. data/lib/natty-ui/hbars_renderer.rb +0 -66
  61. data/lib/natty-ui/options.rb +0 -78
  62. data/lib/natty-ui/shell_renderer.rb +0 -91
  63. data/lib/natty-ui/table.rb +0 -325
  64. data/lib/natty-ui/table_renderer.rb +0 -165
  65. data/lib/natty-ui/theme.rb +0 -403
  66. data/lib/natty-ui/utils.rb +0 -111
  67. data/lib/natty-ui/vbars_renderer.rb +0 -49
  68. data/lib/natty-ui/width_finder.rb +0 -137
  69. data/natty-ui.gemspec +0 -34
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'element'
4
+ require_relative 'utils/border'
5
+
6
+ module NattyUI
7
+ # An {Element} that draws a Unicode border box around its content.
8
+ #
9
+ # Instances are created by {Features#frame}. An optional title can be
10
+ # embedded in the top border line. The border style and ANSI colour are
11
+ # configurable.
12
+ #
13
+ # All {Features} methods are available on this element.
14
+ #
15
+ # @example Via block (auto-close)
16
+ # ui.frame 'Results', border: :double do
17
+ # ui.puts 'All checks passed.'
18
+ # end
19
+ #
20
+ # @example Manual close
21
+ # frm = ui.frame 'Preview'
22
+ # ui.puts 'Content inside the frame.'
23
+ # frm.end
24
+ class Frame < Element
25
+ # @private
26
+ def puts(*, **options)
27
+ return self if @done != 0
28
+ options[:width] = @parent.columns - @prefix.width - @suffix.width
29
+ options[:align] ||= :left
30
+ super
31
+ end
32
+
33
+ # @private
34
+ def hr(kind = nil)
35
+ return self if @done != 0
36
+ width = @parent.columns
37
+ return _hr_border(width, @border) if kind.nil?
38
+ return _hr_border(width, Border[kind]) if kind.is_a?(Symbol)
39
+ kind = StrConst[kind]
40
+ return _hr_border(width, @border) if kind.width == 0
41
+ width -= 2
42
+ puts(
43
+ "#{@style}#{
44
+ if kind.width > width
45
+ kind.to_str[0, width]
46
+ elsif kind.width == width
47
+ kind
48
+ else
49
+ kind.to_str * (width / kind.width)
50
+ end
51
+ }"
52
+ )
53
+ end
54
+
55
+ # @private
56
+ def heading(level, title)
57
+ return self if @done != 0
58
+ width = @parent.columns
59
+ hr = @border.hor(Border[level == 1 ? :double : :single], width, @style)
60
+ @parent.puts(hr) if level < 3 && @start_line != NattyUI.lines_written
61
+ puts(title, padding: [0, 1])
62
+ @parent.puts(hr)
63
+ self
64
+ end
65
+
66
+ private
67
+
68
+ def done
69
+ @parent.puts(@bottom) if (@done += 1) == 1 && @bottom
70
+ end
71
+
72
+ def initialize(parent, title, kind, style)
73
+ super(parent)
74
+ @start_line = NattyUI.lines_written
75
+ @border = Border[kind]
76
+ @style = Ansi[*(style || :bright_blue)]
77
+ @prefix, @suffix, top, @bottom =
78
+ @border.build(parent.columns, title, @style)
79
+ parent.puts(top, bbcode: false) if top
80
+ end
81
+
82
+ def _hr_border(width, border)
83
+ @parent.puts(@border.hor(border, width, @style))
84
+ self
85
+ end
86
+ end
87
+ end