howzit 2.1.2 → 2.1.4

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: 23a304a27d457b410c8764ed0b83f0a00e2e6e9108ba3fd4a7bef722695d8607
4
- data.tar.gz: 2041090127040e2315691750de2ee9ccaf3d770a7b8561d328f573e78e633a50
3
+ metadata.gz: c6636feaeffc5a9b8ece43a5ac13d50959412ae83b45aa22f2c8f45aa3243b51
4
+ data.tar.gz: 537931680e6c7edcb1149339b09877df06d283daa0d0513486cfd1452de4f0b3
5
5
  SHA512:
6
- metadata.gz: 8dda575709255dec600f6ba6f259c856b67ab91d9418fbcbc374f85a8eaa6a2842ac8a0b9bdd22a5eec9621e17353b6f2dfa7bc7b6f9b7de9d0c64006d5a27b1
7
- data.tar.gz: 236c40bbd997c4bd956aa9796999771b965907add10b208929ba45a09c04679126177232dce1a5d29d15cec4ebfd09315b8bc274e588b0fccc02a938395731ef
6
+ metadata.gz: 93b5c6136f0c612aa914151e0e0df4caa2c4a01259325b4b725aad289eda22d11b09f70d4801d40bb9587733ee8ff62c9117a9b14d53344ee449c6a1c394e612
7
+ data.tar.gz: 1ccc318642663bde10dd806752f796d39344cebea009b930d7dbe2ead69a537fbd5077f66f1e0876d41706fba9a982c4bb6328ddfcea17d2d4f09ae42d4c69bc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ### 2.1.4
2
+
3
+ 2023-03-07 12:52
4
+
5
+ #### NEW
6
+
7
+ - A theme file is automatically created where you can change the default output of any color that Howzit outputs. They can be 2-3 digit ANSI escape codes, or '#XXXXXX' RGB hex codes
8
+
9
+ ### 2.1.3
10
+
11
+ 2023-03-07 11:21
12
+
13
+ #### FIXED
14
+
15
+ - Annoying warning about color template format string having too many arguments
16
+
1
17
  ### 2.1.2
2
18
 
3
19
  2023-03-07 10:24
data/lib/howzit/colors.rb CHANGED
@@ -205,6 +205,49 @@ module Howzit
205
205
  @coloring ||= true
206
206
  end
207
207
 
208
+ def translate_rgb(code)
209
+ return code if code !~ /#[A-Z0-9]{3,6}/i
210
+
211
+ rgb(code)
212
+ end
213
+
214
+ ##
215
+ ## Generate escape codes for hex colors
216
+ ##
217
+ ## @param hex [String] The hexadecimal color code
218
+ ##
219
+ ## @return [String] ANSI escape string
220
+ ##
221
+ def rgb(hex)
222
+ is_bg = hex.match(/^bg?#/) ? true : false
223
+ hex_string = hex.sub(/^([fb]g?)?#/, '')
224
+
225
+ parts = hex_string.match(/(?<r>..)(?<g>..)(?<b>..)/)
226
+ t = []
227
+ %w[r g b].each do |e|
228
+ t << parts[e].hex
229
+ end
230
+
231
+ "\e[#{is_bg ? '48' : '38'};2;#{t.join(';')}"
232
+ end
233
+
234
+ # Merge config file colors into attributes
235
+ def configured_colors
236
+ color_file = File.join(File.expand_path(CONFIG_DIR), COLOR_FILE)
237
+ if File.exist?(color_file)
238
+ colors = YAML.load(Util.read_file(color_file))
239
+ return ATTRIBUTES unless !colors.nil? && colors.is_a?(Hash)
240
+
241
+ attrs = ATTRIBUTES.to_h
242
+ attrs = attrs.merge(colors.symbolize_keys)
243
+ new_colors = {}
244
+ attrs.each { |k, v| new_colors[k] = translate_rgb(v) }
245
+ new_colors.to_a
246
+ else
247
+ ATTRIBUTES
248
+ end
249
+ end
250
+
208
251
  ##
209
252
  ## Convert a template string to a colored string.
210
253
  ## Colors are specified with single letters inside
@@ -237,11 +280,13 @@ module Howzit
237
280
  Y: bgyellow, C: bgcyan, M: bgmagenta, R: bgred,
238
281
  d: dark, b: bold, u: underline, i: italic, x: reset }
239
282
 
240
- format(fmt, colors)
283
+ fmt.empty? ? input : format(fmt, colors)
241
284
  end
242
285
  end
243
286
 
244
- ATTRIBUTES.each do |c, v|
287
+ # Dynamically generate methods for each color name. Each
288
+ # resulting method can be called with a string or a block.
289
+ configured_colors.each do |c, v|
245
290
  new_method = <<-EOSCRIPT
246
291
  # Color string as #{c}
247
292
  def #{c}(string = nil)
@@ -288,26 +333,6 @@ module Howzit
288
333
  module_eval(new_method)
289
334
  end
290
335
 
291
- ##
292
- ## Generate escape codes for hex colors
293
- ##
294
- ## @param hex [String] The hexadecimal color code
295
- ##
296
- ## @return [String] ANSI escape string
297
- ##
298
- def rgb(hex)
299
- is_bg = hex.match(/^bg?#/) ? true : false
300
- hex_string = hex.sub(/^([fb]g?)?#/, '')
301
-
302
- parts = hex_string.match(/(?<r>..)(?<g>..)(?<b>..)/)
303
- t = []
304
- %w[r g b].each do |e|
305
- t << parts[e].hex
306
- end
307
- color =
308
- "\e[#{is_bg ? '48' : '38'};2;#{t.join(';')}m"
309
- end
310
-
311
336
  # Regular expression that is used to scan for ANSI-sequences while
312
337
  # uncoloring strings.
313
338
  COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9])?m/.freeze
data/lib/howzit/config.rb CHANGED
@@ -23,6 +23,45 @@ module Howzit
23
23
  wrap: 0
24
24
  }.deep_freeze
25
25
 
26
+ DEFAULT_COLORS = [
27
+ [:black, 30],
28
+ [:red, 31],
29
+ [:green, 32],
30
+ [:yellow, 33],
31
+ [:blue, 34],
32
+ [:magenta, 35],
33
+ [:purple, 35],
34
+ [:cyan, 36],
35
+ [:white, 37],
36
+ [:bgblack, 40],
37
+ [:bgred, 41],
38
+ [:bggreen, 42],
39
+ [:bgyellow, 43],
40
+ [:bgblue, 44],
41
+ [:bgmagenta, 45],
42
+ [:bgpurple, 45],
43
+ [:bgcyan, 46],
44
+ [:bgwhite, 47],
45
+ [:boldblack, 90],
46
+ [:boldred, 91],
47
+ [:boldgreen, 92],
48
+ [:boldyellow, 93],
49
+ [:boldblue, 94],
50
+ [:boldmagenta, 95],
51
+ [:boldpurple, 95],
52
+ [:boldcyan, 96],
53
+ [:boldwhite, 97],
54
+ [:boldbgblack, 100],
55
+ [:boldbgred, 101],
56
+ [:boldbggreen, 102],
57
+ [:boldbgyellow, 103],
58
+ [:boldbgblue, 104],
59
+ [:boldbgmagenta, 105],
60
+ [:boldbgpurple, 105],
61
+ [:boldbgcyan, 106],
62
+ [:boldbgwhite, 107]
63
+ ].to_h.deep_freeze
64
+
26
65
  ##
27
66
  ## Initialize a config object
28
67
  ##
@@ -39,6 +78,15 @@ module Howzit
39
78
  File.open(config_file, 'w') { |f| f.puts config.to_yaml }
40
79
  end
41
80
 
81
+ ##
82
+ ## Write a theme to a file
83
+ ##
84
+ ## @param config The configuration
85
+ ##
86
+ def write_theme(config)
87
+ File.open(theme_file, 'w') { |f| f.puts config.to_yaml }
88
+ end
89
+
42
90
  ##
43
91
  ## Test if a file should be ignored based on YAML file
44
92
  ##
@@ -105,6 +153,7 @@ module Howzit
105
153
  }
106
154
 
107
155
  config = load_config
156
+ load_theme
108
157
  @options = flags.merge(config)
109
158
  end
110
159
 
@@ -126,6 +175,15 @@ module Howzit
126
175
  File.join(config_dir, CONFIG_FILE)
127
176
  end
128
177
 
178
+ ##
179
+ ## Get the theme file
180
+ ##
181
+ ## @return [String] path to config file
182
+ ##
183
+ def theme_file
184
+ File.join(config_dir, COLOR_FILE)
185
+ end
186
+
129
187
  ##
130
188
  ## Get the ignore config file
131
189
  ##
@@ -153,6 +211,24 @@ module Howzit
153
211
  config_file
154
212
  end
155
213
 
214
+ ##
215
+ ## Create a new config file (and directory if needed)
216
+ ##
217
+ ## @param default [Hash] default configuration to write
218
+ ##
219
+ def create_theme(default)
220
+ unless File.directory?(config_dir)
221
+ Howzit::ConsoleLogger.new(1).info "Creating theme directory at #{config_dir}"
222
+ FileUtils.mkdir_p(config_dir)
223
+ end
224
+
225
+ unless File.exist?(theme_file)
226
+ Howzit::ConsoleLogger.new(1).info "Writing fresh theme file to #{theme_file}"
227
+ write_theme(default)
228
+ end
229
+ theme_file
230
+ end
231
+
156
232
  ##
157
233
  ## Load the config file
158
234
  ##
@@ -166,6 +242,19 @@ module Howzit
166
242
  newconfig.dup
167
243
  end
168
244
 
245
+ ##
246
+ ## Load the theme file
247
+ ##
248
+ ## @return [Hash] configuration object
249
+ ##
250
+ def load_theme
251
+ file = create_theme(DEFAULT_COLORS)
252
+ config = YAML.load(Util.read_file(file))
253
+ newconfig = config ? DEFAULT_COLORS.merge(config) : DEFAULT_COLORS
254
+ write_theme(newconfig)
255
+ newconfig.dup
256
+ end
257
+
169
258
  ##
170
259
  ## Open the config in an editor
171
260
  ##
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.1.2'
6
+ VERSION = '2.1.4'
7
7
  end
data/lib/howzit.rb CHANGED
@@ -1,35 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'howzit/version'
4
- require_relative 'howzit/prompt'
5
- require_relative 'howzit/colors'
6
- require_relative 'howzit/stringutils'
7
-
8
- require_relative 'howzit/hash'
9
- require_relative 'howzit/console_logger'
10
- require_relative 'howzit/util'
11
- require_relative 'howzit/config'
12
- require_relative 'howzit/task'
13
- require_relative 'howzit/topic'
14
- require_relative 'howzit/buildnote'
15
-
16
- require 'optparse'
17
- require 'shellwords'
18
- require 'pathname'
19
- require 'readline'
20
- require 'tempfile'
21
- require 'yaml'
22
-
23
- require 'tty/screen'
24
- require 'tty/box'
25
- # require 'tty/prompt'
26
-
27
3
  # Main config dir
28
4
  CONFIG_DIR = '~/.config/howzit'
29
5
 
30
6
  # Config file name
31
7
  CONFIG_FILE = 'howzit.yaml'
32
8
 
9
+ # Color template name
10
+ COLOR_FILE = 'theme.yaml'
11
+
33
12
  # Ignore file name
34
13
  IGNORE_FILE = 'ignore.yaml'
35
14
 
@@ -42,6 +21,31 @@ MULTIPLE_OPTIONS = %w[first best all choose].freeze
42
21
  # Available options for header formatting
43
22
  HEADER_FORMAT_OPTIONS = %w[border block].freeze
44
23
 
24
+ require 'optparse'
25
+ require 'shellwords'
26
+ require 'pathname'
27
+ require 'readline'
28
+ require 'tempfile'
29
+ require 'yaml'
30
+
31
+ require_relative 'howzit/util'
32
+ require_relative 'howzit/hash'
33
+
34
+ require_relative 'howzit/version'
35
+ require_relative 'howzit/prompt'
36
+ require_relative 'howzit/colors'
37
+ require_relative 'howzit/stringutils'
38
+
39
+ require_relative 'howzit/console_logger'
40
+ require_relative 'howzit/config'
41
+ require_relative 'howzit/task'
42
+ require_relative 'howzit/topic'
43
+ require_relative 'howzit/buildnote'
44
+
45
+ require 'tty/screen'
46
+ require 'tty/box'
47
+ # require 'tty/prompt'
48
+
45
49
  # Main module for howzit
46
50
  module Howzit
47
51
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra