Support "blink" attribute in the thumbnails

This commit is contained in:
Marcin Kulik 2013-08-15 23:05:09 +02:00
parent a53c8de5b9
commit 40856933aa
3 changed files with 76 additions and 4 deletions

View File

@ -1,6 +1,6 @@
GIT GIT
remote: git://github.com/sickill/tsm.git remote: git://github.com/sickill/tsm.git
revision: 13841c34e7320807eda25086c430b8501d1c7bae revision: 7b0a8b17577b477f4b870327401ec15b53053c82
specs: specs:
tsm (0.1.0) tsm (0.1.0)
ffi (~> 1.8) ffi (~> 1.8)

View File

@ -9,7 +9,8 @@ class Brush
bg == other.bg && bg == other.bg &&
bold? == other.bold? && bold? == other.bold? &&
underline? == other.underline? && underline? == other.underline? &&
inverse? == other.inverse? inverse? == other.inverse? &&
blink? == other.blink?
end end
def fg def fg
@ -25,7 +26,15 @@ class Brush
end end
def bg def bg
attributes[:bg] code = attributes[:bg]
if code
if code < 8 && blink?
code += 8
end
end
code
end end
def bold? def bold?
@ -40,8 +49,12 @@ class Brush
!!attributes[:inverse] !!attributes[:inverse]
end end
def blink?
!!attributes[:blink]
end
def default? def default?
fg.nil? && bg.nil? && !bold? && !underline? && !inverse? fg.nil? && bg.nil? && !bold? && !underline? && !inverse? && !blink?
end end
protected protected

View File

@ -10,6 +10,7 @@ describe Brush do
:bold => true, :bold => true,
:underline => false, :underline => false,
:inverse => true, :inverse => true,
:blink => false,
:foo => true, :foo => true,
} } } }
@ -22,6 +23,7 @@ describe Brush do
:bold => true, :bold => true,
:underline => false, :underline => false,
:inverse => true, :inverse => true,
:blink => false,
:foo => false # should be ignored :foo => false # should be ignored
) } ) }
@ -35,6 +37,7 @@ describe Brush do
:bold => false, :bold => false,
:underline => false, :underline => false,
:inverse => true, :inverse => true,
:blink => false,
:foo => true # should be ignored :foo => true # should be ignored
) } ) }
@ -100,6 +103,34 @@ describe Brush do
it { should be(nil) } it { should be(nil) }
end end
context "when blink is set" do
let(:attributes) { { :blink => true } }
context "and input bg is < 8" do
before do
attributes[:bg] = 7
end
it { should eq(15) }
end
context "and input bg is == 8" do
before do
attributes[:bg] = 8
end
it { should eq(8) }
end
context "and input bg is > 8" do
before do
attributes[:bg] = 9
end
it { should eq(9) }
end
end
end end
describe '#bold?' do describe '#bold?' do
@ -168,6 +199,28 @@ describe Brush do
end end
end end
describe '#blink?' do
subject { brush.blink? }
context "when blink was set to true" do
let(:attributes) { { :blink => true } }
it { should be(true) }
end
context "when blink was set to false" do
let(:attributes) { { :blink => false } }
it { should be(false) }
end
context "when blink was not set" do
let(:attributes) { {} }
it { should be(false) }
end
end
describe '#default?' do describe '#default?' do
subject { brush.default? } subject { brush.default? }
@ -206,6 +259,12 @@ describe Brush do
it { should be(false) } it { should be(false) }
end end
context "when blink is set" do
let(:attributes) { { :blink => true } }
it { should be(false) }
end
end end
end end