natty-ui 0.34.0 → 0.35.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 +1 -1
- data/examples/8bit-colors.rb +2 -0
- data/examples/sections.rb +14 -6
- data/lib/natty-ui/element.rb +15 -7
- data/lib/natty-ui/features.rb +163 -84
- data/lib/natty-ui/framed.rb +1 -2
- data/lib/natty-ui/progress.rb +3 -0
- data/lib/natty-ui/section.rb +5 -16
- data/lib/natty-ui/task.rb +2 -3
- data/lib/natty-ui/version.rb +1 -1
- data/lib/natty-ui.rb +23 -7
- data/natty-ui.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f193a0c86adab949f0d0c40d522e879d47f0a75a6a52ae9cf4f9ff39a7582e0e
|
|
4
|
+
data.tar.gz: 2841fcf9135c48ef2df17ffcea4f5ff7619fe51dc62a489e58a9b7fc21f2bc1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d956fcf0d7cf2809bda3db9e82e84a02fe260e7646c54f1ba195dc04e3e8842677d6bb2c6e3dc95712c2da59580d6753e5218cccd2779408d10c1174cf96d12
|
|
7
|
+
data.tar.gz: 99c7fa8acd5d4f6c12db79b95e02da4a269ade5439a8d6918ca8b47a07ac2dce24cb2f91a146f23fe3b9d4554588b2e6f9b02be476cf725d9e058985f7ed763a
|
data/.yardopts
CHANGED
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely, nat
|
|
|
4
4
|
|
|
5
5
|
- Gem: [rubygems.org](https://rubygems.org/gems/natty-ui)
|
|
6
6
|
- Source: [codeberg.org](https://codeberg.org/mblumtritt/natty-ui)
|
|
7
|
-
- Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/
|
|
7
|
+
- Help: [rubydoc.info](https://rubydoc.info/gems/natty-ui/NattyUI)
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
data/examples/8bit-colors.rb
CHANGED
|
@@ -10,12 +10,14 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]8bit Color Support[/]' do
|
|
|
10
10
|
[#ff]#{0.upto(7).map(&color).join}
|
|
11
11
|
[#00]#{8.upto(15).map(&color).join}
|
|
12
12
|
COLORS
|
|
13
|
+
ui.end
|
|
13
14
|
|
|
14
15
|
ui.space
|
|
15
16
|
ui.message 'Grayscale', <<~GRAYSCALE.chomp
|
|
16
17
|
[#ff]#{0xe8.upto(0xf3).map(&color).join}
|
|
17
18
|
[#ff]#{0xf4.upto(0xff).map(&color).join}
|
|
18
19
|
GRAYSCALE
|
|
20
|
+
ui.end
|
|
19
21
|
|
|
20
22
|
ui.space
|
|
21
23
|
ui.message '6x6x6 Color Cube' do
|
data/examples/sections.rb
CHANGED
|
@@ -10,17 +10,25 @@ ui.message '[b]ᓚᕠᗢ NattyUI[/b] [i green]Sections[/]' do
|
|
|
10
10
|
means they may contain text, other sections, titles, horizontal rules,
|
|
11
11
|
lists, progress bars and much more!
|
|
12
12
|
TEXT
|
|
13
|
-
end
|
|
14
13
|
|
|
15
|
-
ui.space
|
|
16
|
-
ui.warning "Warning\nThis is a warning message example."
|
|
17
|
-
|
|
18
|
-
ui.space
|
|
19
|
-
ui.error 'Error Message' do
|
|
20
14
|
ui.space
|
|
21
15
|
ui.cols do |cc|
|
|
22
16
|
cc.add "()-()\n \\\"/\n `", width: 6, style: :yellow
|
|
23
17
|
cc.add 'You can add all other elements to a section.', vertical: :middle
|
|
24
18
|
end
|
|
19
|
+
|
|
20
|
+
ui.framed(<<~TEXT, align: :centered, eol: false).end
|
|
21
|
+
Sections and messages can be called with code blocks and will be
|
|
22
|
+
automatically closed when the block ends. Without a code block the
|
|
23
|
+
section or message needs to be closed.
|
|
24
|
+
TEXT
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
ui.warning "Warning\nThis is a warning message example."
|
|
28
|
+
ui.end
|
|
29
|
+
|
|
30
|
+
ui.error('Error Message', <<~MSG, align: :right, prefix: '[b red]>[/] ').end
|
|
31
|
+
Error message text with
|
|
32
|
+
print options.
|
|
33
|
+
MSG
|
|
26
34
|
end
|
data/lib/natty-ui/element.rb
CHANGED
|
@@ -8,6 +8,11 @@ module NattyUI
|
|
|
8
8
|
class Element
|
|
9
9
|
include Features
|
|
10
10
|
|
|
11
|
+
# Close the element.
|
|
12
|
+
#
|
|
13
|
+
# @return [Features] current element
|
|
14
|
+
def end = NattyUI.__send__(:_end, self)
|
|
15
|
+
|
|
11
16
|
# @private
|
|
12
17
|
def columns = @parent.columns - @prefix_width - @suffix_width
|
|
13
18
|
|
|
@@ -71,13 +76,13 @@ module NattyUI
|
|
|
71
76
|
# Close the element.
|
|
72
77
|
#
|
|
73
78
|
# @param [#to_s] text optional message
|
|
74
|
-
# @return [
|
|
79
|
+
# @return [Features] current element
|
|
75
80
|
def ok(*text)
|
|
76
81
|
return self if @state
|
|
77
82
|
text = [@title] if text.empty? && @title
|
|
78
83
|
_done(text)
|
|
79
84
|
@state = :ok
|
|
80
|
-
self
|
|
85
|
+
self.end
|
|
81
86
|
end
|
|
82
87
|
alias done ok
|
|
83
88
|
|
|
@@ -86,14 +91,17 @@ module NattyUI
|
|
|
86
91
|
# @param text [#to_s] optional message
|
|
87
92
|
# @yield optionally, when block is given
|
|
88
93
|
# @yieldparam failed [Section] see {Features.failed}
|
|
89
|
-
# @return [
|
|
94
|
+
# @return [Features] current element
|
|
90
95
|
def failed(*text, &block)
|
|
91
96
|
return self if @state
|
|
92
|
-
|
|
97
|
+
if text.empty?
|
|
98
|
+
super(@title, &block).ok if @title
|
|
99
|
+
else
|
|
100
|
+
super.ok
|
|
101
|
+
end
|
|
93
102
|
@state = :failed
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
self
|
|
103
|
+
_failed
|
|
104
|
+
self.end
|
|
97
105
|
end
|
|
98
106
|
end
|
|
99
107
|
end
|
data/lib/natty-ui/features.rb
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module NattyUI
|
|
4
4
|
# These are all supported features by {NattyUI} or any other sub- element
|
|
5
|
-
# like {section}, {message}, {
|
|
5
|
+
# like {#section}, {#message}, {#information}, {#warning}, {#error},
|
|
6
|
+
# {#failed}, {#framed}, {#task}, ...
|
|
6
7
|
#
|
|
7
8
|
# Any printed text can contain *BBCode*-like embedded ANSI attributes which
|
|
8
9
|
# will be used when the output terminal supports attributes and colors.
|
|
@@ -26,8 +27,8 @@ module NattyUI
|
|
|
26
27
|
#
|
|
27
28
|
# @see #pin
|
|
28
29
|
#
|
|
29
|
-
# @param text [
|
|
30
|
-
# one or more
|
|
30
|
+
# @param text [*#to_s]
|
|
31
|
+
# one or more objects to print line by line
|
|
31
32
|
# @param options [{Symbol => Object}]
|
|
32
33
|
# @option options [:left, :right, :centered] :align (:left)
|
|
33
34
|
# text alignment
|
|
@@ -570,13 +571,14 @@ module NattyUI
|
|
|
570
571
|
# @return [Object]
|
|
571
572
|
# the result of the given block
|
|
572
573
|
def progress(title, max: nil, pin: false, &block)
|
|
573
|
-
|
|
574
|
+
__with(
|
|
574
575
|
if Terminal.ansi?
|
|
575
576
|
Progress.new(self, title, max, pin)
|
|
576
577
|
else
|
|
577
578
|
DumbProgress.new(self, title, max)
|
|
578
|
-
end
|
|
579
|
-
|
|
579
|
+
end,
|
|
580
|
+
&block
|
|
581
|
+
)
|
|
580
582
|
end
|
|
581
583
|
|
|
582
584
|
# Execute a program.
|
|
@@ -649,101 +651,163 @@ module NattyUI
|
|
|
649
651
|
#
|
|
650
652
|
|
|
651
653
|
# Create a visually separated section for the output of text elements.
|
|
654
|
+
# Besides this simple sections there exist sections of different kinds:
|
|
655
|
+
# {#message}, {#information}, {#warning}, {#error}, {#failed}, {#framed}
|
|
656
|
+
#
|
|
652
657
|
# Like any other {Element} sections support all {Features}.
|
|
653
658
|
#
|
|
654
|
-
# @
|
|
655
|
-
#
|
|
659
|
+
# @overload section#
|
|
660
|
+
# @example
|
|
661
|
+
# ui.section do |section|
|
|
662
|
+
# section.h1 'About Sections'
|
|
663
|
+
# section.space
|
|
664
|
+
# section.puts 'Sections are areas of text elements.'
|
|
665
|
+
# section.puts 'You can use any other feature inside such an area.'
|
|
666
|
+
# end
|
|
667
|
+
# # => ╭────╶╶╶
|
|
668
|
+
# # => │ ╴╶╴╶─═══ About Sections ═══─╴╶╴╶
|
|
669
|
+
# # => │
|
|
670
|
+
# # => │ Sections are areas of text elements.
|
|
671
|
+
# # => │ You can use any other feature inside such an area.
|
|
672
|
+
# # => ╰──── ─╶╶╶
|
|
673
|
+
#
|
|
674
|
+
# @yieldparam section [Section]
|
|
675
|
+
# itself
|
|
676
|
+
# @return [Object]
|
|
677
|
+
# the result of the given block
|
|
678
|
+
#
|
|
679
|
+
# @overload section(*text, **options)
|
|
680
|
+
#
|
|
681
|
+
# @example
|
|
682
|
+
# section = ui.section
|
|
656
683
|
# section.h1 'About Sections'
|
|
657
684
|
# section.space
|
|
658
685
|
# section.puts 'Sections are areas of text elements.'
|
|
659
|
-
# section.
|
|
660
|
-
# end
|
|
661
|
-
# # => ╭────╶╶╶
|
|
662
|
-
# # => │ ╴╶╴╶─═══ About Sections ═══─╴╶╴╶
|
|
663
|
-
# # => │
|
|
664
|
-
# # => │ Sections are areas of text elements.
|
|
665
|
-
# # => │ You can use any other feature inside such an area.
|
|
666
|
-
# # => ╰──── ─╶╶╶
|
|
667
|
-
#
|
|
668
|
-
# @param text [#to_s]
|
|
669
|
-
# convertible objects to print line by line
|
|
670
|
-
#
|
|
671
|
-
# @yieldparam section [Section]
|
|
672
|
-
# itself
|
|
686
|
+
# section.end # close the section
|
|
673
687
|
#
|
|
674
|
-
#
|
|
675
|
-
#
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
#
|
|
679
|
-
#
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
#
|
|
688
|
+
# @param text [*#to_s]
|
|
689
|
+
# optional objects to print line by line
|
|
690
|
+
# @param options [{Symbol => Object}]
|
|
691
|
+
# print options – see {puts}
|
|
692
|
+
# @return [Section]
|
|
693
|
+
# itself
|
|
694
|
+
def section(*text, **options, &block)
|
|
695
|
+
__sec(:default, false, nil, text, options, &block)
|
|
696
|
+
end
|
|
697
|
+
alias begin section
|
|
698
|
+
|
|
699
|
+
# @!macro msg_like
|
|
700
|
+
#
|
|
701
|
+
# Like any other {Element} sections support all {Features}.
|
|
702
|
+
#
|
|
703
|
+
# @overload $0(title)
|
|
704
|
+
# @param title [#to_s]
|
|
705
|
+
# section title
|
|
706
|
+
# @yieldparam message [Section]
|
|
707
|
+
# itself
|
|
708
|
+
# @return [Object]
|
|
709
|
+
# the result of the given block
|
|
710
|
+
# @overload $0(title, *text, **options)
|
|
711
|
+
# @param title [#to_s]
|
|
712
|
+
# section title
|
|
713
|
+
# @param text [*#to_s]
|
|
714
|
+
# optional objects to print line by line
|
|
715
|
+
# @param options [{Symbol => Object}]
|
|
716
|
+
# print options – see {puts}
|
|
717
|
+
# @return [Section]
|
|
718
|
+
# itself
|
|
719
|
+
|
|
720
|
+
# Create a visually separated section with title for the output of text
|
|
687
721
|
# elements.
|
|
688
|
-
#
|
|
689
|
-
|
|
690
|
-
|
|
722
|
+
# @macro msg_like
|
|
723
|
+
def message(title, *text, **options, &block)
|
|
724
|
+
__sec(:message, false, title, text, options, &block)
|
|
725
|
+
end
|
|
691
726
|
alias msg message
|
|
692
727
|
|
|
693
|
-
# Create a visually separated section marked as informational with
|
|
694
|
-
#
|
|
728
|
+
# Create a visually separated section marked as informational with title for
|
|
729
|
+
# the output of text elements.
|
|
695
730
|
#
|
|
696
|
-
# @macro
|
|
697
|
-
def information(title, *text, &block)
|
|
698
|
-
|
|
731
|
+
# @macro msg_like
|
|
732
|
+
def information(title, *text, **options, &block)
|
|
733
|
+
__sec(:information, true, title, text, options, &block)
|
|
699
734
|
end
|
|
700
735
|
alias info information
|
|
701
736
|
|
|
702
|
-
# Create a visually separated section marked as
|
|
737
|
+
# Create a visually separated section marked as warning with title for
|
|
703
738
|
# the output of text elements.
|
|
704
739
|
#
|
|
705
|
-
# @macro
|
|
706
|
-
def warning(title, *text,
|
|
740
|
+
# @macro msg_like
|
|
741
|
+
def warning(title, *text, **options, &block)
|
|
742
|
+
__sec(:warning, true, title, text, options, &block)
|
|
743
|
+
end
|
|
707
744
|
alias warn warning
|
|
708
745
|
|
|
709
|
-
# Create a visually separated section marked as
|
|
746
|
+
# Create a visually separated section marked as error with title for
|
|
710
747
|
# the output of text elements.
|
|
711
748
|
#
|
|
712
|
-
# @macro
|
|
713
|
-
def error(title, *text,
|
|
749
|
+
# @macro msg_like
|
|
750
|
+
def error(title, *text, **options, &block)
|
|
751
|
+
__sec(:error, true, title, text, options, &block)
|
|
752
|
+
end
|
|
714
753
|
alias err error
|
|
715
754
|
|
|
716
|
-
# Create a visually separated section marked as
|
|
755
|
+
# Create a visually separated section marked as failure with title for
|
|
717
756
|
# the output of text elements.
|
|
718
757
|
#
|
|
719
|
-
# @macro
|
|
720
|
-
def failed(title, *text,
|
|
758
|
+
# @macro msg_like
|
|
759
|
+
def failed(title, *text, **options, &block)
|
|
760
|
+
__sec(:failed, true, title, text, options, &block)
|
|
761
|
+
end
|
|
721
762
|
|
|
722
763
|
# Create a framed section.
|
|
764
|
+
# Like any other {Element} sections support all {Features}.
|
|
723
765
|
#
|
|
724
|
-
# @
|
|
725
|
-
#
|
|
726
|
-
#
|
|
727
|
-
#
|
|
728
|
-
#
|
|
729
|
-
#
|
|
730
|
-
#
|
|
731
|
-
#
|
|
732
|
-
#
|
|
733
|
-
#
|
|
734
|
-
#
|
|
735
|
-
#
|
|
736
|
-
#
|
|
737
|
-
# @
|
|
738
|
-
|
|
766
|
+
# @overload framed(align: :left, border: :default, border_style: nil)
|
|
767
|
+
# @param align [:left, :right, :centered]
|
|
768
|
+
# text alignment,
|
|
769
|
+
# see {Attributes::Align}
|
|
770
|
+
# @param border [Symbol]
|
|
771
|
+
# kind of border,
|
|
772
|
+
# see {Attributes::Border}
|
|
773
|
+
# @param border_style [Enumerable<Symbol>]
|
|
774
|
+
# style of border,
|
|
775
|
+
# see {Attributes::BorderStyle}
|
|
776
|
+
# @yieldparam framed [Element]
|
|
777
|
+
# itself
|
|
778
|
+
# @return [Object] the result of the given block
|
|
779
|
+
# @overload framed(*text, align: :left, border: :default, border_style: nil, **options)
|
|
780
|
+
# @param text [*#to_s]
|
|
781
|
+
# optional objects to print line by line
|
|
782
|
+
# @param align [:left, :right, :centered]
|
|
783
|
+
# text alignment,
|
|
784
|
+
# see {Attributes::Align}
|
|
785
|
+
# @param border [Symbol]
|
|
786
|
+
# kind of border,
|
|
787
|
+
# see {Attributes::Border}
|
|
788
|
+
# @param border_style [Enumerable<Symbol>]
|
|
789
|
+
# style of border,
|
|
790
|
+
# see {Attributes::BorderStyle}
|
|
791
|
+
# @param options [{Symbol => Object}]
|
|
792
|
+
# print options – see {puts}
|
|
793
|
+
# @return [Element] itself
|
|
794
|
+
def framed(
|
|
795
|
+
*text,
|
|
796
|
+
align: :left,
|
|
797
|
+
border: :default,
|
|
798
|
+
border_style: nil,
|
|
799
|
+
**options,
|
|
800
|
+
&block
|
|
801
|
+
)
|
|
739
802
|
__with(
|
|
740
803
|
Framed.new(
|
|
741
804
|
self,
|
|
742
805
|
Utils.align(align),
|
|
743
806
|
Theme.current.border(border),
|
|
744
|
-
Utils.style(border_style)
|
|
745
|
-
text
|
|
807
|
+
Utils.style(border_style)
|
|
746
808
|
),
|
|
809
|
+
*text,
|
|
810
|
+
**options,
|
|
747
811
|
&block
|
|
748
812
|
)
|
|
749
813
|
end
|
|
@@ -752,14 +816,17 @@ module NattyUI
|
|
|
752
816
|
#
|
|
753
817
|
# @param title [#to_s]
|
|
754
818
|
# task title text
|
|
755
|
-
# @param text
|
|
819
|
+
# @param text [*#to_s]
|
|
820
|
+
# optional objects to print line by line
|
|
756
821
|
# @param pin [true, false] whether to keep text "pinned"
|
|
822
|
+
# @param options [{Symbol => Object}]
|
|
823
|
+
# print options – see {puts}
|
|
757
824
|
#
|
|
758
825
|
# @yieldparam task [Task] itself
|
|
759
826
|
#
|
|
760
|
-
# @return
|
|
761
|
-
def task(title, *text, pin: false, &block)
|
|
762
|
-
__with(Task.new(self, title, text,
|
|
827
|
+
# @return [Task] itself
|
|
828
|
+
def task(title, *text, pin: false, **options, &block)
|
|
829
|
+
__with(Task.new(self, title, pin), *text, **options, &block)
|
|
763
830
|
end
|
|
764
831
|
|
|
765
832
|
#
|
|
@@ -972,9 +1039,18 @@ module NattyUI
|
|
|
972
1039
|
# Display some temporary content.
|
|
973
1040
|
# The content displayed in the block will be erased after the block ends.
|
|
974
1041
|
#
|
|
975
|
-
# @example
|
|
1042
|
+
# @example
|
|
1043
|
+
# ui.temporary(<<~MSG) { ui.await }
|
|
1044
|
+
# This is a [i]temporary[/i] displayed text.
|
|
1045
|
+
# It will disappear when you press [b]ENTER[/b].
|
|
1046
|
+
# MSG
|
|
1047
|
+
#
|
|
1048
|
+
# @example
|
|
976
1049
|
# ui.temporary do
|
|
977
|
-
# ui.
|
|
1050
|
+
# ui.information 'Hint' do
|
|
1051
|
+
# ui.puts 'This is a [i]temporary[/i] displayed text.'
|
|
1052
|
+
# ui.puts 'It will disappear when you press [b]ENTER[/b].'
|
|
1053
|
+
# end
|
|
978
1054
|
# ui.await
|
|
979
1055
|
# end
|
|
980
1056
|
#
|
|
@@ -982,7 +1058,9 @@ module NattyUI
|
|
|
982
1058
|
# itself
|
|
983
1059
|
#
|
|
984
1060
|
# @return (see section)
|
|
985
|
-
def temporary(
|
|
1061
|
+
def temporary(*text, **options, &block)
|
|
1062
|
+
__with(Temporary.new(self), *text, **options, &block)
|
|
1063
|
+
end
|
|
986
1064
|
|
|
987
1065
|
#
|
|
988
1066
|
# @!endgroup
|
|
@@ -990,14 +1068,15 @@ module NattyUI
|
|
|
990
1068
|
|
|
991
1069
|
private
|
|
992
1070
|
|
|
993
|
-
def __with(
|
|
1071
|
+
def __with(...) = NattyUI.__send__(:_with, ...)
|
|
994
1072
|
|
|
995
|
-
def __sec(color, title, text, &block)
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1073
|
+
def __sec(color, mark, title, text, options, &block)
|
|
1074
|
+
if title && !title.empty?
|
|
1075
|
+
title, *rest =
|
|
1076
|
+
Text.each_line(title, limit: columns - 9, ansi: Terminal.ansi?).to_a
|
|
1077
|
+
text.unshift(rest.join("\n")) unless rest.empty?
|
|
1078
|
+
end
|
|
1079
|
+
__with(Section.new(self, color, mark, title), *text, **options, &block)
|
|
1001
1080
|
end
|
|
1002
1081
|
|
|
1003
1082
|
def __await(yes, no)
|
|
@@ -1014,7 +1093,7 @@ module NattyUI
|
|
|
1014
1093
|
end
|
|
1015
1094
|
end
|
|
1016
1095
|
|
|
1017
|
-
dir = __dir__
|
|
1096
|
+
dir = __dir__
|
|
1018
1097
|
|
|
1019
1098
|
autoload :Framed, "#{dir}/framed.rb"
|
|
1020
1099
|
autoload :Section, "#{dir}/section.rb"
|
data/lib/natty-ui/framed.rb
CHANGED
|
@@ -29,7 +29,7 @@ module NattyUI
|
|
|
29
29
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
|
-
def initialize(parent, align, chars, style
|
|
32
|
+
def initialize(parent, align, chars, style)
|
|
33
33
|
super(parent)
|
|
34
34
|
@align = align
|
|
35
35
|
if style
|
|
@@ -45,7 +45,6 @@ module NattyUI
|
|
|
45
45
|
line = chars[10] * (parent.columns - 2)
|
|
46
46
|
parent.puts("#{style}#{chars[0]}#{line}#{chars[2]}")
|
|
47
47
|
@bottom = "#{style}#{chars[6]}#{line}#{chars[8]}"
|
|
48
|
-
puts(*msg) unless msg.empty?
|
|
49
48
|
end
|
|
50
49
|
end
|
|
51
50
|
end
|
data/lib/natty-ui/progress.rb
CHANGED
data/lib/natty-ui/section.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative 'element'
|
|
4
4
|
|
|
5
5
|
module NattyUI
|
|
6
|
-
# Display section used by
|
|
6
|
+
# Display section instance used by
|
|
7
7
|
#
|
|
8
8
|
# - {Features.section}
|
|
9
9
|
# - {Features.message}
|
|
@@ -11,6 +11,7 @@ module NattyUI
|
|
|
11
11
|
# - {Features.warning}
|
|
12
12
|
# - {Features.error}
|
|
13
13
|
# - {Features.failed}
|
|
14
|
+
# - {Features.framed}
|
|
14
15
|
#
|
|
15
16
|
class Section < Element
|
|
16
17
|
include WithStatus
|
|
@@ -42,25 +43,13 @@ module NattyUI
|
|
|
42
43
|
)
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
def initialize(parent,
|
|
46
|
+
def initialize(parent, kind, mark, title)
|
|
46
47
|
super(parent)
|
|
47
|
-
title, rest = split(title) if title && !title.empty?
|
|
48
48
|
@border = Theme.current.section_border(kind)
|
|
49
|
-
|
|
49
|
+
mark &&= Theme.current.mark(kind)
|
|
50
|
+
show_title(mark ? "#{mark}#{title}" : title)
|
|
50
51
|
@prefix = @border.prefix
|
|
51
52
|
@prefix_width = @prefix.width
|
|
52
|
-
puts(*rest) if rest && !rest.empty?
|
|
53
|
-
puts(*msg) unless msg.empty?
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def split(title)
|
|
57
|
-
rest =
|
|
58
|
-
Text.each_line(
|
|
59
|
-
title,
|
|
60
|
-
limit: @parent.columns - 9,
|
|
61
|
-
ansi: Terminal.ansi?
|
|
62
|
-
).to_a
|
|
63
|
-
[rest.shift, rest]
|
|
64
53
|
end
|
|
65
54
|
end
|
|
66
55
|
end
|
data/lib/natty-ui/task.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative 'element'
|
|
4
4
|
|
|
5
5
|
module NattyUI
|
|
6
|
-
# Task
|
|
6
|
+
# Task section used by {Features.task}.
|
|
7
7
|
#
|
|
8
8
|
class Task < Temporary
|
|
9
9
|
include WithStatus
|
|
@@ -27,7 +27,7 @@ module NattyUI
|
|
|
27
27
|
@start_line = nil
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def initialize(parent, title,
|
|
30
|
+
def initialize(parent, title, pin)
|
|
31
31
|
super(parent)
|
|
32
32
|
@title = title
|
|
33
33
|
@pin = pin
|
|
@@ -42,7 +42,6 @@ module NattyUI
|
|
|
42
42
|
prefix: "#{@prefix}#{style}",
|
|
43
43
|
prefix_width: cm.width
|
|
44
44
|
)
|
|
45
|
-
puts(*msg) unless msg.empty?
|
|
46
45
|
end
|
|
47
46
|
end
|
|
48
47
|
end
|
data/lib/natty-ui/version.rb
CHANGED
data/lib/natty-ui.rb
CHANGED
|
@@ -87,17 +87,33 @@ module NattyUI
|
|
|
87
87
|
|
|
88
88
|
private
|
|
89
89
|
|
|
90
|
-
def
|
|
90
|
+
def _begin(element)
|
|
91
91
|
Terminal.hide_cursor if @element == self
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
@stack << element
|
|
93
|
+
@element = element
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def _end(element)
|
|
97
|
+
idx = @stack.index(element) or return @element
|
|
98
|
+
@stack.drop(idx).each { _1.done if _1.respond_to?(:done) }
|
|
99
|
+
@stack = @stack.take(idx)
|
|
100
|
+
Terminal.show_cursor if (@element = @stack[-1]) == self
|
|
101
|
+
@element
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def _with(element, *text, **options, &block)
|
|
105
|
+
_begin(element)
|
|
106
|
+
element.puts(*text, **options) unless text.empty?
|
|
107
|
+
return element unless block
|
|
108
|
+
begin
|
|
109
|
+
yield(element)
|
|
110
|
+
ensure
|
|
111
|
+
_end(element)
|
|
112
|
+
end
|
|
97
113
|
end
|
|
98
114
|
end
|
|
99
115
|
|
|
100
|
-
@element = self
|
|
116
|
+
@stack = [@element = self]
|
|
101
117
|
@lines_written = 0
|
|
102
118
|
@title_stack = []
|
|
103
119
|
|
data/natty-ui.gemspec
CHANGED
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.metadata['yard.run'] = 'yard'
|
|
27
27
|
|
|
28
28
|
spec.required_ruby_version = '>= 3.0'
|
|
29
|
-
spec.add_dependency 'terminal_rb', '>= 0.17.
|
|
29
|
+
spec.add_dependency 'terminal_rb', '>= 0.17.2'
|
|
30
30
|
|
|
31
31
|
spec.files = Dir['lib/**/*.rb'] + Dir['examples/*.rb']
|
|
32
32
|
spec.files << 'natty-ui.gemspec' << '.yardopts'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: natty-ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.35.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Blumtritt
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.17.
|
|
18
|
+
version: 0.17.2
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.17.
|
|
25
|
+
version: 0.17.2
|
|
26
26
|
description: 'This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich,
|
|
27
27
|
lovely, natty user interface tool you like to have for your command line applications.
|
|
28
28
|
It contains elegant, simple and beautiful features that enhance your command line
|
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
103
103
|
- !ruby/object:Gem::Version
|
|
104
104
|
version: '0'
|
|
105
105
|
requirements: []
|
|
106
|
-
rubygems_version:
|
|
106
|
+
rubygems_version: 4.0.1
|
|
107
107
|
specification_version: 4
|
|
108
108
|
summary: This is the beautiful, nice, nifty, fancy, neat, pretty, cool, rich, lovely,
|
|
109
109
|
natty user interface you like to have for your CLI.
|