lit-cli 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config.rb +14 -5
  3. data/lib/lit_cli.rb +87 -27
  4. data/lib/lit_pry.rb +2 -0
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ed5d7713a6943b0043bf26568c069dc4c0a647a8581dc48d7a88c05abb3b5de
4
- data.tar.gz: 53c911d1424038fa5bb836dfc68f739514d53a62b91ed813dc506078d4c5742d
3
+ metadata.gz: 0d016a1786059f76f691d0dd55ab4a8d2e408f4b2ee5bca3d8e42ea29012d379
4
+ data.tar.gz: 5f0756f25977560051e7b07b86ae795584e954fa14eeb4533f56505c60d9cdfd
5
5
  SHA512:
6
- metadata.gz: e75aab70ca6f9aac9258b68f289ca7efdaf24d8328030a7195c91e24ecd7828eaf32d42d7cee87acc6b1d188d2ef692969cc402055b1a98ed71bc5a0edf4632e
7
- data.tar.gz: 0f88b27bcb0308d93b8e7ba223a91a11125faf4c29fdb600e3ff77a18a1526c1be51f5dc4c60e276f5b2a0aca2e91577a92e8f4ef85b6e6c233d80cab8c0a2c3
6
+ metadata.gz: b902f2d26e1b868be3026783a2f99e10a34ca1be0851cd73b5c16c2a4ef23fad146b5f9f51ddaca41975b249833c6f382cd47468f21ef6c2ecfa1638a9a2382e
7
+ data.tar.gz: 01c08ebe1937ed4d31240aed5bcda06c4d5f85b9d6c28c23ca21b939e547e6267fc7e6248d7f3d14972bd5e9b1ea27dc74df5c38fd3d39f2aaa0a09e5340fef2
data/lib/config.rb CHANGED
@@ -22,14 +22,17 @@ module LitCLI
22
22
  @@errors = Set.new
23
23
 
24
24
  attr_accessor :enabled
25
+ attr_accessor :statuses
25
26
  attr_accessor :types
26
- attr_accessor :type
27
+ # Flags.
27
28
  attr_accessor :step
29
+ attr_accessor :status
30
+ attr_accessor :type
28
31
  attr_accessor :delay
29
32
 
30
33
  def initialize()
31
34
 
32
- @types = {
35
+ @statuses = {
33
36
  :info => { icon: "ℹ", color: :blue },
34
37
  :pass => { icon: "✔", color: :green },
35
38
  :warn => { icon: "⚠", color: :yellow },
@@ -38,6 +41,8 @@ module LitCLI
38
41
  :debug => { icon: "?", color: :purple },
39
42
  }
40
43
 
44
+ @types = nil
45
+
41
46
  # Lit is disabled by default, then enabled via the `lit` command.
42
47
  # Or it can be permanently enabled, without the use of the `lit` command.
43
48
  @enabled = false
@@ -48,12 +53,15 @@ module LitCLI
48
53
  # Flag defaults when not supplied via command line.
49
54
  ##
50
55
 
51
- # Array of types to filter by, for example... [:warn, :error, :fail]
52
- @type = nil
53
-
54
56
  # Boolean on whether or not to step through each lit() breakpoint.
55
57
  @step = false
56
58
 
59
+ # Array of statuses to filter by, for example: [:warn, :error, :fail]
60
+ @status = nil
61
+
62
+ # Array of types to filter by, for example: [:cat, :dog, :tree]
63
+ @type = nil
64
+
57
65
  # Integer or float representing amount of seconds to delay each lit() by.
58
66
  @delay = 0
59
67
 
@@ -89,6 +97,7 @@ module LitCLI
89
97
  end
90
98
 
91
99
  @step = true if flags.has_key? :step
100
+ @status = Array(flags[:status]).map(&:to_sym) if valid? flags, :status
92
101
  @type = Array(flags[:type]).map(&:to_sym) if valid? flags, :type
93
102
  @delay = flags[:delay].to_f if valid? flags, :delay
94
103
  end
data/lib/lit_cli.rb CHANGED
@@ -8,26 +8,42 @@ module LitCLI
8
8
  @@config = Config.new
9
9
  @@is_prying = false
10
10
 
11
- def lit(message, type = :info)
11
+ def lit(message, status = :info, type = nil)
12
12
  if @@config.enabled
13
- return if LitCLI.filter? type
14
- LitCLI.render(type)
13
+ return if LitCLI.filter_status? status
14
+ return if LitCLI.filter_type? type
15
+ LitCLI.render(message, status, type)
15
16
  LitCLI.step()
16
17
  LitCLI.delay()
17
18
  end
18
19
  end
19
20
  alias 🔥 lit
20
21
 
21
- def self.render(type)
22
- type_config = @@config.types[type]
22
+ def self.render(message, status, type)
23
+ text = "🔥"
23
24
 
24
- time_text = LitCLI.colorize(Time.now().strftime("%k:%M"), :cyan)
25
- type_text = type_config[:icon] + " " + type.to_s
26
- type_text_color = LitCLI.colorize(type_text, type_config[:color])
25
+ # Time.
26
+ time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
27
+ text << " #{time}"
27
28
 
28
- message = "🔥 #{time_text} #{type_text_color} #{message}"
29
+ # Status.
30
+ config = @@config.statuses[status]
31
+ text << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
29
32
 
30
- puts message
33
+ # Type.
34
+ if !@@config.types.nil? && @@config.types.has_key?(type)
35
+ config = @@config.types[type]
36
+ if config.has_key? :icon
37
+ text << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
38
+ else
39
+ text << LitCLI.format(" #{type.to_s}", config)
40
+ end
41
+ end
42
+
43
+ # Message.
44
+ text << " #{message}"
45
+
46
+ puts text
31
47
  end
32
48
 
33
49
  def self.step()
@@ -39,7 +55,15 @@ module LitCLI
39
55
  end
40
56
  end
41
57
 
42
- def self.filter? type
58
+ def self.filter_status? status
59
+ unless @@config.status.nil? || @@config.status.include?(status)
60
+ return true
61
+ end
62
+
63
+ false
64
+ end
65
+
66
+ def self.filter_type? type
43
67
  unless @@config.type.nil? || @@config.type.include?(type)
44
68
  return true
45
69
  end
@@ -57,23 +81,59 @@ module LitCLI
57
81
  @@config.step && @@is_prying
58
82
  end
59
83
 
60
- def self.colorize(text, color)
61
- case color
62
- when :blue
63
- return @@pastel.bright_blue(text)
64
- when :green
65
- return @@pastel.green(text)
66
- when :yellow
67
- return @@pastel.yellow(text)
68
- when :red
69
- return @@pastel.red(text)
70
- when :purple, :magenta
71
- return @@pastel.magenta(text)
72
- when :cyan
73
- return @@pastel.cyan(text)
74
- else
75
- return text
84
+ def self.format(text, config)
85
+
86
+ if config.has_key? :styles
87
+ # Change characters first.
88
+ config[:styles].each do |style|
89
+ case style
90
+ when :upcase
91
+ text = text.upcase
92
+ when :downcase
93
+ text = text.downcase
94
+ end
95
+ end
96
+ # Then apply styling.
97
+ config[:styles].each do |style|
98
+ case style
99
+ when :clear
100
+ text = @@pastel.clear(text)
101
+ when :bold
102
+ text = @@pastel.bold(text)
103
+ when :dim
104
+ text = @@pastel.dim(text)
105
+ when :italic
106
+ text = @@pastel.italic(text)
107
+ when :underline
108
+ text = @@pastel.underline(text)
109
+ when :inverse
110
+ text = @@pastel.inverse(text)
111
+ when :hidden
112
+ text = @@pastel.hidden(text)
113
+ when :strike, :strikethrough
114
+ text = @@pastel.strikethrough(text)
115
+ end
116
+ end
76
117
  end
118
+
119
+ if config.has_key? :color
120
+ case config[:color]
121
+ when :blue
122
+ text = @@pastel.bright_blue(text)
123
+ when :green
124
+ text = @@pastel.green(text)
125
+ when :yellow
126
+ text = @@pastel.yellow(text)
127
+ when :red
128
+ text = @@pastel.red(text)
129
+ when :purple, :magenta
130
+ text = @@pastel.magenta(text)
131
+ when :cyan
132
+ text = @@pastel.cyan(text)
133
+ end
134
+ end
135
+
136
+ text
77
137
  end
78
138
 
79
139
  # Override config from application.
data/lib/lit_pry.rb CHANGED
@@ -41,6 +41,8 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
41
41
  end
42
42
 
43
43
  # TODO: Investigate RubyGems `require` before overriding.
44
+ # SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
45
+ #
44
46
  # def require path
45
47
  # absolute_path = File.join(Dir.pwd, path)
46
48
  # #p "requiring #{absolute_path}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lit-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel