termline 1.1.2 → 1.1.3
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/lib/termline/details.rb +62 -0
- data/lib/termline/list.rb +20 -2
- data/lib/termline/msg.rb +20 -8
- data/lib/termline/space.rb +23 -8
- data/lib/termline/style.rb +21 -27
- data/lib/termline/table.rb +156 -34
- data/lib/termline/terminal.rb +82 -0
- data/lib/termline/text.rb +49 -0
- data/lib/termline/version.rb +2 -2
- data/lib/termline.rb +117 -20
- data/license.txt +674 -0
- data/readme.md +266 -31
- data/todo.md +52 -0
- metadata +12 -4
data/lib/termline.rb
CHANGED
|
@@ -32,68 +32,165 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
# ·
|
|
35
|
+
require_relative "termline/version"
|
|
36
|
+
require_relative "termline/terminal"
|
|
35
37
|
require_relative "termline/style"
|
|
36
38
|
require_relative "termline/table"
|
|
37
39
|
require_relative "termline/space"
|
|
38
40
|
require_relative "termline/list"
|
|
39
41
|
require_relative "termline/msg"
|
|
42
|
+
require_relative "termline/text"
|
|
43
|
+
require_relative "termline/details"
|
|
40
44
|
|
|
41
45
|
|
|
42
46
|
# ·
|
|
43
47
|
module Termline
|
|
44
48
|
class << self
|
|
49
|
+
def terminal
|
|
50
|
+
@terminal ||= Termline::Terminal.new
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def output
|
|
54
|
+
terminal.output
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def output=(io)
|
|
58
|
+
terminal.output = io
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def ansi
|
|
62
|
+
terminal.ansi
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def ansi=(mode)
|
|
66
|
+
terminal.ansi = mode
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def width
|
|
70
|
+
terminal.width
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def width=(value)
|
|
74
|
+
terminal.width = value
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def timestamps
|
|
78
|
+
@timestamps.nil? ? true : @timestamps
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
alias timestamps? timestamps
|
|
82
|
+
|
|
83
|
+
def timestamps=(value)
|
|
84
|
+
unless value == true || value == false
|
|
85
|
+
raise ArgumentError, "Timestamps must be true or false"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
@timestamps = value
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def timestamp_format
|
|
92
|
+
@timestamp_format || "%H:%M:%S:%L"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def timestamp_format=(format)
|
|
96
|
+
unless format.is_a?(String) && !format.empty?
|
|
97
|
+
raise ArgumentError, "Timestamp format must be a non-empty string"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
@timestamp_format = format
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def configure
|
|
104
|
+
yield self
|
|
105
|
+
self
|
|
106
|
+
end
|
|
107
|
+
|
|
45
108
|
def m(*messages)
|
|
46
|
-
messages.
|
|
109
|
+
write(messages.map(&:to_s).join("\n"))
|
|
47
110
|
end
|
|
48
111
|
|
|
49
|
-
def msg(*messages, **data)
|
|
50
|
-
messages.
|
|
112
|
+
def msg(*messages, time:nil, bgcolor: :default, **data)
|
|
113
|
+
write(messages.map { |message| Termline::Msg.builder(message, bgcolor:bgcolor, data:data, time:time) }.join("\n"))
|
|
51
114
|
end
|
|
52
115
|
|
|
53
|
-
def info(*messages, tag:'INFO:', icon: :info, time:
|
|
54
|
-
messages.
|
|
116
|
+
def info(*messages, tag:'INFO:', icon: :info, time:nil, bgcolor: :default, **data)
|
|
117
|
+
write(messages.map { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :blue, bgcolor:bgcolor, time:time) }.join("\n"))
|
|
55
118
|
end
|
|
56
119
|
|
|
57
|
-
def success(*messages, tag:'SUCCESS:', icon: :success, time:
|
|
58
|
-
messages.
|
|
120
|
+
def success(*messages, tag:'SUCCESS:', icon: :success, time:nil, bgcolor: :default, **data)
|
|
121
|
+
write(messages.map { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :green, bgcolor:bgcolor, time:time) }.join("\n"))
|
|
59
122
|
end
|
|
60
123
|
|
|
61
|
-
def warning(*messages, tag:'WARNING:', icon: :warning, time:
|
|
62
|
-
messages.
|
|
124
|
+
def warning(*messages, tag:'WARNING:', icon: :warning, time:nil, bgcolor: :default, **data)
|
|
125
|
+
write(messages.map { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :yellow, bgcolor:bgcolor, time:time) }.join("\n"))
|
|
63
126
|
end
|
|
64
127
|
|
|
65
|
-
def danger(*messages, tag:'DANGER:', icon: :error, time:
|
|
66
|
-
messages.
|
|
128
|
+
def danger(*messages, tag:'DANGER:', icon: :error, time:nil, bgcolor: :default, **data)
|
|
129
|
+
write(messages.map { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :red, bgcolor:bgcolor, time:time) }.join("\n"))
|
|
67
130
|
end
|
|
68
131
|
|
|
69
132
|
def alert(*messages)
|
|
70
|
-
messages.
|
|
133
|
+
write(messages.map { |message| Termline::Msg.alert(message) }.join("\n"))
|
|
71
134
|
end
|
|
72
135
|
|
|
73
136
|
|
|
74
137
|
def list(*items, color: :default, icon: :debug)
|
|
75
|
-
Termline::List.builder(items, color:color, icon:icon)
|
|
138
|
+
write(Termline::List.builder(items, color:color, icon:icon))
|
|
76
139
|
end
|
|
77
140
|
|
|
141
|
+
def ordered_list(*items, color: :default, start: 1)
|
|
142
|
+
write(Termline::List.builder(items, color:color, ordered:true, start:start))
|
|
143
|
+
end
|
|
78
144
|
|
|
79
|
-
def table(data, header:true)
|
|
80
|
-
Termline::Table.builder(data, header:header)
|
|
145
|
+
def table(data, header:true, align: :auto)
|
|
146
|
+
write(Termline::Table.builder(data, header:header, align:align))
|
|
81
147
|
end
|
|
82
148
|
|
|
83
149
|
def br(count=1)
|
|
84
|
-
|
|
150
|
+
write(Termline::Space.builder("\n", count))
|
|
85
151
|
end
|
|
86
152
|
|
|
87
|
-
def line(count=
|
|
88
|
-
|
|
153
|
+
def line(count=nil, character: "─", width: nil)
|
|
154
|
+
content = if count
|
|
155
|
+
Termline::Space.builder('-·- ', count)
|
|
156
|
+
else
|
|
157
|
+
Termline::Space.line(character, width || terminal.width)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
write(content)
|
|
89
161
|
end
|
|
90
162
|
|
|
91
163
|
def color(color)
|
|
92
|
-
Termline::Space.color(
|
|
164
|
+
write(Termline::Space.color(color))
|
|
93
165
|
end
|
|
94
166
|
|
|
95
167
|
|
|
96
|
-
def
|
|
168
|
+
def title(text, color: :blue, character: "─", width: nil)
|
|
169
|
+
write(Termline::Text.title(text, color:color, character:character, width:width || terminal.width))
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def details(data=nil, color: :blue, separator: ": ", icon: nil, icons: nil, **pairs)
|
|
173
|
+
write(Termline::Details.builder(
|
|
174
|
+
data,
|
|
175
|
+
color:color,
|
|
176
|
+
separator:separator,
|
|
177
|
+
icon:icon,
|
|
178
|
+
icons:icons,
|
|
179
|
+
**pairs
|
|
180
|
+
))
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def deprecation(*messages, time:nil, **data)
|
|
184
|
+
warning(*messages, tag: 'DEPRECATED:', time:time, **data)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
private
|
|
188
|
+
|
|
189
|
+
def write(content)
|
|
190
|
+
return content if content.nil? || content.empty?
|
|
191
|
+
|
|
192
|
+
output.puts(content)
|
|
193
|
+
content
|
|
97
194
|
end
|
|
98
195
|
end
|
|
99
196
|
end
|