spoom 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c138290b530402f788fd25c8238340609f68e370cdfce7166f82f910f6352125
4
- data.tar.gz: '08595ccc6f1485d1b935c98a318daf9de6475d2fbcc742efafd955679e372cd3'
3
+ metadata.gz: 526b44a6bb1b2ec6b8b09a3bec42264f86b2803c561c4862d622c374893d529a
4
+ data.tar.gz: ac616a998a9800706ca28d805d5e975b35e78fb4c0b725463938b4b925f24728
5
5
  SHA512:
6
- metadata.gz: 8617496b57ade807623ef5cad109d20ff1024c8b6125c6286092859c69aab3e34f2a367fcb3ed531f425425af41cbc04492c0fd098f6e42170a9edf4bb41d120
7
- data.tar.gz: b8040df444748a8769739caf0699d784ffcc4518e1a55c152d72f2073ae5a62d08ef02085aaa8808eb48c078baba7655e3880700ca8fb0b79830a52d66f95c7d
6
+ metadata.gz: c6cf08eb1fe7d880e8dfae54352d554b83c41ff6878546b84d986fdbb17fa95244b1630f31aa0f1ccd14ef843dc71d80bd3236715d16165c7c1a0a6fc7271502
7
+ data.tar.gz: ea376f188b1a33a83784f4e7923ba4087cd2891f10deacf998b145c724f586f76e2cfda338011f50d7990b8b860720eb832f365c5a6541042453d3381e45c871
@@ -10,7 +10,8 @@ module Spoom
10
10
  module Helper
11
11
  extend T::Sig
12
12
  extend T::Helpers
13
- include Thor::Shell
13
+
14
+ include Colorize
14
15
 
15
16
  requires_ancestor { Thor }
16
17
 
@@ -85,7 +86,7 @@ module Spoom
85
86
  # Colors
86
87
 
87
88
  # Color used to highlight expressions in backticks
88
- HIGHLIGHT_COLOR = :blue
89
+ HIGHLIGHT_COLOR = T.let(Spoom::Color::BLUE, Spoom::Color)
89
90
 
90
91
  # Is the `--color` option true?
91
92
  sig { returns(T::Boolean) }
@@ -117,35 +118,35 @@ module Spoom
117
118
  end
118
119
 
119
120
  # Colorize a string if `color?`
120
- sig { params(string: String, color: Symbol).returns(String) }
121
- def colorize(string, color)
121
+ sig { params(string: String, color: Color).returns(String) }
122
+ def colorize(string, *color)
122
123
  return string unless color?
123
- string.colorize(color)
124
+ T.unsafe(self).set_color(string, *color)
124
125
  end
125
126
 
126
127
  sig { params(string: String).returns(String) }
127
128
  def blue(string)
128
- colorize(string, :blue)
129
+ colorize(string, Color::BLUE)
129
130
  end
130
131
 
131
132
  sig { params(string: String).returns(String) }
132
133
  def gray(string)
133
- colorize(string, :light_black)
134
+ colorize(string, Color::LIGHT_BLACK)
134
135
  end
135
136
 
136
137
  sig { params(string: String).returns(String) }
137
138
  def green(string)
138
- colorize(string, :green)
139
+ colorize(string, Color::GREEN)
139
140
  end
140
141
 
141
142
  sig { params(string: String).returns(String) }
142
143
  def red(string)
143
- colorize(string, :red)
144
+ colorize(string, Color::RED)
144
145
  end
145
146
 
146
147
  sig { params(string: String).returns(String) }
147
148
  def yellow(string)
148
- colorize(string, :yellow)
149
+ colorize(string, Color::YELLOW)
149
150
  end
150
151
  end
151
152
  end
@@ -0,0 +1,45 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Spoom
5
+ class Color < T::Enum
6
+ extend T::Sig
7
+
8
+ enums do
9
+ CLEAR = new("\e[0m")
10
+ BOLD = new("\e[1m")
11
+
12
+ BLACK = new("\e[30m")
13
+ RED = new("\e[31m")
14
+ GREEN = new("\e[32m")
15
+ YELLOW = new("\e[33m")
16
+ BLUE = new("\e[34m")
17
+ MAGENTA = new("\e[35m")
18
+ CYAN = new("\e[36m")
19
+ WHITE = new("\e[37m")
20
+
21
+ LIGHT_BLACK = new("\e[90m")
22
+ LIGHT_RED = new("\e[91m")
23
+ LIGHT_GREEN = new("\e[92m")
24
+ LIGHT_YELLOW = new("\e[93m")
25
+ LIGHT_BLUE = new("\e[94m")
26
+ LIGHT_MAGENTA = new("\e[95m")
27
+ LIGHT_CYAN = new("\e[96m")
28
+ LIGHT_WHITE = new("\e[97m")
29
+ end
30
+
31
+ sig { returns(String) }
32
+ def ansi_code
33
+ serialize
34
+ end
35
+ end
36
+
37
+ module Colorize
38
+ extend T::Sig
39
+
40
+ sig { params(string: String, color: Color).returns(String) }
41
+ def set_color(string, *color)
42
+ "#{color.map(&:ansi_code).join}#{string}#{Color::CLEAR.ansi_code}"
43
+ end
44
+ end
45
+ end
@@ -156,7 +156,7 @@ module Spoom
156
156
  end
157
157
  print("\n")
158
158
  else
159
- print_colored(node.name, :blue)
159
+ print_colored(node.name, Color::BLUE)
160
160
  print("/")
161
161
  printn
162
162
  indent
@@ -180,15 +180,15 @@ module Spoom
180
180
  Spoom::Sorbet::Sigils.file_strictness(path)
181
181
  end
182
182
 
183
- sig { params(strictness: T.nilable(String)).returns(Symbol) }
183
+ sig { params(strictness: T.nilable(String)).returns(Color) }
184
184
  def strictness_color(strictness)
185
185
  case strictness
186
186
  when "false"
187
- :red
187
+ Color::RED
188
188
  when "true", "strict", "strong"
189
- :green
189
+ Color::GREEN
190
190
  else
191
- :uncolored
191
+ Color::CLEAR
192
192
  end
193
193
  end
194
194
  end
data/lib/spoom/printer.rb CHANGED
@@ -8,6 +8,8 @@ module Spoom
8
8
  extend T::Sig
9
9
  extend T::Helpers
10
10
 
11
+ include Colorize
12
+
11
13
  abstract!
12
14
 
13
15
  sig { returns(T.any(IO, StringIO)) }
@@ -42,11 +44,10 @@ module Spoom
42
44
  # Print `string` colored with `color` into `out`
43
45
  #
44
46
  # Does not use colors unless `@colors`.
45
- sig { params(string: T.nilable(String), color: Symbol, colors: Symbol).void }
46
- def print_colored(string, color, *colors)
47
+ sig { params(string: T.nilable(String), color: Color).void }
48
+ def print_colored(string, *color)
47
49
  return unless string
48
- string = colorize(string, color)
49
- colors.each { |c| string = colorize(string, c) }
50
+ string = T.unsafe(self).colorize(string, *color)
50
51
  @out.print(string)
51
52
  end
52
53
 
@@ -72,9 +73,10 @@ module Spoom
72
73
  end
73
74
 
74
75
  # Colorize `string` with color if `@colors`
75
- sig { params(string: String, color: Symbol).returns(String) }
76
- def colorize(string, color)
77
- @colors ? string.colorize(color) : string
76
+ sig { params(string: String, color: Spoom::Color).returns(String) }
77
+ def colorize(string, *color)
78
+ return string unless @colors
79
+ T.unsafe(self).set_color(string, *color)
78
80
  end
79
81
  end
80
82
  end
@@ -56,7 +56,7 @@ module Spoom
56
56
 
57
57
  sig { override.params(printer: SymbolPrinter).void }
58
58
  def accept_printer(printer)
59
- printer.print_colored("#{line}:#{char}", :light_black)
59
+ printer.print_colored("#{line}:#{char}", Color::LIGHT_BLACK)
60
60
  end
61
61
 
62
62
  def to_s
@@ -81,7 +81,7 @@ module Spoom
81
81
  sig { override.params(printer: SymbolPrinter).void }
82
82
  def accept_printer(printer)
83
83
  printer.print_object(start)
84
- printer.print_colored("-", :light_black)
84
+ printer.print_colored("-", Color::LIGHT_BLACK)
85
85
  printer.print_object(self.end)
86
86
  end
87
87
 
@@ -106,7 +106,7 @@ module Spoom
106
106
 
107
107
  sig { override.params(printer: SymbolPrinter).void }
108
108
  def accept_printer(printer)
109
- printer.print_colored("#{printer.clean_uri(uri)}:", :light_black)
109
+ printer.print_colored("#{printer.clean_uri(uri)}:", Color::LIGHT_BLACK)
110
110
  printer.print_object(range)
111
111
  end
112
112
 
@@ -203,14 +203,14 @@ module Spoom
203
203
  printer.printt
204
204
  printer.print(kind_string)
205
205
  printer.print(' ')
206
- printer.print_colored(name, :blue, :bold)
207
- printer.print_colored(' (', :light_black)
206
+ printer.print_colored(name, Color::BLUE, Color::BOLD)
207
+ printer.print_colored(' (', Color::LIGHT_BLACK)
208
208
  if range
209
209
  printer.print_object(range)
210
210
  elsif location
211
211
  printer.print_object(location)
212
212
  end
213
- printer.print_colored(')', :light_black)
213
+ printer.print_colored(')', Color::LIGHT_BLACK)
214
214
  printer.printn
215
215
  unless children.empty?
216
216
  printer.indent
data/lib/spoom/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.1.4"
5
+ VERSION = "1.1.5"
6
6
  end
data/lib/spoom.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- require "colorize"
5
4
  require "sorbet-runtime"
6
5
 
7
6
  module Spoom
@@ -27,6 +26,7 @@ module Spoom
27
26
  end
28
27
  end
29
28
 
29
+ require "spoom/colors"
30
30
  require "spoom/sorbet"
31
31
  require "spoom/cli"
32
32
  require "spoom/version"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-06 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.19.2
97
- - !ruby/object:Gem::Dependency
98
- name: colorize
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
97
  description:
112
98
  email:
113
99
  - ruby@shopify.com
@@ -128,6 +114,7 @@ files:
128
114
  - lib/spoom/cli/helper.rb
129
115
  - lib/spoom/cli/lsp.rb
130
116
  - lib/spoom/cli/run.rb
117
+ - lib/spoom/colors.rb
131
118
  - lib/spoom/coverage.rb
132
119
  - lib/spoom/coverage/d3.rb
133
120
  - lib/spoom/coverage/d3/base.rb