Browse files

Handle 'NONE'

  • Loading branch information...
1 parent ac5ffd0 commit e8235f67aad591e7e3dd67b7717d76e73e0235e0 Micah Werbitt committed with May 20, 2011
Showing with 24 additions and 6 deletions.
  1. +16 −6 lib/palette/rule.rb
  2. +8 −0 spec/rule_spec.rb
View
22 lib/palette/rule.rb
@@ -20,15 +20,25 @@ def to_s
output = ["hi #{sprintf("%-#{@@max_length}s", name)}"]
if fg
- color = Palette::Color.new(fg)
- output << %{guifg=##{color.to_hex}}
- output << %{ctermfg=#{sprintf("%-3s", color.to_cterm)}}
+ if fg.to_s.upcase == 'NONE'
+ output << 'guifg=NONE'
+ output << 'ctermfg=NONE'
+ else
+ color = Palette::Color.new(fg)
+ output << %{guifg=##{color.to_hex}}
+ output << %{ctermfg=#{sprintf("%-3s", color.to_cterm)}}
+ end
end
if bg
- color = Palette::Color.new(bg)
- output << %{guibg=##{color.to_hex}}
- output << %{ctermbg=#{sprintf("%-3s", color.to_cterm)}}
+ if bg.to_s.upcase == 'NONE'
+ output << 'guibg=NONE'
+ output << 'ctermbg=NONE'
+ else
+ color = Palette::Color.new(bg)
+ output << %{guibg=##{color.to_hex}}
+ output << %{ctermbg=#{sprintf("%-3s", color.to_cterm)}}
+ end
end
if gui
View
8 spec/rule_spec.rb
@@ -30,6 +30,14 @@
end
end
+describe Palette::Rule, "with a foreground set to none" do
+ subject { Palette::Rule.new("Awesome", :none) }
+
+ it "highlights the correct colors" do
+ subject.to_s.should == "hi Awesome guifg=NONE ctermfg=NONE"
+ end
+end
+
describe Palette::Rule, "with a foreground and background" do
it_should_behave_like "rule with colors" do
subject { Palette::Rule.new("Awesome", fg, bg) }

0 comments on commit e8235f6

Please sign in to comment.