natty-ui 0.32.0 → 0.34.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.
- checksums.yaml +4 -4
- data/.yardopts +0 -1
- data/README.md +4 -0
- data/examples/hbars.rb +3 -3
- data/examples/info.rb +1 -1
- data/examples/key-codes.rb +18 -23
- data/examples/named-colors.rb +8 -6
- data/examples/sh.rb +17 -0
- data/examples/tasks.rb +4 -4
- data/examples/vbars.rb +4 -4
- data/lib/natty-ui/attributes.rb +7 -3
- data/lib/natty-ui/choice.rb +6 -5
- data/lib/natty-ui/dumb_choice.rb +6 -5
- data/lib/natty-ui/dumb_options.rb +6 -5
- data/lib/natty-ui/element.rb +28 -3
- data/lib/natty-ui/features.rb +59 -74
- data/lib/natty-ui/framed.rb +4 -4
- data/lib/natty-ui/ls_renderer.rb +2 -0
- data/lib/natty-ui/options.rb +3 -2
- data/lib/natty-ui/progress.rb +9 -7
- data/lib/natty-ui/section.rb +1 -1
- data/lib/natty-ui/shell_renderer.rb +9 -10
- data/lib/natty-ui/table_renderer.rb +2 -0
- data/lib/natty-ui/temporary.rb +3 -4
- data/lib/natty-ui/theme.rb +9 -2
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui/width_finder.rb +2 -0
- data/lib/natty-ui.rb +10 -21
- data/natty-ui.gemspec +34 -0
- metadata +11 -12
- data/LICENSE +0 -28
- data/lib/natty-ui/shell_command.rb +0 -132
data/lib/natty-ui/features.rb
CHANGED
|
@@ -45,7 +45,7 @@ module NattyUI
|
|
|
45
45
|
ignore_newline = options[:eol] == false || options[:ignore_newline]
|
|
46
46
|
|
|
47
47
|
if (max_width = options[:max_width]).nil?
|
|
48
|
-
|
|
48
|
+
max_width = Terminal.columns
|
|
49
49
|
elsif max_width < 1
|
|
50
50
|
if max_width > 0
|
|
51
51
|
max_width *= Terminal.columns
|
|
@@ -56,6 +56,8 @@ module NattyUI
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
return self if max_width <= 0
|
|
60
|
+
|
|
59
61
|
prefix_width =
|
|
60
62
|
if (prefix = options[:prefix])
|
|
61
63
|
prefix = Ansi.bbcode(prefix) if bbcode
|
|
@@ -117,8 +119,7 @@ module NattyUI
|
|
|
117
119
|
end
|
|
118
120
|
|
|
119
121
|
unless options[:expand]
|
|
120
|
-
lines = lines.to_a
|
|
121
|
-
max_width = lines.max_by(&:last).last
|
|
122
|
+
max_width = (lines = lines.to_a).max_by(&:last)[-1]
|
|
122
123
|
end
|
|
123
124
|
|
|
124
125
|
case align
|
|
@@ -595,20 +596,15 @@ module NattyUI
|
|
|
595
596
|
#
|
|
596
597
|
# @see run
|
|
597
598
|
#
|
|
598
|
-
# @param cmd
|
|
599
|
-
#
|
|
600
|
-
# @param
|
|
601
|
-
# whether a seperate shell should be created
|
|
602
|
-
# @param input [IO,#to_io,Array,#each,#to_a,#to_s,nil]
|
|
603
|
-
# input piped to the command
|
|
604
|
-
# @param preserve_spaces [true,false]
|
|
605
|
-
# whether the spaces and tabs of the output should be preserve
|
|
599
|
+
# @param cmd (see run)
|
|
600
|
+
# @param preserve_spaces (see run)
|
|
601
|
+
# @param options (see run)
|
|
606
602
|
# @return [Process::Status]
|
|
607
603
|
# when command was executed
|
|
608
604
|
# @return [nil]
|
|
609
605
|
# in error case (like command not found)
|
|
610
|
-
def sh(*cmd,
|
|
611
|
-
ShellRenderer.sh(self, cmd,
|
|
606
|
+
def sh(*cmd, preserve_spaces: false, **options)
|
|
607
|
+
ShellRenderer.sh(self, cmd, options, preserve_spaces)
|
|
612
608
|
end
|
|
613
609
|
|
|
614
610
|
# Execute a shell program and return output. Limit the lines displayed.
|
|
@@ -621,27 +617,23 @@ module NattyUI
|
|
|
621
617
|
#
|
|
622
618
|
# @see sh
|
|
623
619
|
#
|
|
624
|
-
# @param cmd
|
|
625
|
-
#
|
|
626
|
-
# @param
|
|
627
|
-
#
|
|
628
|
-
# @param max_lines [Integer]
|
|
620
|
+
# @param cmd [String]
|
|
621
|
+
# command and optional arguments
|
|
622
|
+
# @param preserve_spaces [true,false]
|
|
623
|
+
# whether the spaces and tabs of the output should be preserve
|
|
624
|
+
# @param max_lines [Integer]
|
|
625
|
+
# limit of displayed lines
|
|
626
|
+
# @param options [Hash] executions options
|
|
629
627
|
# @return [[Process::Status, Array<String>, Array<String>]]
|
|
630
628
|
# process status, output and error output when command was executed
|
|
631
|
-
# @return [nil]
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
shell: false,
|
|
635
|
-
input: nil,
|
|
636
|
-
preserve_spaces: false,
|
|
637
|
-
max_lines: 10
|
|
638
|
-
)
|
|
629
|
+
# @return [nil]
|
|
630
|
+
# in error case (like command not found)
|
|
631
|
+
def run(*cmd, preserve_spaces: false, max_lines: 10, **options)
|
|
639
632
|
result =
|
|
640
633
|
ShellRenderer.run(
|
|
641
634
|
self,
|
|
642
635
|
cmd,
|
|
643
|
-
|
|
644
|
-
input,
|
|
636
|
+
options,
|
|
645
637
|
preserve_spaces,
|
|
646
638
|
max_lines.clamp(1, Terminal.rows)
|
|
647
639
|
)
|
|
@@ -794,28 +786,20 @@ module NattyUI
|
|
|
794
786
|
# # Italian, Polish, Portuguese, Romanian, Spanish and Swedish.
|
|
795
787
|
#
|
|
796
788
|
# @overload await(yes: 'Enter', no: 'Esc')
|
|
797
|
-
# @param yes [String, Enumerable<String>]
|
|
798
|
-
# key code/s a user can input to return positive result
|
|
799
|
-
# @param no [String, Enumerable<String>]
|
|
800
|
-
# key code/s a user can input to return negative resault
|
|
801
|
-
#
|
|
802
|
-
# @return [true, false]
|
|
803
|
-
# whether the user inputs a positive result
|
|
804
789
|
#
|
|
805
790
|
# @overload await(yes: 'Enter', no: 'Esc', &block)
|
|
806
|
-
# @param yes [String, Enumerable<String>]
|
|
807
|
-
# key code/s a user can input to return positive result
|
|
808
|
-
# @param no [String, Enumerable<String>]
|
|
809
|
-
# key code/s a user can input to return negative resault
|
|
810
|
-
#
|
|
811
791
|
# @yieldparam temp [Temporary]
|
|
812
792
|
# temporary displayed section (section will be erased after input)
|
|
813
793
|
#
|
|
814
|
-
#
|
|
815
|
-
#
|
|
816
|
-
#
|
|
817
|
-
#
|
|
794
|
+
# @param yes [String, Enumerable<String>]
|
|
795
|
+
# key code/s a user can input to return positive result
|
|
796
|
+
# @param no [String, Enumerable<String>]
|
|
797
|
+
# key code/s a user can input to return negative resault
|
|
818
798
|
#
|
|
799
|
+
# @return [true, false]
|
|
800
|
+
# whether the user inputs a positive result
|
|
801
|
+
# @return [nil]
|
|
802
|
+
# in error case
|
|
819
803
|
def await(yes: 'Enter', no: 'Esc')
|
|
820
804
|
return __await(yes, no) unless block_given?
|
|
821
805
|
temporary do |temp|
|
|
@@ -828,9 +812,9 @@ module NattyUI
|
|
|
828
812
|
# The selected option is returned.
|
|
829
813
|
#
|
|
830
814
|
# @overload choice(*choices, abortable: false)
|
|
831
|
-
# @param [#to_s]
|
|
815
|
+
# @param choices [#to_s]
|
|
832
816
|
# one or more alternatives to select from
|
|
833
|
-
# @param [true, false]
|
|
817
|
+
# @param abortable [true, false]
|
|
834
818
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
835
819
|
#
|
|
836
820
|
# @return [Integer]
|
|
@@ -845,9 +829,9 @@ module NattyUI
|
|
|
845
829
|
# # => 1, when bananas are user's favorite
|
|
846
830
|
# # => 2, when user is a oranges lover
|
|
847
831
|
#
|
|
848
|
-
# @param [#to_s]
|
|
832
|
+
# @param choices[#to_s]
|
|
849
833
|
# one or more alternatives to select from
|
|
850
|
-
# @param [true, false]
|
|
834
|
+
# @param abortable[true, false]
|
|
851
835
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
852
836
|
#
|
|
853
837
|
# @yieldparam temp [Temporary]
|
|
@@ -859,11 +843,11 @@ module NattyUI
|
|
|
859
843
|
# when user aborted the selection
|
|
860
844
|
#
|
|
861
845
|
# @overload choice(**choices, abortable: false)
|
|
862
|
-
# @param [#to_s]
|
|
846
|
+
# @param choices [#to_s]
|
|
863
847
|
# one or more alternatives to select from
|
|
864
|
-
# @param [true, false]
|
|
848
|
+
# @param abortable [true, false]
|
|
865
849
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
866
|
-
# @param [#to_s, nil]
|
|
850
|
+
# @param selected [#to_s, nil]
|
|
867
851
|
# optionally pre-selected option
|
|
868
852
|
#
|
|
869
853
|
# @return [Object]
|
|
@@ -883,11 +867,11 @@ module NattyUI
|
|
|
883
867
|
# ) { ui.puts 'Which terminal emulator do you like?' }
|
|
884
868
|
# # => whether the user selected: :k, :i, :g, :t, :r
|
|
885
869
|
# # => nil, when the user aborted
|
|
886
|
-
# @param [#to_s]
|
|
870
|
+
# @param choices[#to_s]
|
|
887
871
|
# one or more alternatives to select from
|
|
888
|
-
# @param [true, false]
|
|
872
|
+
# @param abortable[true, false]
|
|
889
873
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
890
|
-
# @param [Integer]
|
|
874
|
+
# @param selected[Integer]
|
|
891
875
|
# pre-selected option index
|
|
892
876
|
#
|
|
893
877
|
# @yieldparam temp [Temporary]
|
|
@@ -912,11 +896,11 @@ module NattyUI
|
|
|
912
896
|
# Allows the user to select from several options.
|
|
913
897
|
# All options are returned with their selection status.
|
|
914
898
|
#
|
|
915
|
-
# @param [{#to_s => [true,false]}]
|
|
899
|
+
# @param choices [{#to_s => [true,false]}]
|
|
916
900
|
# Hash of options and their selection state
|
|
917
|
-
# @param [true, false]
|
|
901
|
+
# @param abortable [true, false]
|
|
918
902
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
919
|
-
# @param [#to_s, nil]
|
|
903
|
+
# @param selected [#to_s, nil]
|
|
920
904
|
# optionally pre-selected key
|
|
921
905
|
#
|
|
922
906
|
# @yieldparam temp [Temporary]
|
|
@@ -945,11 +929,11 @@ module NattyUI
|
|
|
945
929
|
# ui.puts '[i]Which terminal applications did you already tested?[/i]'
|
|
946
930
|
# end
|
|
947
931
|
#
|
|
948
|
-
# @param [Array<#to_s>]
|
|
932
|
+
# @param choices [Array<#to_s>]
|
|
949
933
|
# selectable options
|
|
950
|
-
# @param [true, false]
|
|
934
|
+
# @param abortable [true, false]
|
|
951
935
|
# whether the user is allowed to abort with 'Esc' or 'Ctrl+c'
|
|
952
|
-
# @param [Integer, :all, nil]
|
|
936
|
+
# @param selected [Integer, :all, nil]
|
|
953
937
|
# optionally pre-selected option index or `:all` to pre-select all items
|
|
954
938
|
# @yieldparam temp [Temporary]
|
|
955
939
|
# temporary displayed section (section will be erased after input)
|
|
@@ -982,7 +966,7 @@ module NattyUI
|
|
|
982
966
|
# @!group Utilities
|
|
983
967
|
#
|
|
984
968
|
|
|
985
|
-
#
|
|
969
|
+
# @private
|
|
986
970
|
def columns = Terminal.columns
|
|
987
971
|
|
|
988
972
|
# Display some temporary content.
|
|
@@ -1017,18 +1001,21 @@ module NattyUI
|
|
|
1017
1001
|
end
|
|
1018
1002
|
|
|
1019
1003
|
def __await(yes, no)
|
|
1020
|
-
|
|
1004
|
+
Terminal.on_key_event do |event|
|
|
1005
|
+
event = event.name
|
|
1021
1006
|
if (no == event) || (no.is_a?(Enumerable) && no.include?(event))
|
|
1022
1007
|
return false
|
|
1023
1008
|
end
|
|
1024
1009
|
if (yes == event) || (yes.is_a?(Enumerable) && yes.include?(event))
|
|
1025
1010
|
return true
|
|
1026
1011
|
end
|
|
1012
|
+
true
|
|
1027
1013
|
end
|
|
1028
1014
|
end
|
|
1029
1015
|
end
|
|
1030
1016
|
|
|
1031
|
-
dir = __dir__
|
|
1017
|
+
dir = __dir__ # call the function once
|
|
1018
|
+
|
|
1032
1019
|
autoload :Framed, "#{dir}/framed.rb"
|
|
1033
1020
|
autoload :Section, "#{dir}/section.rb"
|
|
1034
1021
|
autoload :Table, "#{dir}/table.rb"
|
|
@@ -1036,6 +1023,7 @@ module NattyUI
|
|
|
1036
1023
|
autoload :Temporary, "#{dir}/temporary.rb"
|
|
1037
1024
|
autoload :Theme, "#{dir}/theme.rb"
|
|
1038
1025
|
autoload :Utils, "#{dir}/utils.rb"
|
|
1026
|
+
private_constant(:Framed, :Utils)
|
|
1039
1027
|
|
|
1040
1028
|
autoload :Choice, "#{dir}/choice.rb"
|
|
1041
1029
|
autoload :DumbChoice, "#{dir}/dumb_choice.rb"
|
|
@@ -1043,24 +1031,21 @@ module NattyUI
|
|
|
1043
1031
|
autoload :DumbOptions, "#{dir}/dumb_options.rb"
|
|
1044
1032
|
autoload :Progress, "#{dir}/progress.rb"
|
|
1045
1033
|
autoload :DumbProgress, "#{dir}/progress.rb"
|
|
1034
|
+
private_constant(
|
|
1035
|
+
:Choice,
|
|
1036
|
+
:DumbChoice,
|
|
1037
|
+
:Options,
|
|
1038
|
+
:DumbOptions,
|
|
1039
|
+
:Progress,
|
|
1040
|
+
:DumbProgress
|
|
1041
|
+
)
|
|
1046
1042
|
|
|
1047
1043
|
autoload :CompactLSRenderer, "#{dir}/ls_renderer.rb"
|
|
1048
1044
|
autoload :HBarsRenderer, "#{dir}/hbars_renderer.rb"
|
|
1049
1045
|
autoload :LSRenderer, "#{dir}/ls_renderer.rb"
|
|
1050
1046
|
autoload :ShellRenderer, "#{dir}/shell_renderer.rb"
|
|
1051
1047
|
autoload :VBarsRenderer, "#{dir}/vbars_renderer.rb"
|
|
1052
|
-
|
|
1053
1048
|
private_constant(
|
|
1054
|
-
:Framed,
|
|
1055
|
-
:Utils,
|
|
1056
|
-
# -
|
|
1057
|
-
:Choice,
|
|
1058
|
-
:DumbChoice,
|
|
1059
|
-
:Options,
|
|
1060
|
-
:DumbOptions,
|
|
1061
|
-
:Progress,
|
|
1062
|
-
:DumbProgress,
|
|
1063
|
-
# -
|
|
1064
1049
|
:CompactLSRenderer,
|
|
1065
1050
|
:HBarsRenderer,
|
|
1066
1051
|
:LSRenderer,
|
data/lib/natty-ui/framed.rb
CHANGED
|
@@ -6,10 +6,10 @@ module NattyUI
|
|
|
6
6
|
# {Element} with a frame around the content used by {Features.framed}.
|
|
7
7
|
#
|
|
8
8
|
class Framed < Element
|
|
9
|
-
#
|
|
9
|
+
# @private
|
|
10
10
|
def closed? = @bottom ? false : true
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# @private
|
|
13
13
|
def puts(*objects, **options)
|
|
14
14
|
return self if closed?
|
|
15
15
|
options[:align] = @align
|
|
@@ -17,14 +17,14 @@ module NattyUI
|
|
|
17
17
|
super
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
#
|
|
20
|
+
# @private
|
|
21
21
|
def done
|
|
22
22
|
return if closed?
|
|
23
23
|
@parent.puts(@bottom)
|
|
24
24
|
@bottom = nil
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
#
|
|
27
|
+
# @private
|
|
28
28
|
def inspect = "#{_to_s.chop} align=#{@align.inspect} closed?=#{closed?}>"
|
|
29
29
|
|
|
30
30
|
private
|
data/lib/natty-ui/ls_renderer.rb
CHANGED
|
@@ -47,6 +47,7 @@ module NattyUI
|
|
|
47
47
|
|
|
48
48
|
class Item
|
|
49
49
|
attr_reader :width
|
|
50
|
+
|
|
50
51
|
def to_s(in_width) = "#{@str}#{' ' * (in_width - @width)}"
|
|
51
52
|
|
|
52
53
|
def initialize(str)
|
|
@@ -54,6 +55,7 @@ module NattyUI
|
|
|
54
55
|
@width = Text.width(str)
|
|
55
56
|
end
|
|
56
57
|
end
|
|
58
|
+
|
|
57
59
|
private_constant :Item
|
|
58
60
|
end
|
|
59
61
|
end
|
data/lib/natty-ui/options.rb
CHANGED
|
@@ -9,7 +9,7 @@ module NattyUI
|
|
|
9
9
|
pin_line = NattyUI.lines_written
|
|
10
10
|
draw
|
|
11
11
|
last = @current
|
|
12
|
-
|
|
12
|
+
Terminal.on_key_event do |event|
|
|
13
13
|
case event.name
|
|
14
14
|
when 'Esc', 'Ctrl+c'
|
|
15
15
|
return if @abortable
|
|
@@ -34,7 +34,7 @@ module NattyUI
|
|
|
34
34
|
keys = @opts.keys
|
|
35
35
|
@current = keys[keys.index(@current) + 1] || keys[0]
|
|
36
36
|
end
|
|
37
|
-
next if last == @current
|
|
37
|
+
next true if last == @current
|
|
38
38
|
pin_line = NattyUI.back_to_line(pin_line, erase: false)
|
|
39
39
|
draw
|
|
40
40
|
last = @current
|
|
@@ -73,5 +73,6 @@ module NattyUI
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
|
+
|
|
76
77
|
private_constant :Options
|
|
77
78
|
end
|
data/lib/natty-ui/progress.rb
CHANGED
|
@@ -44,6 +44,11 @@ module NattyUI
|
|
|
44
44
|
redraw
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Increment {value} and/or change {title}.
|
|
48
|
+
#
|
|
49
|
+
# @param count [Integer] increment
|
|
50
|
+
# @param title [#to_s] new title
|
|
51
|
+
# @return [ProgressHelper] itself
|
|
47
52
|
def step(count: 1, title: nil)
|
|
48
53
|
@title = title if title
|
|
49
54
|
self.value += count
|
|
@@ -53,7 +58,7 @@ module NattyUI
|
|
|
53
58
|
alias _to_s to_s
|
|
54
59
|
private :_to_s
|
|
55
60
|
|
|
56
|
-
#
|
|
61
|
+
# @private
|
|
57
62
|
def to_s
|
|
58
63
|
return "#{title}: #{format('%5.2f', @value)}" unless @max
|
|
59
64
|
"#{@title}: #{
|
|
@@ -66,7 +71,7 @@ module NattyUI
|
|
|
66
71
|
}"
|
|
67
72
|
end
|
|
68
73
|
|
|
69
|
-
#
|
|
74
|
+
# @private
|
|
70
75
|
def inspect = "#{_to_s.chop} #{self}>"
|
|
71
76
|
end
|
|
72
77
|
|
|
@@ -77,7 +82,6 @@ module NattyUI
|
|
|
77
82
|
|
|
78
83
|
def _done(text)
|
|
79
84
|
NattyUI.back_to_line(@pin_line)
|
|
80
|
-
@pin_line = nil
|
|
81
85
|
cm = Theme.current.mark(:checkmark)
|
|
82
86
|
@parent.puts(
|
|
83
87
|
*text,
|
|
@@ -89,7 +93,6 @@ module NattyUI
|
|
|
89
93
|
|
|
90
94
|
def _failed
|
|
91
95
|
NattyUI.back_to_line(NattyUI.lines_written - 1) if @last&.size == 2
|
|
92
|
-
@pin_line = nil
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
def initialize(parent, title, max, pin)
|
|
@@ -101,8 +104,8 @@ module NattyUI
|
|
|
101
104
|
@style = Theme.current.task_style
|
|
102
105
|
cm = Theme.current.mark(:current)
|
|
103
106
|
@redraw_opts = {
|
|
104
|
-
first_line_prefix: "#{cm}
|
|
105
|
-
first_line_prefix_width: cm.width
|
|
107
|
+
first_line_prefix: "#{cm}#{@style}",
|
|
108
|
+
first_line_prefix_width: cm.width
|
|
106
109
|
}
|
|
107
110
|
max ? self.max = max : redraw
|
|
108
111
|
end
|
|
@@ -125,7 +128,6 @@ module NattyUI
|
|
|
125
128
|
size = [@parent.columns, 72].min - 11
|
|
126
129
|
percent = format('%5.2f', 100.0 * diff)
|
|
127
130
|
return percent if size < 10
|
|
128
|
-
return if percent == '100.00'
|
|
129
131
|
fill = '█' * (size * diff)
|
|
130
132
|
"#{percent}% [bright_black]┃#{@style}#{fill}[bright_black]#{
|
|
131
133
|
'░' * (size - fill.size)
|
data/lib/natty-ui/section.rb
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'theme'
|
|
4
|
-
require_relative 'shell_command'
|
|
5
4
|
|
|
6
5
|
module NattyUI
|
|
7
6
|
module ShellRenderer
|
|
8
|
-
def self.sh(parent, cmd,
|
|
9
|
-
opts_out, opts_err =
|
|
10
|
-
|
|
7
|
+
def self.sh(parent, cmd, options, space)
|
|
8
|
+
opts_out, opts_err = opts_from(Theme.current)
|
|
9
|
+
Terminal.sh(*cmd, **options) do |line, kind|
|
|
11
10
|
parent.puts(
|
|
12
11
|
space ? line.gsub("\t", ' ').gsub(/[[:space:]]/, ' ') : line,
|
|
13
12
|
**(kind == :error ? opts_err : opts_out)
|
|
@@ -16,7 +15,7 @@ module NattyUI
|
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
if Terminal.ansi?
|
|
19
|
-
def self.
|
|
18
|
+
def self.opts_from(theme)
|
|
20
19
|
out = theme.mark(:sh_out)
|
|
21
20
|
err = theme.mark(:sh_err)
|
|
22
21
|
[
|
|
@@ -33,14 +32,14 @@ module NattyUI
|
|
|
33
32
|
]
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
def self.run(parent, cmd,
|
|
35
|
+
def self.run(parent, cmd, options, space, tail)
|
|
37
36
|
theme = Theme.current
|
|
38
37
|
opref = "#{theme.mark(:sh_out)}#{theme.sh_out_style}"
|
|
39
38
|
epref = "#{theme.mark(:sh_err)}#{theme.sh_err_style}"
|
|
40
39
|
out, err, show = [], [], []
|
|
41
40
|
start = NattyUI.lines_written
|
|
42
41
|
[
|
|
43
|
-
|
|
42
|
+
Terminal.sh(*cmd, **options) do |line, kind|
|
|
44
43
|
start = NattyUI.back_to_line(start)
|
|
45
44
|
ol = space ? line.gsub("\t", ' ').gsub(/[[:space:]]/, ' ') : line
|
|
46
45
|
if kind == :error
|
|
@@ -57,7 +56,7 @@ module NattyUI
|
|
|
57
56
|
]
|
|
58
57
|
end
|
|
59
58
|
else
|
|
60
|
-
def self.
|
|
59
|
+
def self.opts_from(theme)
|
|
61
60
|
out = theme.mark(:sh_out)
|
|
62
61
|
err = theme.mark(:sh_err)
|
|
63
62
|
[
|
|
@@ -66,12 +65,12 @@ module NattyUI
|
|
|
66
65
|
]
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
def self.run(parent, cmd,
|
|
68
|
+
def self.run(parent, cmd, options, _space, _tail)
|
|
70
69
|
theme = Theme.current
|
|
71
70
|
opref, epref = theme.mark(:sh_out), theme.mark(:sh_err)
|
|
72
71
|
out, err = [], []
|
|
73
72
|
[
|
|
74
|
-
|
|
73
|
+
Terminal.sh(*cmd, **options) do |line, kind|
|
|
75
74
|
ol = line.gsub("\t", ' ').gsub(/[[:space:]]/, ' ')
|
|
76
75
|
if kind == :error
|
|
77
76
|
err << line
|
data/lib/natty-ui/temporary.rb
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
require_relative 'element'
|
|
4
4
|
|
|
5
5
|
module NattyUI
|
|
6
|
-
#
|
|
7
|
-
# {Features.temporary}.
|
|
6
|
+
# Temporary display section used by {Features.temporary}.
|
|
8
7
|
#
|
|
9
8
|
class Temporary < Element
|
|
10
|
-
#
|
|
9
|
+
# @private
|
|
11
10
|
def puts(*objects, **opts)
|
|
12
11
|
return self if @state
|
|
13
12
|
if opts.delete(:pin)
|
|
@@ -16,7 +15,7 @@ module NattyUI
|
|
|
16
15
|
super
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
#
|
|
18
|
+
# @private
|
|
20
19
|
def done
|
|
21
20
|
return self if @state
|
|
22
21
|
NattyUI.back_to_line(@start_line) if @start_line
|
data/lib/natty-ui/theme.rb
CHANGED
|
@@ -163,6 +163,8 @@ module NattyUI
|
|
|
163
163
|
current: '➔',
|
|
164
164
|
choice: '◦',
|
|
165
165
|
current_choice: '◉',
|
|
166
|
+
option: '[ ]',
|
|
167
|
+
option_selected: '[X]',
|
|
166
168
|
sh_out: ':',
|
|
167
169
|
sh_err: '𝙓'
|
|
168
170
|
}
|
|
@@ -243,8 +245,8 @@ module NattyUI
|
|
|
243
245
|
# [current?][selected?]
|
|
244
246
|
c = @mark[:current_choice]
|
|
245
247
|
n = @mark[:none]
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
uns = @mark[:option]
|
|
249
|
+
sel = @mark[:option_selected]
|
|
248
250
|
{
|
|
249
251
|
false => { false => n + uns, true => n + sel }.compare_by_identity,
|
|
250
252
|
true => { false => c + uns, true => c + sel }.compare_by_identity
|
|
@@ -323,6 +325,7 @@ module NattyUI
|
|
|
323
325
|
]
|
|
324
326
|
end
|
|
325
327
|
end
|
|
328
|
+
|
|
326
329
|
private_constant :SectionBorder
|
|
327
330
|
|
|
328
331
|
@ll = {}
|
|
@@ -347,6 +350,8 @@ module NattyUI
|
|
|
347
350
|
current: '[bright_green]➔[/fg]',
|
|
348
351
|
choice: '[bright_white]◦[/fg]',
|
|
349
352
|
current_choice: '[bright_green]➔[/fg]',
|
|
353
|
+
option: '[dim][ ][/dim]',
|
|
354
|
+
option_selected: '[dim][[/dim][green]X[/fg][dim]][/dim]',
|
|
350
355
|
sh_out: '[bright_white]:[/fg]',
|
|
351
356
|
sh_err: '[red]𝙓[/fg]'
|
|
352
357
|
)
|
|
@@ -378,6 +383,8 @@ module NattyUI
|
|
|
378
383
|
current: '➡️',
|
|
379
384
|
choice: '[bright_white]•[/fg]',
|
|
380
385
|
current_choice: '[bright_green]●[/fg]',
|
|
386
|
+
option: '[dim][ ][/dim] ',
|
|
387
|
+
option_selected: '[dim][[/dim][green]X[/fg][dim]][/dim]',
|
|
381
388
|
sh_out: '[white b]:[/]',
|
|
382
389
|
sh_err: '❗️'
|
|
383
390
|
)
|
data/lib/natty-ui/version.rb
CHANGED
data/lib/natty-ui.rb
CHANGED
|
@@ -33,7 +33,7 @@ module NattyUI
|
|
|
33
33
|
# @return [:dumb]
|
|
34
34
|
# when terminal does not support ANSI or interactive input
|
|
35
35
|
# @return [nil]
|
|
36
|
-
# when terminal
|
|
36
|
+
# when terminal input is not supported
|
|
37
37
|
def input_mode
|
|
38
38
|
case Terminal.input_mode
|
|
39
39
|
when :csi_u, :legacy
|
|
@@ -50,29 +50,29 @@ module NattyUI
|
|
|
50
50
|
# configured title
|
|
51
51
|
# @return [nil]
|
|
52
52
|
# when no title was set
|
|
53
|
-
def title = @title_stack
|
|
53
|
+
def title = @title_stack[-1]
|
|
54
54
|
|
|
55
55
|
# @attribute [w] title
|
|
56
56
|
def title=(value)
|
|
57
57
|
if value
|
|
58
58
|
title = Ansi.plain(value).gsub(/\s+/, ' ')
|
|
59
|
-
|
|
59
|
+
Terminal.raw_write(Ansi.title(title)) if Terminal.ansi?
|
|
60
60
|
@title_stack << title
|
|
61
61
|
else
|
|
62
62
|
@title_stack.pop
|
|
63
63
|
last = @title_stack[-1]
|
|
64
|
-
|
|
64
|
+
Terminal.raw_write(Ansi.title(last)) if last && Terminal.ansi?
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
#
|
|
68
|
+
# @private
|
|
69
69
|
attr_reader :lines_written
|
|
70
70
|
|
|
71
|
-
#
|
|
71
|
+
# @private
|
|
72
72
|
def back_to_line(number, erase: true)
|
|
73
73
|
return @lines_written if (c = @lines_written - number) <= 0
|
|
74
74
|
if Terminal.ansi?
|
|
75
|
-
|
|
75
|
+
Terminal.raw_write(
|
|
76
76
|
if erase == :all
|
|
77
77
|
Ansi.cursor_prev_line(c) + Ansi::SCREEN_ERASE_BELOW
|
|
78
78
|
elsif erase
|
|
@@ -85,21 +85,8 @@ module NattyUI
|
|
|
85
85
|
@lines_written = number
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
# @!visibility private
|
|
89
|
-
def alternate_screen
|
|
90
|
-
return yield unless Terminal.ansi?
|
|
91
|
-
begin
|
|
92
|
-
_write(Ansi::SCREEN_ALTERNATE)
|
|
93
|
-
yield
|
|
94
|
-
ensure
|
|
95
|
-
_write(Ansi::SCREEN_ALTERNATE_OFF)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
88
|
private
|
|
100
89
|
|
|
101
|
-
def _write(str) = Terminal.__send__(:_write, str)
|
|
102
|
-
|
|
103
90
|
def with(element)
|
|
104
91
|
Terminal.hide_cursor if @element == self
|
|
105
92
|
current, @element = @element, element
|
|
@@ -113,12 +100,14 @@ module NattyUI
|
|
|
113
100
|
@element = self
|
|
114
101
|
@lines_written = 0
|
|
115
102
|
@title_stack = []
|
|
103
|
+
|
|
104
|
+
autoload :VERSION, "#{__dir__}/natty-ui/version.rb"
|
|
116
105
|
end
|
|
117
106
|
|
|
118
107
|
unless defined?(Kernel.ui)
|
|
119
108
|
module Kernel
|
|
120
109
|
# @attribute [r] ui
|
|
121
|
-
# @return [NattyUI::Features] current used
|
|
110
|
+
# @return [NattyUI::Features] current used UI element
|
|
122
111
|
# @see NattyUI.element
|
|
123
112
|
def ui = NattyUI.element
|
|
124
113
|
|