tty 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/CHANGELOG.md +8 -0
- data/README.md +74 -42
- data/lib/tty.rb +7 -9
- data/lib/tty/conversion.rb +16 -0
- data/lib/tty/conversion/converter/array.rb +35 -0
- data/lib/tty/{coercer → conversion/converter}/boolean.rb +20 -7
- data/lib/tty/conversion/converter/float.rb +28 -0
- data/lib/tty/conversion/converter/integer.rb +28 -0
- data/lib/tty/{coercer → conversion/converter}/range.rb +16 -7
- data/lib/tty/logger.rb +1 -1
- data/lib/tty/shell/question.rb +2 -1
- data/lib/tty/shell/response.rb +9 -4
- data/lib/tty/shell/statement.rb +3 -2
- data/lib/tty/table.rb +3 -3
- data/lib/tty/table/border.rb +8 -5
- data/lib/tty/table/border/row_line.rb +2 -2
- data/lib/tty/table/operation/alignment_set.rb +2 -1
- data/lib/tty/table/padder.rb +1 -1
- data/lib/tty/table/renderer/basic.rb +1 -1
- data/lib/tty/terminal.rb +1 -118
- data/lib/tty/text/truncation.rb +4 -1
- data/lib/tty/text/wrapping.rb +4 -1
- data/lib/tty/vector.rb +4 -3
- data/lib/tty/version.rb +2 -2
- data/spec/tty/{support/conversion_spec.rb → conversion/converter/array/convert_spec.rb} +4 -5
- data/spec/tty/{coercer/boolean/coerce_spec.rb → conversion/converter/boolean/convert_spec.rb} +5 -4
- data/spec/tty/{coercer/float/coerce_spec.rb → conversion/converter/float/convert_spec.rb} +3 -2
- data/spec/tty/{coercer/integer/coerce_spec.rb → conversion/converter/integer/convert_spec.rb} +4 -2
- data/spec/tty/{coercer/range/coerce_spec.rb → conversion/converter/range/convert_spec.rb} +3 -2
- data/spec/tty/shell/error_spec.rb +4 -1
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/say_spec.rb +3 -0
- data/spec/tty/shell/statement/initialize_spec.rb +2 -2
- data/spec/tty/shell/warn_spec.rb +3 -0
- data/spec/tty/table/field/equality_spec.rb +1 -1
- data/spec/tty/table/render_spec.rb +3 -0
- data/spec/tty/table/render_with_spec.rb +8 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +10 -9
- data/spec/tty/table/renderer/style_spec.rb +3 -0
- data/spec/tty/terminal/color_spec.rb +6 -3
- data/tasks/console.rake +1 -1
- data/tty.gemspec +7 -1
- metadata +88 -30
- data/lib/tty/coercer.rb +0 -13
- data/lib/tty/coercer/float.rb +0 -20
- data/lib/tty/coercer/integer.rb +0 -20
- data/lib/tty/support/conversion.rb +0 -35
- data/lib/tty/support/equatable.rb +0 -152
- data/lib/tty/terminal/color.rb +0 -157
- data/spec/tty/support/equatable_spec.rb +0 -201
- data/spec/tty/terminal/color/code_spec.rb +0 -19
- data/spec/tty/terminal/color/remove_spec.rb +0 -44
- data/spec/tty/terminal/color/set_spec.rb +0 -29
- data/spec/tty/terminal/size_spec.rb +0 -97
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Color, '#code' do
|
6
|
-
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
7
|
-
|
8
|
-
it 'finds single code' do
|
9
|
-
expect(subject.code(:black)).to eq(["\e[30m"])
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'finds more than one code' do
|
13
|
-
expect(subject.code(:black, :green)).to eq(["\e[30m", "\e[32m"])
|
14
|
-
end
|
15
|
-
|
16
|
-
it "doesn't find code" do
|
17
|
-
expect { subject.code(:unkown) }.to raise_error(ArgumentError)
|
18
|
-
end
|
19
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Color, '#remove' do
|
6
|
-
let(:instance) { described_class.new }
|
7
|
-
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
8
|
-
|
9
|
-
subject { instance.remove string }
|
10
|
-
|
11
|
-
it 'remove color from string' do
|
12
|
-
is_expected.to eq("This is a bold blue text")
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'with octal in encapsulating brackets' do
|
16
|
-
let(:string) { "\[\033[01;32m\]u@h \[\033[01;34m\]W $ \[\033[00m\]" }
|
17
|
-
|
18
|
-
it { is_expected.to eq('u@h W $ ') }
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with octal without brackets' do
|
22
|
-
let(:string) { "\033[01;32mu@h \033[01;34mW $ \033[00m" }
|
23
|
-
|
24
|
-
it { is_expected.to eq('u@h W $ ') }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with octal with multiple colors' do
|
28
|
-
let(:string) { "\e[3;0;0;t\e[8;50;0t" }
|
29
|
-
|
30
|
-
it { is_expected.to eq("") }
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with' do
|
34
|
-
let(:string ) { "WARN. \x1b[1m&\x1b[0m ERR. \x1b[7m&\x1b[0m" }
|
35
|
-
|
36
|
-
it { is_expected.to eq('WARN. & ERR. &') }
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'with escape byte' do
|
40
|
-
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
41
|
-
|
42
|
-
it { is_expected.to eq("This is a bold blue text") }
|
43
|
-
end
|
44
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal::Color, '#set' do
|
6
|
-
let(:string) { 'string' }
|
7
|
-
|
8
|
-
it 'applies green text to string' do
|
9
|
-
expect(subject.set(string, :green)).to eq("\e[32m#{string}\e[0m")
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'applies red text background to string' do
|
13
|
-
expect(subject.set(string, :on_red)).to eq("\e[41m#{string}\e[0m")
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'applies style and color to string' do
|
17
|
-
text = subject.set(string, :bold, :green)
|
18
|
-
expect(text).to eq("\e[1m\e[32m#{string}\e[0m")
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'applies style, color and background to string' do
|
22
|
-
text = subject.set(string, :bold, :green, :on_blue)
|
23
|
-
expect(text).to eq("\e[1m\e[32m\e[44m#{string}\e[0m")
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'errors for unkown color' do
|
27
|
-
expect { subject.set(string, :crimson) }.to raise_error(ArgumentError)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Terminal, '#size' do
|
6
|
-
let(:default_width) { 80 }
|
7
|
-
let(:default_height) { 24 }
|
8
|
-
|
9
|
-
it { is_expected.to be_instance_of(described_class) }
|
10
|
-
|
11
|
-
it { is_expected.to respond_to(:width) }
|
12
|
-
|
13
|
-
it { is_expected.to respond_to(:height) }
|
14
|
-
|
15
|
-
|
16
|
-
subject(:terminal) { described_class.new }
|
17
|
-
|
18
|
-
it { expect(terminal.default_width).to eq(default_width) }
|
19
|
-
|
20
|
-
it { expect(subject.default_height).to eq(default_height) }
|
21
|
-
|
22
|
-
context '#width' do
|
23
|
-
it 'reads the env variable' do
|
24
|
-
allow(ENV).to receive(:[]).with('TTY_COLUMNS').and_return('100')
|
25
|
-
expect(subject.width).to eq(100)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'is not unix system' do
|
29
|
-
allow(TTY::System).to receive(:unix?) { false }
|
30
|
-
expect(subject).to receive(:default_width)
|
31
|
-
subject.width
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'is unix system' do
|
35
|
-
allow(TTY::System).to receive(:unix?) { true }
|
36
|
-
expect(subject).to receive(:dynamic_width) { default_width }
|
37
|
-
expect(subject.width).to eq(80)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'cannot determine width' do
|
41
|
-
allow(ENV).to receive(:[]) { raise }
|
42
|
-
expect(terminal).to receive(:default_width) { default_width }
|
43
|
-
expect(terminal.width).to eq(default_width)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context '#height' do
|
48
|
-
it 'sets the env variable' do
|
49
|
-
allow(ENV).to receive(:[]).with('TTY_LINES').and_return('50')
|
50
|
-
expect(subject.height).to eq(50)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'is not unix system' do
|
54
|
-
allow(TTY::System).to receive(:unix?) { false }
|
55
|
-
expect(subject).to receive(:default_height) { default_height }
|
56
|
-
expect(subject.height).to eq(default_height)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'is unix system' do
|
60
|
-
allow(TTY::System).to receive(:unix?) { true }
|
61
|
-
expect(subject).to receive(:dynamic_height) { default_height }
|
62
|
-
expect(subject.height).to eq(default_height)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'cannot determine width' do
|
66
|
-
allow(ENV).to receive(:[]) { raise }
|
67
|
-
expect(subject).to receive(:default_height)
|
68
|
-
subject.height
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context '#dynamic_width' do
|
73
|
-
it 'uses stty' do
|
74
|
-
expect(subject).to receive(:dynamic_width_stty) { 100 }
|
75
|
-
expect(subject.dynamic_width).to eq(100)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'uses tput' do
|
79
|
-
allow(subject).to receive(:dynamic_width_stty).and_return(0)
|
80
|
-
expect(subject).to receive(:dynamic_width_tput) { 100 }
|
81
|
-
expect(subject.dynamic_width).to eq(100)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context '#dynamic_height' do
|
86
|
-
it 'uses stty' do
|
87
|
-
allow(subject).to receive(:dynamic_height_stty) { 100 }
|
88
|
-
expect(subject.dynamic_height).to eq(100)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'uses tput' do
|
92
|
-
allow(subject).to receive(:dynamic_height_stty).and_return(0)
|
93
|
-
expect(subject).to receive(:dynamic_height_tput) { 100 }
|
94
|
-
expect(subject.dynamic_height).to eq(100)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|