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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31c52f81fd0fe02b29f7a294cf7fae93e3cb008b2cdb1e34169f06fbf367d638
4
- data.tar.gz: 8a810a992c7be490f7eea90172bc480d0e078af072b633520dc8c1c75dce3392
3
+ metadata.gz: 9ffa74e98e74cd4e79135aab3703a664301edad3c1a68789547876b5ed523a25
4
+ data.tar.gz: e194b805ec6fee33f52cde37d15af6005bd27d0c876fabe6978a7f585e584e0d
5
5
  SHA512:
6
- metadata.gz: 06ca46dd65fcf1a262568be376a160b9a0ea96d32f8db952d066fe0af71061ffd21342de906f79dfcc53c7f88837e56c1d75547e6b5754b6656b5dfaa4e6cb9c
7
- data.tar.gz: aa14be84ef383c11cdfea7571a73b0b2354d39a13d694ca170f03d280efed502f99267148f5e60ea69cc073caf910d1af5cf1e123b9045979e275c8a7c2b9bf2
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
- def self.bullet *items
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
@@ -21,6 +21,7 @@ module Termline
21
21
  white: '1;37',
22
22
  green: '32',
23
23
  black: '30',
24
+ gray: '90',
24
25
  blue: '36',
25
26
  red: '31'
26
27
  }.freeze
@@ -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 = Config::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
- # only for table header
43
- if index == 0 && header
35
+ # only for table header
36
+ if header
44
37
 
45
- # print table titles
46
- puts '| ' << row.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
38
+ # print table titles
39
+ puts '| ' << data.first.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
40
+ end
47
41
 
48
- # print header separators, only for visible columns
49
- puts separator * (cols - 1)
42
+ # print header separators, only for visible columns
43
+ puts separator * (cols - 1)
50
44
 
51
- end
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
- # in its own column
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
@@ -30,6 +30,6 @@ Building a better future, one line of code at a time.
30
30
  =end
31
31
 
32
32
  module Termline
33
- VERSION = "0.2.0"
34
- BUILD = "1774211535"
33
+ VERSION = "1.0.0"
34
+ BUILD = "1774219112"
35
35
  end
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:nil)
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:nil
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:nil
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:nil
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:nil
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Lesli Development Team