natty-ui 0.34.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.
- checksums.yaml +4 -4
- data/.yardopts +0 -1
- data/README.md +6 -6
- data/examples/24bit-colors.rb +9 -5
- data/examples/3bit-colors.rb +7 -7
- data/examples/8bit-colors.rb +5 -5
- data/examples/attributes.rb +2 -3
- data/examples/elements.rb +9 -6
- data/examples/examples.rb +9 -9
- data/examples/frames.rb +31 -0
- data/examples/hbars.rb +6 -3
- data/examples/info.rb +13 -10
- data/examples/key-codes.rb +8 -9
- data/examples/ls.rb +24 -22
- data/examples/named-colors.rb +4 -3
- data/examples/sections.rb +27 -17
- data/examples/select.rb +28 -0
- data/examples/sh.rb +25 -7
- data/examples/tables.rb +19 -37
- data/examples/tasks.rb +32 -22
- data/examples/vbars.rb +5 -3
- data/lib/natty-ui/dumb_progress.rb +68 -0
- data/lib/natty-ui/element.rb +64 -65
- data/lib/natty-ui/features.rb +773 -872
- data/lib/natty-ui/frame.rb +87 -0
- data/lib/natty-ui/helper/table.rb +1376 -0
- data/lib/natty-ui/margin.rb +83 -0
- data/lib/natty-ui/progress.rb +116 -149
- data/lib/natty-ui/renderer/bars.rb +93 -0
- data/lib/natty-ui/renderer/choice.rb +56 -0
- data/lib/natty-ui/renderer/dumb_choice.rb +34 -0
- data/lib/natty-ui/renderer/dumb_select.rb +60 -0
- data/lib/natty-ui/renderer/dumb_shell_runner.rb +19 -0
- data/lib/natty-ui/renderer/heading.rb +26 -0
- data/lib/natty-ui/renderer/horizontal_rule.rb +32 -0
- data/lib/natty-ui/{ls_renderer.rb → renderer/ls.rb} +15 -27
- data/lib/natty-ui/renderer/mark.rb +13 -0
- data/lib/natty-ui/renderer/quote.rb +13 -0
- data/lib/natty-ui/renderer/select.rb +63 -0
- data/lib/natty-ui/renderer/shell.rb +15 -0
- data/lib/natty-ui/renderer/shell_runner.rb +29 -0
- data/lib/natty-ui/renderer/table_renderer.rb +429 -0
- data/lib/natty-ui/section.rb +142 -41
- data/lib/natty-ui/task.rb +39 -27
- data/lib/natty-ui/temporary.rb +27 -14
- data/lib/natty-ui/utils/border.rb +139 -0
- data/lib/natty-ui/utils/str_const.rb +62 -0
- data/lib/natty-ui/utils/utils.rb +47 -0
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui.rb +87 -30
- metadata +31 -28
- data/examples/cols.rb +0 -38
- data/examples/illustration.rb +0 -60
- data/examples/options.rb +0 -28
- data/examples/themes.rb +0 -51
- data/lib/natty-ui/attributes.rb +0 -593
- data/lib/natty-ui/choice.rb +0 -67
- data/lib/natty-ui/dumb_choice.rb +0 -47
- data/lib/natty-ui/dumb_options.rb +0 -64
- data/lib/natty-ui/framed.rb +0 -51
- data/lib/natty-ui/hbars_renderer.rb +0 -66
- data/lib/natty-ui/options.rb +0 -78
- data/lib/natty-ui/shell_renderer.rb +0 -91
- data/lib/natty-ui/table.rb +0 -325
- data/lib/natty-ui/table_renderer.rb +0 -165
- data/lib/natty-ui/theme.rb +0 -403
- data/lib/natty-ui/utils.rb +0 -111
- data/lib/natty-ui/vbars_renderer.rb +0 -49
- data/lib/natty-ui/width_finder.rb +0 -137
- 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
|