tty 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -7
- data/CHANGELOG.md +6 -0
- data/Gemfile +18 -1
- data/README.md +55 -28
- data/Rakefile +5 -9
- data/images/tty.png +0 -0
- data/lib/tty.rb +7 -1
- data/lib/tty/coercer/boolean.rb +6 -9
- data/lib/tty/coercer/float.rb +14 -17
- data/lib/tty/coercer/integer.rb +14 -17
- data/lib/tty/coercer/range.rb +6 -7
- data/lib/tty/logger.rb +23 -9
- data/lib/tty/plugins.rb +3 -6
- data/lib/tty/plugins/plugin.rb +4 -7
- data/lib/tty/shell.rb +20 -12
- data/lib/tty/shell/question.rb +41 -48
- data/lib/tty/shell/question/modifier.rb +5 -8
- data/lib/tty/shell/question/validation.rb +8 -7
- data/lib/tty/shell/reader.rb +28 -19
- data/lib/tty/shell/response.rb +26 -22
- data/lib/tty/shell/statement.rb +13 -9
- data/lib/tty/shell/suggestion.rb +17 -13
- data/lib/tty/support/coercion.rb +5 -6
- data/lib/tty/support/conversion.rb +7 -6
- data/lib/tty/support/delegatable.rb +5 -5
- data/lib/tty/support/unicode.rb +3 -4
- data/lib/tty/support/utils.rb +1 -2
- data/lib/tty/system.rb +13 -6
- data/lib/tty/system/editor.rb +21 -18
- data/lib/tty/system/which.rb +3 -5
- data/lib/tty/table.rb +18 -22
- data/lib/tty/table/border.rb +2 -4
- data/lib/tty/table/border/ascii.rb +3 -2
- data/lib/tty/table/border/null.rb +1 -3
- data/lib/tty/table/border/row_line.rb +1 -4
- data/lib/tty/table/border/unicode.rb +3 -2
- data/lib/tty/table/border_dsl.rb +21 -17
- data/lib/tty/table/border_options.rb +6 -5
- data/lib/tty/table/column_set.rb +11 -7
- data/lib/tty/table/columns.rb +19 -16
- data/lib/tty/table/error.rb +1 -3
- data/lib/tty/table/field.rb +30 -12
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/indentation.rb +1 -3
- data/lib/tty/table/operation/alignment.rb +8 -9
- data/lib/tty/table/operation/alignment_set.rb +6 -5
- data/lib/tty/table/operation/escape.rb +3 -3
- data/lib/tty/table/operation/filter.rb +3 -4
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -4
- data/lib/tty/table/operations.rb +19 -22
- data/lib/tty/table/orientation.rb +5 -5
- data/lib/tty/table/orientation/horizontal.rb +9 -6
- data/lib/tty/table/orientation/vertical.rb +10 -7
- data/lib/tty/table/padder.rb +46 -8
- data/lib/tty/table/renderer.rb +21 -14
- data/lib/tty/table/renderer/ascii.rb +6 -5
- data/lib/tty/table/renderer/basic.rb +18 -19
- data/lib/tty/table/renderer/unicode.rb +11 -5
- data/lib/tty/table/row.rb +36 -20
- data/lib/tty/table/transformation.rb +6 -5
- data/lib/tty/table/validatable.rb +32 -17
- data/lib/tty/terminal.rb +26 -42
- data/lib/tty/terminal/color.rb +10 -12
- data/lib/tty/terminal/echo.rb +4 -7
- data/lib/tty/terminal/home.rb +3 -10
- data/lib/tty/terminal/pager.rb +11 -10
- data/lib/tty/terminal/pager/basic.rb +3 -6
- data/lib/tty/terminal/pager/system.rb +2 -5
- data/lib/tty/text.rb +7 -10
- data/lib/tty/text/distance.rb +2 -4
- data/lib/tty/text/truncation.rb +1 -3
- data/lib/tty/text/wrapping.rb +1 -3
- data/lib/tty/vector.rb +3 -5
- data/lib/tty/version.rb +2 -2
- data/spec/spec_helper.rb +4 -11
- data/spec/tty/coercer/boolean/coerce_spec.rb +19 -16
- data/spec/tty/coercer/float/coerce_spec.rb +6 -4
- data/spec/tty/coercer/integer/coerce_spec.rb +5 -4
- data/spec/tty/coercer/range/coerce_spec.rb +12 -11
- data/spec/tty/logger/log_spec.rb +23 -0
- data/spec/tty/logger/new_spec.rb +14 -14
- data/spec/tty/logger/valid_level_spec.rb +6 -6
- data/spec/tty/plugins/find_spec.rb +4 -4
- data/spec/tty/plugins/load_spec.rb +4 -5
- data/spec/tty/plugins/plugin/load_spec.rb +10 -8
- data/spec/tty/plugins/plugin/new_spec.rb +7 -7
- data/spec/tty/shell/ask_spec.rb +6 -7
- data/spec/tty/shell/error_spec.rb +1 -2
- data/spec/tty/shell/print_table_spec.rb +1 -2
- data/spec/tty/shell/question/argument_spec.rb +1 -1
- data/spec/tty/shell/question/character_spec.rb +11 -3
- data/spec/tty/shell/question/default_spec.rb +3 -3
- data/spec/tty/shell/question/in_spec.rb +1 -1
- data/spec/tty/shell/question/initialize_spec.rb +8 -11
- data/spec/tty/shell/question/modifier/apply_to_spec.rb +8 -4
- data/spec/tty/shell/question/modifier/letter_case_spec.rb +4 -4
- data/spec/tty/shell/question/modifier/whitespace_spec.rb +5 -5
- data/spec/tty/shell/question/modify_spec.rb +1 -1
- data/spec/tty/shell/question/valid_spec.rb +4 -4
- data/spec/tty/shell/question/validate_spec.rb +4 -4
- data/spec/tty/shell/question/validation/coerce_spec.rb +2 -3
- data/spec/tty/shell/question/validation/valid_value_spec.rb +3 -3
- data/spec/tty/shell/reader/getc_spec.rb +16 -14
- data/spec/tty/shell/response/read_bool_spec.rb +1 -1
- data/spec/tty/shell/response/read_char_spec.rb +1 -2
- data/spec/tty/shell/response/read_date_spec.rb +1 -1
- data/spec/tty/shell/response/read_email_spec.rb +1 -1
- data/spec/tty/shell/response/read_multiple_spec.rb +3 -4
- data/spec/tty/shell/response/read_number_spec.rb +1 -2
- data/spec/tty/shell/response/read_range_spec.rb +2 -2
- data/spec/tty/shell/response/read_spec.rb +7 -7
- data/spec/tty/shell/response/read_string_spec.rb +2 -2
- data/spec/tty/shell/say_spec.rb +1 -1
- data/spec/tty/shell/statement/initialize_spec.rb +3 -3
- data/spec/tty/shell/suggest_spec.rb +1 -1
- data/spec/tty/shell/warn_spec.rb +1 -2
- data/spec/tty/support/coercion_spec.rb +10 -10
- data/spec/tty/support/conversion_spec.rb +9 -9
- data/spec/tty/support/delegatable_spec.rb +7 -5
- data/spec/tty/support/equatable_spec.rb +32 -34
- data/spec/tty/support/fixtures/classes.rb +4 -2
- data/spec/tty/system/editor/available_spec.rb +12 -12
- data/spec/tty/system/editor/build_spec.rb +8 -16
- data/spec/tty/system/editor/command_spec.rb +3 -2
- data/spec/tty/system/editor/executables_spec.rb +3 -3
- data/spec/tty/system/editor/invoke_spec.rb +10 -14
- data/spec/tty/system/editor/open_spec.rb +9 -7
- data/spec/tty/system/platform_spec.rb +32 -13
- data/spec/tty/system/which/which_spec.rb +9 -9
- data/spec/tty/system/which_spec.rb +4 -4
- data/spec/tty/table/access_spec.rb +24 -21
- data/spec/tty/table/add_row_spec.rb +2 -2
- data/spec/tty/table/border/ascii/rendering_spec.rb +13 -13
- data/spec/tty/table/border/new_spec.rb +5 -4
- data/spec/tty/table/border/null/rendering_spec.rb +12 -12
- data/spec/tty/table/border/options/from_spec.rb +2 -3
- data/spec/tty/table/border/options/new_spec.rb +4 -5
- data/spec/tty/table/border/unicode/rendering_spec.rb +10 -10
- data/spec/tty/table/border_options/new_spec.rb +20 -0
- data/spec/tty/table/border_options/update_spec.rb +18 -0
- data/spec/tty/table/column_set/extract_widths_spec.rb +1 -1
- data/spec/tty/table/column_set/total_width_spec.rb +2 -2
- data/spec/tty/table/column_set/widths_from_spec.rb +1 -2
- data/spec/tty/table/columns/enforce_spec.rb +2 -2
- data/spec/tty/table/columns/widths_spec.rb +2 -0
- data/spec/tty/table/data_spec.rb +3 -3
- data/spec/tty/table/each_spec.rb +9 -11
- data/spec/tty/table/each_with_index_spec.rb +8 -9
- data/spec/tty/table/empty_spec.rb +3 -3
- data/spec/tty/table/eql_spec.rb +6 -6
- data/spec/tty/table/field/equality_spec.rb +11 -11
- data/spec/tty/table/field/length_spec.rb +4 -4
- data/spec/tty/table/field/lines_spec.rb +3 -3
- data/spec/tty/table/field/new_spec.rb +7 -7
- data/spec/tty/table/field/width_spec.rb +6 -4
- data/spec/tty/table/filter_spec.rb +3 -3
- data/spec/tty/table/header/call_spec.rb +3 -3
- data/spec/tty/table/header/height_spec.rb +1 -1
- data/spec/tty/table/header/new_spec.rb +5 -5
- data/spec/tty/table/header/set_spec.rb +9 -4
- data/spec/tty/table/header/to_ary_spec.rb +4 -4
- data/spec/tty/table/header_spec.rb +3 -4
- data/spec/tty/table/indentation/insert_indent_spec.rb +1 -1
- data/spec/tty/table/initialize_spec.rb +13 -13
- data/spec/tty/table/operation/alignment/format_spec.rb +5 -5
- data/spec/tty/table/operation/alignment/new_spec.rb +4 -4
- data/spec/tty/table/operation/alignment_set/call_spec.rb +11 -11
- data/spec/tty/table/operation/alignment_set/each_spec.rb +3 -3
- data/spec/tty/table/operation/alignment_set/new_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/to_ary_spec.rb +4 -4
- data/spec/tty/table/operation/escape/call_spec.rb +1 -1
- data/spec/tty/table/operation/filter/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/call_spec.rb +1 -1
- data/spec/tty/table/operation/truncation/truncate_spec.rb +4 -4
- data/spec/tty/table/operation/wrapped/call_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +3 -3
- data/spec/tty/table/operations/new_spec.rb +1 -1
- data/spec/tty/table/options_spec.rb +8 -8
- data/spec/tty/table/orientation_spec.rb +15 -13
- data/spec/tty/table/padder/parse_spec.rb +1 -1
- data/spec/tty/table/padder/to_s_spec.rb +14 -0
- data/spec/tty/table/padding_spec.rb +1 -1
- data/spec/tty/table/properties_spec.rb +9 -8
- data/spec/tty/table/render_spec.rb +8 -5
- data/spec/tty/table/render_with_spec.rb +5 -4
- data/spec/tty/table/renderer/ascii/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/render_spec.rb +7 -7
- data/spec/tty/table/renderer/ascii/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/ascii/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +5 -5
- data/spec/tty/table/renderer/basic/coloring_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +6 -6
- data/spec/tty/table/renderer/basic/filter_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/indentation_spec.rb +5 -3
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +10 -10
- data/spec/tty/table/renderer/basic/new_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +9 -9
- data/spec/tty/table/renderer/basic/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/render_spec.rb +8 -8
- data/spec/tty/table/renderer/basic/resizing_spec.rb +1 -1
- data/spec/tty/table/renderer/basic/separator_spec.rb +2 -2
- data/spec/tty/table/renderer/basic/truncation_spec.rb +4 -4
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +4 -4
- data/spec/tty/table/renderer/border_spec.rb +21 -21
- data/spec/tty/table/renderer/render_spec.rb +7 -7
- data/spec/tty/table/renderer/select_spec.rb +4 -4
- data/spec/tty/table/renderer/style_spec.rb +19 -19
- data/spec/tty/table/renderer/unicode/indentation_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/padding_spec.rb +1 -1
- data/spec/tty/table/renderer/unicode/render_spec.rb +6 -6
- data/spec/tty/table/renderer/unicode/separator_spec.rb +2 -2
- data/spec/tty/table/renderer_spec.rb +1 -1
- data/spec/tty/table/rotate_spec.rb +27 -27
- data/spec/tty/table/row/access_spec.rb +3 -3
- data/spec/tty/table/row/call_spec.rb +4 -4
- data/spec/tty/table/row/data_spec.rb +5 -5
- data/spec/tty/table/row/each_spec.rb +1 -1
- data/spec/tty/table/row/equality_spec.rb +16 -16
- data/spec/tty/table/row/height_spec.rb +1 -1
- data/spec/tty/table/row/new_spec.rb +11 -11
- data/spec/tty/table/row/to_ary_spec.rb +3 -3
- data/spec/tty/table/to_s_spec.rb +8 -8
- data/spec/tty/table/validatable/validate_options_spec.rb +5 -5
- data/spec/tty/table/validatable_spec.rb +14 -1
- data/spec/tty/terminal/color/code_spec.rb +3 -3
- data/spec/tty/terminal/color/remove_spec.rb +8 -9
- data/spec/tty/terminal/color/set_spec.rb +5 -6
- data/spec/tty/terminal/color_spec.rb +3 -5
- data/spec/tty/terminal/echo_spec.rb +3 -4
- data/spec/tty/terminal/home_spec.rb +12 -14
- data/spec/tty/terminal/page_spec.rb +5 -4
- data/spec/tty/terminal/pager/available_spec.rb +11 -11
- data/spec/tty/terminal/pager/basic/page_spec.rb +8 -8
- data/spec/tty/terminal/pager/command_spec.rb +2 -2
- data/spec/tty/terminal/pager/executables_spec.rb +3 -3
- data/spec/tty/terminal/pager/page_spec.rb +8 -10
- data/spec/tty/terminal/pager/system/page_spec.rb +8 -8
- data/spec/tty/terminal/size_spec.rb +39 -36
- data/spec/tty/text/distance/distance_spec.rb +13 -13
- data/spec/tty/text/distance/initialize_spec.rb +4 -4
- data/spec/tty/text/distance_spec.rb +2 -2
- data/spec/tty/text/truncate_spec.rb +2 -3
- data/spec/tty/text/truncation/initialize_spec.rb +9 -9
- data/spec/tty/text/truncation/truncate_spec.rb +14 -14
- data/spec/tty/text/wrap_spec.rb +2 -3
- data/spec/tty/text/wrapping/initialize_spec.rb +7 -7
- data/spec/tty/text/wrapping/wrap_spec.rb +11 -11
- data/spec/tty/tty_spec.rb +22 -0
- data/spec/tty/vector/new_spec.rb +7 -7
- data/tasks/console.rake +10 -0
- data/tasks/coverage.rake +11 -0
- data/tasks/metrics/cane.rake +2 -0
- data/tasks/metrics/flog.rake +2 -0
- data/tasks/metrics/heckle.rake +15 -0
- data/tasks/metrics/reek.rake +2 -0
- data/tasks/spec.rake +29 -0
- data/tty.gemspec +5 -12
- metadata +34 -91
- data/.rvmrc +0 -34
@@ -1,10 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Table::Validatable do
|
6
6
|
let(:described_class) { Class.new { include TTY::Table::Validatable } }
|
7
7
|
let(:rows) { [['a1', 'a2'], ['b1']] }
|
8
|
+
|
8
9
|
subject { described_class.new }
|
9
10
|
|
10
11
|
it 'raises no exception' do
|
@@ -16,4 +17,16 @@ describe TTY::Table::Validatable do
|
|
16
17
|
expect { subject.assert_row_sizes(rows) }.
|
17
18
|
to raise_error(TTY::Table::DimensionMismatchError)
|
18
19
|
end
|
20
|
+
|
21
|
+
it "raises exception when :header key has wrong data type" do
|
22
|
+
options = {header: 'h1'}
|
23
|
+
expect { subject.validate_options!(options) }.
|
24
|
+
to raise_error(TTY::InvalidArgument)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises exception when :rows key has wrong data type" do
|
28
|
+
options = {rows: 'a1'}
|
29
|
+
expect { subject.validate_options!(options) }.
|
30
|
+
to raise_error(TTY::InvalidArgument)
|
31
|
+
end
|
19
32
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,11 +6,11 @@ describe TTY::Terminal::Color, '#code' do
|
|
6
6
|
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
7
7
|
|
8
8
|
it 'finds single code' do
|
9
|
-
subject.code(:black).
|
9
|
+
expect(subject.code(:black)).to eq(["\e[30m"])
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'finds more than one code' do
|
13
|
-
subject.code(:black, :green).
|
13
|
+
expect(subject.code(:black, :green)).to eq(["\e[30m", "\e[32m"])
|
14
14
|
end
|
15
15
|
|
16
16
|
it "doesn't find code" do
|
@@ -1,45 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Terminal::Color, '#remove' do
|
6
6
|
let(:instance) { described_class.new }
|
7
|
-
|
8
|
-
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
7
|
+
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
9
8
|
|
10
9
|
subject { instance.remove string }
|
11
10
|
|
12
11
|
it 'remove color from string' do
|
13
|
-
|
12
|
+
is_expected.to eq("This is a bold blue text")
|
14
13
|
end
|
15
14
|
|
16
15
|
context 'with octal in encapsulating brackets' do
|
17
16
|
let(:string) { "\[\033[01;32m\]u@h \[\033[01;34m\]W $ \[\033[00m\]" }
|
18
17
|
|
19
|
-
it {
|
18
|
+
it { is_expected.to eq('u@h W $ ') }
|
20
19
|
end
|
21
20
|
|
22
21
|
context 'with octal without brackets' do
|
23
22
|
let(:string) { "\033[01;32mu@h \033[01;34mW $ \033[00m" }
|
24
23
|
|
25
|
-
it {
|
24
|
+
it { is_expected.to eq('u@h W $ ') }
|
26
25
|
end
|
27
26
|
|
28
27
|
context 'with octal with multiple colors' do
|
29
28
|
let(:string) { "\e[3;0;0;t\e[8;50;0t" }
|
30
29
|
|
31
|
-
it {
|
30
|
+
it { is_expected.to eq("") }
|
32
31
|
end
|
33
32
|
|
34
33
|
context 'with' do
|
35
34
|
let(:string ) { "WARN. \x1b[1m&\x1b[0m ERR. \x1b[7m&\x1b[0m" }
|
36
35
|
|
37
|
-
it {
|
36
|
+
it { is_expected.to eq('WARN. & ERR. &') }
|
38
37
|
end
|
39
38
|
|
40
39
|
context 'with escape byte' do
|
41
40
|
let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
|
42
41
|
|
43
|
-
it {
|
42
|
+
it { is_expected.to eq("This is a bold blue text") }
|
44
43
|
end
|
45
44
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -6,25 +6,24 @@ describe TTY::Terminal::Color, '#set' do
|
|
6
6
|
let(:string) { 'string' }
|
7
7
|
|
8
8
|
it 'applies green text to string' do
|
9
|
-
subject.set(string, :green).
|
9
|
+
expect(subject.set(string, :green)).to eq("\e[32m#{string}\e[0m")
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'applies red text background to string' do
|
13
|
-
subject.set(string, :on_red).
|
13
|
+
expect(subject.set(string, :on_red)).to eq("\e[41m#{string}\e[0m")
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'applies style and color to string' do
|
17
17
|
text = subject.set(string, :bold, :green)
|
18
|
-
text.
|
18
|
+
expect(text).to eq("\e[1m\e[32m#{string}\e[0m")
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'applies style, color and background to string' do
|
22
22
|
text = subject.set(string, :bold, :green, :on_blue)
|
23
|
-
text.
|
23
|
+
expect(text).to eq("\e[1m\e[32m\e[44m#{string}\e[0m")
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'errors for unkown color' do
|
27
27
|
expect { subject.set(string, :crimson) }.to raise_error(ArgumentError)
|
28
28
|
end
|
29
|
-
|
30
29
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Terminal, '#color' do
|
6
6
|
|
7
|
-
it {
|
8
|
-
|
9
|
-
its(:color) { should be_kind_of TTY::Terminal::Color}
|
7
|
+
it { expect(subject.color).to be_a(TTY::Terminal::Color) }
|
10
8
|
|
11
9
|
it 'delegates color handling' do
|
12
10
|
string = 'text'
|
13
|
-
subject.color.set(string, :red).
|
11
|
+
expect(subject.color.set(string, :red)).to eq("\e[31m#{string}\e[0m")
|
14
12
|
end
|
15
13
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -10,13 +10,12 @@ describe TTY::Terminal, '#echo' do
|
|
10
10
|
context 'without block' do
|
11
11
|
let(:block) { }
|
12
12
|
|
13
|
-
it {
|
13
|
+
it { is_expected.to be_nil }
|
14
14
|
end
|
15
15
|
|
16
16
|
context 'with empty block' do
|
17
17
|
let(:block) { lambda { '' } }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to eq('') }
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
@@ -1,37 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Terminal, '#home' do
|
6
|
+
subject(:terminal) { described_class.new }
|
6
7
|
|
7
|
-
before { ENV.
|
8
|
-
|
9
|
-
subject(:terminal) { described_class.new.home }
|
8
|
+
before { allow(ENV).to receive(:[]) }
|
10
9
|
|
11
10
|
after { terminal.instance_variable_set(:@home, nil) }
|
12
11
|
|
13
12
|
it 'expands user home path if HOME environemnt not set' do
|
14
|
-
File.
|
15
|
-
expect(terminal).to eql('/home/user')
|
13
|
+
allow(File).to receive(:expand_path).and_return('/home/user')
|
14
|
+
expect(terminal.home).to eql('/home/user')
|
16
15
|
end
|
17
16
|
|
18
17
|
it 'defaults to user HOME environment' do
|
19
|
-
ENV.
|
20
|
-
expect(terminal).to eq('/home/user')
|
18
|
+
allow(ENV).to receive(:[]).with('HOME').and_return('/home/user')
|
19
|
+
expect(terminal.home).to eq('/home/user')
|
21
20
|
end
|
22
21
|
|
23
22
|
context 'when failed to expand' do
|
24
|
-
before { File.
|
23
|
+
before { allow(File).to receive(:expand_path).and_raise(RuntimeError) }
|
25
24
|
|
26
25
|
it 'returns C:/ on windows' do
|
27
|
-
TTY::System.
|
28
|
-
expect(terminal).to eql("C:/")
|
26
|
+
allow(TTY::System).to receive(:windows?).and_return(true)
|
27
|
+
expect(terminal.home).to eql("C:/")
|
29
28
|
end
|
30
29
|
|
31
30
|
it 'returns root on unix' do
|
32
|
-
TTY::System.
|
33
|
-
expect(terminal).to eql("/")
|
31
|
+
allow(TTY::System).to receive(:windows?).and_return(false)
|
32
|
+
expect(terminal.home).to eql("/")
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
@@ -1,13 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Terminal, '#page' do
|
6
6
|
let(:text) { "a\n"}
|
7
|
-
|
7
|
+
|
8
|
+
subject(:terminal) { described_class.new }
|
8
9
|
|
9
10
|
it 'invokes pager page method' do
|
10
|
-
|
11
|
-
|
11
|
+
expect(terminal.pager).to receive(:page).with(text)
|
12
|
+
terminal.page(text)
|
12
13
|
end
|
13
14
|
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Terminal::Pager, '#available' do
|
6
|
-
let(:execs)
|
7
|
-
let(:system)
|
6
|
+
let(:execs) { ['less', 'more'] }
|
7
|
+
let(:system) { TTY::System }
|
8
8
|
let(:command) { 'less' }
|
9
9
|
|
10
|
-
subject { described_class }
|
10
|
+
subject(:pager) { described_class }
|
11
11
|
|
12
|
-
before { subject.
|
12
|
+
before { allow(subject).to receive(:executables).and_return(execs) }
|
13
13
|
|
14
14
|
context 'when command exists' do
|
15
15
|
before {
|
16
|
-
system.
|
17
|
-
system.
|
16
|
+
allow(system).to receive(:exists?).with('less').and_return(true)
|
17
|
+
allow(system).to receive(:exists?).with('more').and_return(false)
|
18
18
|
}
|
19
19
|
|
20
20
|
it 'finds single command' do
|
21
|
-
expect(
|
21
|
+
expect(pager.available).to eql('less')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when no command exists' do
|
26
|
-
before { system.
|
26
|
+
before { allow(system).to receive(:exists?).and_return(false) }
|
27
27
|
|
28
28
|
it "doesn't find command" do
|
29
|
-
expect(
|
29
|
+
expect(pager.available).to be_nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'when custom command' do
|
34
|
-
before { system.
|
34
|
+
before { allow(system).to receive(:exists?).with(command).and_return(true) }
|
35
35
|
|
36
36
|
it "takes precedence over other commands" do
|
37
37
|
expect(subject.available(command)).to eql(command)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,18 +9,18 @@ describe TTY::Terminal::BasicPager, '#simple' do
|
|
9
9
|
let(:terminal) { TTY.terminal }
|
10
10
|
let(:object) { described_class }
|
11
11
|
|
12
|
-
subject { object.new(text) }
|
12
|
+
subject(:pager) { object.new(text) }
|
13
13
|
|
14
14
|
before {
|
15
|
-
TTY.
|
16
|
-
terminal.
|
15
|
+
allow(TTY).to receive(:shell).and_return(shell)
|
16
|
+
allow(terminal).to receive(:height).and_return(10)
|
17
17
|
}
|
18
18
|
|
19
19
|
context 'when no text' do
|
20
20
|
let(:text) { "" }
|
21
21
|
|
22
22
|
it "doesn't page text" do
|
23
|
-
|
23
|
+
pager.page
|
24
24
|
expect(output.string).to eql(text)
|
25
25
|
end
|
26
26
|
end
|
@@ -29,7 +29,7 @@ describe TTY::Terminal::BasicPager, '#simple' do
|
|
29
29
|
let(:text) { "a\n" }
|
30
30
|
|
31
31
|
it "doesn't page text not long enough" do
|
32
|
-
|
32
|
+
pager.page
|
33
33
|
expect(output.string).to eql(text)
|
34
34
|
end
|
35
35
|
end
|
@@ -40,14 +40,14 @@ describe TTY::Terminal::BasicPager, '#simple' do
|
|
40
40
|
it "continues paging when enter is pressed" do
|
41
41
|
input << '\n'
|
42
42
|
input.rewind
|
43
|
-
|
43
|
+
pager.page
|
44
44
|
expect(output.string).to eql("a\na\na\na\na\na\na\n\n#{object::PAGE_BREAK}\na\na\na\n")
|
45
45
|
end
|
46
46
|
|
47
47
|
it "stops paging when q is pressed" do
|
48
48
|
input << 'q\n'
|
49
49
|
input.rewind
|
50
|
-
|
50
|
+
pager.page
|
51
51
|
expect(output.string).to eql("a\na\na\na\na\na\na\n\n#{object::PAGE_BREAK}\n")
|
52
52
|
end
|
53
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,7 +9,7 @@ describe TTY::Terminal::Pager, '#command' do
|
|
9
9
|
|
10
10
|
context 'when custom command' do
|
11
11
|
it 'searches available commands' do
|
12
|
-
subject.
|
12
|
+
expect(subject).to receive(:available).with(pager)
|
13
13
|
subject.command(pager)
|
14
14
|
end
|
15
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -7,7 +7,7 @@ describe TTY::Terminal::Pager, '#executables' do
|
|
7
7
|
|
8
8
|
subject { object.executables }
|
9
9
|
|
10
|
-
it {
|
10
|
+
it { is_expected.to be_an(Array) }
|
11
11
|
|
12
|
-
it {
|
12
|
+
it { is_expected.to include('less -isr') }
|
13
13
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -12,10 +12,10 @@ describe TTY::Terminal::Pager, '#page' do
|
|
12
12
|
|
13
13
|
subject { described_class }
|
14
14
|
|
15
|
-
before { shell.
|
15
|
+
before { allow(shell).to receive(:tty?).and_return(true) }
|
16
16
|
|
17
17
|
context 'when not tty' do
|
18
|
-
before { shell.
|
18
|
+
before { allow(shell).to receive(:tty?).and_return(false) }
|
19
19
|
|
20
20
|
it "doesn't page" do
|
21
21
|
expect(subject.page(text)).to eql(nil)
|
@@ -23,24 +23,22 @@ describe TTY::Terminal::Pager, '#page' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'when not unix' do
|
26
|
-
before {
|
27
|
-
system.stub(:unix?).and_return(false)
|
28
|
-
}
|
26
|
+
before { allow(system).to receive(:unix?).and_return(false) }
|
29
27
|
|
30
28
|
it 'pages with simple pager' do
|
31
|
-
basic_pager.
|
29
|
+
expect(basic_pager).to receive(:new).with(text).and_return(pager)
|
32
30
|
subject.page(text)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
context 'when unix and available' do
|
37
35
|
before {
|
38
|
-
system.
|
39
|
-
subject.
|
36
|
+
allow(system).to receive(:unix?).and_return(true)
|
37
|
+
allow(subject).to receive(:available?).and_return(true)
|
40
38
|
}
|
41
39
|
|
42
40
|
it 'pages with system pager' do
|
43
|
-
system_pager.
|
41
|
+
expect(system_pager).to receive(:new).with(text).and_return(pager)
|
44
42
|
subject.page(text)
|
45
43
|
end
|
46
44
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -9,21 +9,21 @@ describe TTY::Terminal::SystemPager, '#simple' do
|
|
9
9
|
let(:terminal) { TTY.terminal }
|
10
10
|
let(:object) { described_class }
|
11
11
|
|
12
|
-
subject { object.new(text) }
|
12
|
+
subject(:pager) { object.new(text) }
|
13
13
|
|
14
14
|
before {
|
15
|
-
TTY.
|
16
|
-
IO.
|
17
|
-
Kernel.
|
15
|
+
allow(TTY).to receive(:shell).and_return(shell)
|
16
|
+
allow(IO).to receive(:pipe).and_return([input, output])
|
17
|
+
allow(Kernel).to receive(:fork) { true }
|
18
18
|
}
|
19
19
|
|
20
20
|
context 'when text fits on screen' do
|
21
21
|
let(:text) { "a\na\na\na\na\na\na\na\na\na\n" }
|
22
22
|
|
23
23
|
it "doesn't page text not long enough" do
|
24
|
-
Kernel.
|
25
|
-
Kernel.
|
26
|
-
|
24
|
+
expect(Kernel).to receive(:exec)
|
25
|
+
expect(Kernel).to receive(:select)
|
26
|
+
pager.page
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|