termline 0.2.0 → 1.0.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/lib/termline/list.rb +2 -11
- data/lib/termline/msg.rb +1 -2
- data/lib/termline/style.rb +1 -0
- data/lib/termline/table.rb +19 -22
- data/lib/termline/version.rb +2 -2
- data/lib/termline.rb +7 -17
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ffa74e98e74cd4e79135aab3703a664301edad3c1a68789547876b5ed523a25
|
|
4
|
+
data.tar.gz: e194b805ec6fee33f52cde37d15af6005bd27d0c876fabe6978a7f585e584e0d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8336beddc055905e84ad0cd98c77192d890990daac52cdfeb3f861c33b7cee177f85db496b293e5fd74dfcf934bb0e81a3314e583afeaee65cec58df389dea19
|
|
7
|
+
data.tar.gz: 91ab1b950cb4585c8fe257c92b12e06bc27b4b81ec191684f7b5865a0dc4feebdfcfd120f44cd75dad410b875a7322e06aaafff509db99f8bb927adb11ec54af
|
data/lib/termline/list.rb
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
module Termline
|
|
3
3
|
module List
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
items.each { |item| puts(" #{Config::ICONS[:bullet]} #{ item }" )}
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.check *items
|
|
10
|
-
items.each { |item| puts(" #{Config::ICONS[:checkmark]} #{ item }" )}
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.star *items
|
|
14
|
-
items.each { |item| puts(" #{Config::ICONS[:star]} #{ item }" )}
|
|
4
|
+
def self.builder(items, icon:, color:)
|
|
5
|
+
items.each { |item| puts(" #{Style.colorize(Style.icon(icon), color)} #{ item }" )}
|
|
15
6
|
end
|
|
16
7
|
end
|
|
17
8
|
end
|
data/lib/termline/msg.rb
CHANGED
|
@@ -7,10 +7,9 @@ module Termline
|
|
|
7
7
|
message,
|
|
8
8
|
tag: nil,
|
|
9
9
|
icon: nil,
|
|
10
|
-
data: nil,
|
|
11
10
|
color: :default,
|
|
12
11
|
bgcolor: :default,
|
|
13
|
-
timestamp: Time.now.strftime('%H:%M:%S:%L'))
|
|
12
|
+
timestamp: Time.now.strftime('%H:%M:%S:%L'), data:nil)
|
|
14
13
|
|
|
15
14
|
parts = []
|
|
16
15
|
parts << "[#{timestamp}]" if timestamp
|
data/lib/termline/style.rb
CHANGED
data/lib/termline/table.rb
CHANGED
|
@@ -6,22 +6,18 @@ module Termline
|
|
|
6
6
|
return if Gem.win_platform?
|
|
7
7
|
return unless data.size > 0
|
|
8
8
|
|
|
9
|
+
table_from_array = true if data.first.class == Array
|
|
10
|
+
header = false if table_from_array
|
|
11
|
+
|
|
9
12
|
if data.class.name == "ActiveRecord::Relation"
|
|
10
13
|
data = data.to_a.map(&:serializable_hash)
|
|
11
14
|
end
|
|
12
15
|
|
|
13
16
|
# get the available characters in terminal width
|
|
14
17
|
#terminal_width = `tput cols`.to_i
|
|
15
|
-
terminal_width =
|
|
18
|
+
terminal_width = Style::WIDTH
|
|
16
19
|
|
|
17
20
|
# get the number of columns to print base on the data hash
|
|
18
|
-
|
|
19
|
-
pp "--------------------------"
|
|
20
|
-
pp "--------------------------"
|
|
21
|
-
header = false if data.first.class == Array
|
|
22
|
-
pp "--------------------------"
|
|
23
|
-
pp "--------------------------"
|
|
24
|
-
|
|
25
21
|
cols = data.first.length + 1
|
|
26
22
|
|
|
27
23
|
# get the available space for every column
|
|
@@ -35,27 +31,28 @@ module Termline
|
|
|
35
31
|
|
|
36
32
|
# add extra blank spaces to adjust the col_width only if col_width not a even number
|
|
37
33
|
separator += (' ') if (col_width - separator.size).odd?
|
|
38
|
-
|
|
39
|
-
# print data as table :)
|
|
40
|
-
data.each_with_index do |row, index|
|
|
41
34
|
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
# only for table header
|
|
36
|
+
if header
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
# print table titles
|
|
39
|
+
puts '| ' << data.first.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
|
|
40
|
+
end
|
|
47
41
|
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
# print header separators, only for visible columns
|
|
43
|
+
puts separator * (cols - 1)
|
|
50
44
|
|
|
51
|
-
|
|
45
|
+
# print data as table :)
|
|
46
|
+
data.each_with_index do |row, index|
|
|
52
47
|
|
|
53
|
-
# join hash values as a line and justify every value to print value
|
|
54
|
-
|
|
55
|
-
puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ')
|
|
56
|
-
#puts '| ' << row.map { |value| value.to_s.ljust(col_width) }.join('| ')
|
|
48
|
+
# join hash values as a line and justify every value to print value in its own column
|
|
49
|
+
puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ') unless table_from_array
|
|
57
50
|
|
|
51
|
+
# print simple value from the array data
|
|
52
|
+
puts '| ' << row.map { |value| value.to_s.ljust(col_width) }.join('| ') if table_from_array
|
|
58
53
|
end
|
|
54
|
+
|
|
55
|
+
puts separator * (cols - 1) unless header
|
|
59
56
|
end
|
|
60
57
|
end
|
|
61
58
|
end
|
data/lib/termline/version.rb
CHANGED
data/lib/termline.rb
CHANGED
|
@@ -45,23 +45,23 @@ module Termline
|
|
|
45
45
|
messages.each { |message| puts(message) }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
def self.msg (*messages, data
|
|
48
|
+
def self.msg (*messages, **data)
|
|
49
49
|
messages.each { |message| Termline::Msg.builder(message, data:data) }
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
def self.info *messages, tag:'INFO:', icon: :info, data
|
|
52
|
+
def self.info *messages, tag:'INFO:', icon: :info, **data
|
|
53
53
|
messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :blue) }
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
def self.success *messages, tag:'SUCCESS:', icon: :success, data
|
|
56
|
+
def self.success *messages, tag:'SUCCESS:', icon: :success, **data
|
|
57
57
|
messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :green) }
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def self.warning *messages, tag:'WARNING:', icon: :warning, data
|
|
60
|
+
def self.warning *messages, tag:'WARNING:', icon: :warning, **data
|
|
61
61
|
messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :yellow) }
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def self.danger *messages, tag:'DANGER:', icon: :error, data
|
|
64
|
+
def self.danger *messages, tag:'DANGER:', icon: :error, **data
|
|
65
65
|
messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :red) }
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -70,18 +70,8 @@ module Termline
|
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
def self.list *items
|
|
76
|
-
Termline::List.bullet(items)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.list_check *items
|
|
80
|
-
Termline::List.check(items)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def self.list_star *items
|
|
84
|
-
Termline::List.star(items)
|
|
73
|
+
def self.list *items, color: :default, icon: :debug
|
|
74
|
+
Termline::List.builder(items, color:color, icon:icon)
|
|
85
75
|
end
|
|
86
76
|
|
|
87
77
|
|