output_mode 1.7.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/demo +22 -22
- data/lib/output_mode/formatter.rb +14 -17
- data/lib/output_mode/formatters/index.rb +1 -1
- data/lib/output_mode/formatters/show.rb +1 -1
- data/lib/output_mode/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e8e7233d045c7642d64d90ac04d0af8561ce06f1fb24125f4a849ce5cbf40c6
|
4
|
+
data.tar.gz: acba4cceeb3626e5350f637fa6d3422115622e1e5ef2cde3dbb5186b6df20173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8faf122204eb774c31e5feefdd68cab98f12817b04a904e5c1270dc9cd95496ef0585494a48f7a4ff93050ed41607dc0bb50aab9ba2c3513e8335bd426165df9
|
7
|
+
data.tar.gz: a460316ed1272d74ba1b8a398c9d8b197cdfa9d1682304648ad04534cb52437b0bbbe48d9eb308412e143898ff58ed4530201cac19bdba56a5dbbd9299bfb790
|
data/bin/demo
CHANGED
@@ -30,7 +30,7 @@ require "output_mode"
|
|
30
30
|
require 'erb'
|
31
31
|
|
32
32
|
class DemoIndex < OutputMode::Formatters::Index
|
33
|
-
|
33
|
+
def register_all
|
34
34
|
register(header: 'Integer', row_color: [:yellow, :bold]) { |i| i }
|
35
35
|
register(header: 'Standard', header_color: [:strikethrough] ) { 'always visible' }
|
36
36
|
if verbose?
|
@@ -38,10 +38,10 @@ class DemoIndex < OutputMode::Formatters::Index
|
|
38
38
|
else
|
39
39
|
register(header: 'Simplified') { 'simplified visible' }
|
40
40
|
end
|
41
|
-
if
|
42
|
-
register(header: '
|
41
|
+
if humanize?
|
42
|
+
register(header: 'humanize') { 'humanize visible' }
|
43
43
|
else
|
44
|
-
register(header: 'Non
|
44
|
+
register(header: 'Non humanize') { 'non-humanize visible' }
|
45
45
|
end
|
46
46
|
register(header: 'Yes/True') { true }
|
47
47
|
register(header: 'No/False', row_color: [:clear]) { false }
|
@@ -50,7 +50,7 @@ class DemoIndex < OutputMode::Formatters::Index
|
|
50
50
|
end
|
51
51
|
|
52
52
|
class DemoShow < OutputMode::Formatters::Show
|
53
|
-
|
53
|
+
def register_all
|
54
54
|
register(header: 'Integer') { |i| i }
|
55
55
|
register(header: 'Standard') { 'always visible' }
|
56
56
|
if verbose?
|
@@ -58,10 +58,10 @@ class DemoShow < OutputMode::Formatters::Show
|
|
58
58
|
else
|
59
59
|
register(header: 'Simplified') { 'simplified visible' }
|
60
60
|
end
|
61
|
-
if
|
62
|
-
register(header: '
|
61
|
+
if humanize?
|
62
|
+
register(header: 'humanize') { 'humanize visible' }
|
63
63
|
else
|
64
|
-
register(header: 'Non
|
64
|
+
register(header: 'Non humanize') { 'non-humanize visible' }
|
65
65
|
end
|
66
66
|
register(header: 'Yes/True', section: :boolean) { true }
|
67
67
|
register(header: 'No/False', section: :boolean) { false }
|
@@ -82,7 +82,7 @@ puts <<~EOF
|
|
82
82
|
|
83
83
|
#==============================================================================
|
84
84
|
# Default Demo Index
|
85
|
-
# Simplified in
|
85
|
+
# Simplified in humanize shells, verbose in non-humanize
|
86
86
|
#==============================================================================
|
87
87
|
#{DemoIndex.render(*data)}
|
88
88
|
|
@@ -97,16 +97,16 @@ puts <<~EOF
|
|
97
97
|
#{DemoIndex.render(*data, verbose: false)}
|
98
98
|
|
99
99
|
#==============================================================================
|
100
|
-
# Force
|
101
|
-
# Always print as if the shell is
|
100
|
+
# Force humanize
|
101
|
+
# Always print as if the shell is humanize
|
102
102
|
#==============================================================================
|
103
|
-
#{DemoIndex.render(*data,
|
103
|
+
#{DemoIndex.render(*data, humanize: true)}
|
104
104
|
|
105
105
|
#==============================================================================
|
106
|
-
# Force Non-
|
107
|
-
# Always print as if the shell is non-
|
106
|
+
# Force Non-humanize
|
107
|
+
# Always print as if the shell is non-humanize
|
108
108
|
#==============================================================================
|
109
|
-
#{DemoIndex.render(*data,
|
109
|
+
#{DemoIndex.render(*data, humanize: false)}
|
110
110
|
|
111
111
|
#==============================================================================
|
112
112
|
# Demo ASCII Index
|
@@ -121,7 +121,7 @@ puts <<~EOF
|
|
121
121
|
|
122
122
|
#==============================================================================
|
123
123
|
# Default Settings
|
124
|
-
# Simplified in
|
124
|
+
# Simplified in humanize shells, verbose in non-humanize
|
125
125
|
#==============================================================================
|
126
126
|
#{DemoShow.render(data.first)}
|
127
127
|
|
@@ -136,16 +136,16 @@ puts <<~EOF
|
|
136
136
|
#{DemoShow.render(data.first, verbose: false)}
|
137
137
|
|
138
138
|
#==============================================================================
|
139
|
-
# Force
|
140
|
-
# Always print as if the shell is
|
139
|
+
# Force humanize
|
140
|
+
# Always print as if the shell is humanize
|
141
141
|
#==============================================================================
|
142
|
-
#{DemoShow.render(data.first,
|
142
|
+
#{DemoShow.render(data.first, humanize: true)}
|
143
143
|
|
144
144
|
#==============================================================================
|
145
|
-
# Force Non-
|
146
|
-
# Always print as if the shell is non-
|
145
|
+
# Force Non-humanize
|
146
|
+
# Always print as if the shell is non-humanize
|
147
147
|
#==============================================================================
|
148
|
-
#{DemoShow.render(data.first,
|
148
|
+
#{DemoShow.render(data.first, humanize: false)}
|
149
149
|
|
150
150
|
#==============================================================================
|
151
151
|
# Demo ASCII Index
|
@@ -28,25 +28,18 @@ require 'tty-color'
|
|
28
28
|
|
29
29
|
module OutputMode
|
30
30
|
class Formatter
|
31
|
-
def self.constructor(&block)
|
32
|
-
@constructor ||= block
|
33
|
-
end
|
34
|
-
|
35
31
|
def self.build(*objects, **opts)
|
36
|
-
new(*objects, **opts).tap
|
37
|
-
next unless constructor
|
38
|
-
policy.instance_exec(&constructor)
|
39
|
-
end
|
32
|
+
new(*objects, **opts).tap(&:register_all)
|
40
33
|
end
|
41
34
|
|
42
35
|
def self.render(*objects, **opts)
|
43
36
|
build(*objects, **opts).render
|
44
37
|
end
|
45
38
|
|
46
|
-
def initialize(*objects, verbose: nil, ascii: nil,
|
39
|
+
def initialize(*objects, verbose: nil, ascii: nil, humanize: nil, color: nil)
|
47
40
|
@verbose = verbose
|
48
41
|
@ascii = ascii
|
49
|
-
@
|
42
|
+
@humanize = humanize
|
50
43
|
@color = color
|
51
44
|
|
52
45
|
# NOTE: This is intentionally not exposed on the base class
|
@@ -54,6 +47,10 @@ module OutputMode
|
|
54
47
|
@objects = objects
|
55
48
|
end
|
56
49
|
|
50
|
+
# Override in sub-classes to define the attributes
|
51
|
+
def register_all
|
52
|
+
end
|
53
|
+
|
57
54
|
def callables
|
58
55
|
@callables ||= Callables.new
|
59
56
|
end
|
@@ -89,16 +86,16 @@ module OutputMode
|
|
89
86
|
build_output.render(*@objects)
|
90
87
|
end
|
91
88
|
|
92
|
-
def
|
93
|
-
if @
|
89
|
+
def humanize?
|
90
|
+
if @humanize.nil?
|
94
91
|
$stdout.tty?
|
95
92
|
else
|
96
|
-
@
|
93
|
+
@humanize
|
97
94
|
end
|
98
95
|
end
|
99
96
|
|
100
97
|
def color?
|
101
|
-
if @color.nil? && (ascii? || !
|
98
|
+
if @color.nil? && (ascii? || !humanize?)
|
102
99
|
false
|
103
100
|
elsif @color.nil?
|
104
101
|
TTY::Color.color?
|
@@ -109,7 +106,7 @@ module OutputMode
|
|
109
106
|
|
110
107
|
def ascii?
|
111
108
|
if @ascii.nil?
|
112
|
-
!
|
109
|
+
!humanize?
|
113
110
|
else
|
114
111
|
@ascii
|
115
112
|
end
|
@@ -117,7 +114,7 @@ module OutputMode
|
|
117
114
|
|
118
115
|
def verbose?
|
119
116
|
if @verbose.nil?
|
120
|
-
!
|
117
|
+
!humanize?
|
121
118
|
else
|
122
119
|
@verbose
|
123
120
|
end
|
@@ -135,7 +132,7 @@ module OutputMode
|
|
135
132
|
|
136
133
|
def default(value = nil)
|
137
134
|
@default = value unless value.nil?
|
138
|
-
@default ? @default : (
|
135
|
+
@default ? @default : (humanize? ? '(none)' : '')
|
139
136
|
end
|
140
137
|
|
141
138
|
def time(value = nil)
|
@@ -43,7 +43,7 @@ module OutputMode
|
|
43
43
|
|
44
44
|
def template(value = nil)
|
45
45
|
@template = value unless value.nil?
|
46
|
-
@template ? @template : (
|
46
|
+
@template ? @template : (humanize? ? DEFAULT_ERB : NON_INTERACTIVE_ERB)
|
47
47
|
end
|
48
48
|
|
49
49
|
def scope(value = nil)
|
data/lib/output_mode/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: output_mode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William McCumsite
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-table
|