From 40856933aada9c508df43dbde2f3c2175cd8c1c4 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 15 Aug 2013 23:05:09 +0200 Subject: [PATCH] Support "blink" attribute in the thumbnails --- Gemfile.lock | 2 +- app/models/brush.rb | 19 +++++++++++-- spec/models/brush_spec.rb | 59 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2e740b3..73a1c95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/sickill/tsm.git - revision: 13841c34e7320807eda25086c430b8501d1c7bae + revision: 7b0a8b17577b477f4b870327401ec15b53053c82 specs: tsm (0.1.0) ffi (~> 1.8) diff --git a/app/models/brush.rb b/app/models/brush.rb index 2d12ddf..a894419 100644 --- a/app/models/brush.rb +++ b/app/models/brush.rb @@ -9,7 +9,8 @@ class Brush bg == other.bg && bold? == other.bold? && underline? == other.underline? && - inverse? == other.inverse? + inverse? == other.inverse? && + blink? == other.blink? end def fg @@ -25,7 +26,15 @@ class Brush end def bg - attributes[:bg] + code = attributes[:bg] + + if code + if code < 8 && blink? + code += 8 + end + end + + code end def bold? @@ -40,8 +49,12 @@ class Brush !!attributes[:inverse] end + def blink? + !!attributes[:blink] + end + def default? - fg.nil? && bg.nil? && !bold? && !underline? && !inverse? + fg.nil? && bg.nil? && !bold? && !underline? && !inverse? && !blink? end protected diff --git a/spec/models/brush_spec.rb b/spec/models/brush_spec.rb index 4d6f6f7..649cb8a 100644 --- a/spec/models/brush_spec.rb +++ b/spec/models/brush_spec.rb @@ -10,6 +10,7 @@ describe Brush do :bold => true, :underline => false, :inverse => true, + :blink => false, :foo => true, } } @@ -22,6 +23,7 @@ describe Brush do :bold => true, :underline => false, :inverse => true, + :blink => false, :foo => false # should be ignored ) } @@ -35,6 +37,7 @@ describe Brush do :bold => false, :underline => false, :inverse => true, + :blink => false, :foo => true # should be ignored ) } @@ -100,6 +103,34 @@ describe Brush do it { should be(nil) } 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 describe '#bold?' do @@ -168,6 +199,28 @@ describe Brush do 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 subject { brush.default? } @@ -206,6 +259,12 @@ describe Brush do it { should be(false) } end + + context "when blink is set" do + let(:attributes) { { :blink => true } } + + it { should be(false) } + end end end