Make Terminal return already optimized snapshot

openid
Marcin Kulik 11 years ago
parent 0e2c1784c6
commit ff153fff1a

@ -7,7 +7,7 @@ class FrameDiff
def as_json(*)
json = {}
json[:lines] = optimized_line_changes unless line_changes.blank?
json[:lines] = line_changes unless line_changes.blank?
json[:cursor] = cursor_changes unless cursor_changes.blank?
json
@ -17,12 +17,4 @@ class FrameDiff
attr_reader :line_changes, :cursor_changes
def optimized_line_changes
line_optimizer = LineOptimizer.new
line_changes.each_with_object({}) do |(k, v), h|
h[k] = line_optimizer.optimize(v)
end
end
end

@ -7,24 +7,12 @@ describe FrameDiff do
let(:cursor_changes) { { x: 1 } }
let(:line_0) { double('line_0') }
let(:line_2) { double('line_2') }
let(:line_optimizer) { double('line_optimizer') }
let(:optimized_line_0) { double('optimized_line_0') }
let(:optimized_line_2) { double('optimized_line_2') }
describe '#as_json' do
subject { frame_diff.as_json }
before do
allow(LineOptimizer).to receive(:new) { line_optimizer }
allow(line_optimizer).to receive(:optimize).
with(line_0) { optimized_line_0 }
allow(line_optimizer).to receive(:optimize).
with(line_2) { optimized_line_2 }
end
it 'includes line changes and cursor changes' do
expect(subject).to eq({ :lines => { 0 => optimized_line_0,
2 => optimized_line_2 },
expect(subject).to eq({ :lines => { 0 => line_0, 2 => line_2 },
:cursor => cursor_changes })
end

@ -4,7 +4,7 @@ require 'spec_helper'
describe Terminal do
let(:terminal) { Terminal.new(4, 3) }
let(:terminal) { Terminal.new(6, 3) }
let(:first_line_text) { subject.as_json.first.map(&:first).join.strip }
before do
@ -20,24 +20,29 @@ describe Terminal do
describe '#snapshot' do
subject { terminal.snapshot }
let(:data) { ["f\e[31mo\e[42mo\n", "\rb\e[0ma\e[1;4;5;7ms"] }
let(:data) { ["fo\e[31mo\e[42mba\n", "\rr\e[0mb\e[1;4;5;7maz"] }
it 'returns an instance of Snapshot' do
expect(subject).to be_kind_of(Snapshot)
end
it "returns each screen cell with its character attributes" do
it "returns screen cells groupped by the character attributes" do
expect(subject.as_json).to eq([
[
['f', {}], ['o', fg: 1], ['o', fg: 1, bg: 2], [' ', {}],
['fo', {}],
['o', fg: 1],
['ba', fg: 1, bg: 2],
[' ', {}],
],
[
['b', fg: 1, bg: 2], ['a', {}], ['s', bold: true, underline: true,
inverse: true, blink: true],
[' ', inverse: true] # <- cursor here
['r', fg: 1, bg: 2],
['b', {}],
['az', bold: true, underline: true, inverse: true, blink: true],
[' ', inverse: true], # <- cursor here
[' ', {}]
],
[
[' ', {}], [' ', {}], [' ', {}], [' ', {}]
[' ', {}]
]
])
end

Loading…
Cancel
Save