simple style validation
This commit is contained in:
parent
5738d37803
commit
fef5e3f633
|
@ -80,6 +80,9 @@ class Fingers::Commands::LoadConfig < Fingers::Commands::Base
|
|||
config.save
|
||||
|
||||
Fingers.reset_config
|
||||
rescue e : TmuxStylePrinter::InvalidFormat
|
||||
puts "[tmux-fingers] #{e.message}"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
def clean_up_patterns(patterns)
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
class TmuxStylePrinter
|
||||
|
||||
class InvalidFormat < Exception
|
||||
end
|
||||
|
||||
abstract class Shell
|
||||
abstract def exec(cmd)
|
||||
end
|
||||
|
@ -70,7 +74,7 @@ class TmuxStylePrinter
|
|||
private def parse_color(style)
|
||||
match = style.match(/(?<layer>bg|fg)=(?<color>(colou?r(?<color_code>[0-9]+)|.*))/)
|
||||
|
||||
return "" unless match
|
||||
raise InvalidFormat.new("Invalid color definition: #{style}") unless match
|
||||
|
||||
layer = match["layer"]
|
||||
color = match["color"]
|
||||
|
@ -81,7 +85,9 @@ class TmuxStylePrinter
|
|||
return reset_to_applied_styles!
|
||||
end
|
||||
|
||||
color_to_apply = color_code || COLOR_MAP[color]
|
||||
color_to_apply = color_code || COLOR_MAP[color]?
|
||||
|
||||
raise InvalidFormat.new("Invalid color definition: #{style}") if color_to_apply.nil?
|
||||
|
||||
result = shell.exec("tput #{LAYER_MAP[layer]} #{color_to_apply}")
|
||||
|
||||
|
@ -93,11 +99,15 @@ class TmuxStylePrinter
|
|||
private def parse_style(style)
|
||||
match = style.match(/(?<remove>no)?(?<style>.*)/)
|
||||
|
||||
return "" unless match
|
||||
raise InvalidFormat.new("Invalid style definition: #{style}") unless match
|
||||
|
||||
should_remove_style = match["remove"]? && match["remove"] == "no"
|
||||
style = match["style"]
|
||||
|
||||
style_to_apply = STYLE_MAP[style]?
|
||||
|
||||
raise InvalidFormat.new("Invalid style definition: #{style}") if style_to_apply.nil?
|
||||
|
||||
result = style == "dim" ? "\033[2m" : shell.exec("tput #{STYLE_MAP[style]}")
|
||||
|
||||
if should_remove_style
|
||||
|
|
Loading…
Reference in New Issue