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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ff8d55e968e3331ebf153894ccbf0a049298bc6
|
4
|
+
data.tar.gz: 5cfbe8e57e25a74cb855e1501ce3c18c0a7b16b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb5e763c659e1b78d82e179e4a25df354b7ab9939d99effe637044d5e27e0b9400025bb2bae37eeb9e350ae1f176a6b2b4227224f467d8ba8a6236cb67a80bbc
|
7
|
+
data.tar.gz: 138c0a16a982220b62b0859bbf19bef558e3a14978cbd1dcd3a57d7b706541cbafed1ffc2d6867c8c36797de30dd273a468d270c55d9268ae25d2a4694abc176
|
data/.rspec
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
tty
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/.travis.yml
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
|
2
|
+
bundler_args: --without yard guard benchmarks
|
3
|
+
script: "bundle exec rake ci"
|
4
4
|
rvm:
|
5
5
|
- 1.9.3
|
6
6
|
- 2.0.0
|
7
|
+
- 2.1.0
|
7
8
|
- ruby-head
|
8
|
-
- jruby-19mode
|
9
|
-
- rbx-19mode
|
10
|
-
- jruby-head
|
11
|
-
- rbx-head
|
12
9
|
matrix:
|
10
|
+
include:
|
11
|
+
- rvm: jruby-19mode
|
12
|
+
- rvm: jruby-20mode
|
13
|
+
- rvm: jruby-21mode
|
14
|
+
- rvm: jruby-head
|
15
|
+
- rvm: rbx-2
|
13
16
|
allow_failures:
|
17
|
+
- rvm: jruby-20mode
|
18
|
+
- rvm: jruby-21mode
|
14
19
|
- rvm: ruby-head
|
15
20
|
- rvm: jruby-head
|
16
|
-
- rvm: rbx
|
21
|
+
- rvm: rbx
|
22
|
+
- rvm: rbx-2
|
23
|
+
fast_finish: true
|
24
|
+
branches:
|
25
|
+
only: master
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -1,4 +1,21 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in tty.gemspec
|
4
3
|
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'rake', '~> 10.1.0'
|
7
|
+
gem 'rspec', '~> 3.1.0'
|
8
|
+
gem 'yard', '~> 0.8.7'
|
9
|
+
gem 'timecop', '~> 0.7.1'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :metrics do
|
13
|
+
gem 'coveralls', '~> 0.7.0'
|
14
|
+
gem 'simplecov', '~> 0.8.2'
|
15
|
+
gem 'yardstick', '~> 0.9.9'
|
16
|
+
gem 'reek', '~> 1.3.7'
|
17
|
+
end
|
18
|
+
|
19
|
+
group :benchmarks do
|
20
|
+
gem 'benchmark_suite', '~> 1.0.0'
|
21
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# [![Application icon](https://github.com/peter-murach/tty/raw/master/images/tty.png)][icon]
|
2
|
+
[icon]: http://peter-murach.github.io/tty/
|
2
3
|
[![Gem Version](https://badge.fury.io/rb/tty.png)][gem]
|
3
4
|
[![Build Status](https://secure.travis-ci.org/peter-murach/tty.png?branch=master)][travis]
|
4
5
|
[![Code Climate](https://codeclimate.com/github/peter-murach/tty.png)][codeclimate]
|
@@ -9,17 +10,23 @@
|
|
9
10
|
[codeclimate]: https://codeclimate.com/github/peter-murach/tty
|
10
11
|
[coveralls]: https://coveralls.io/r/peter-murach/tty
|
11
12
|
|
12
|
-
|
13
|
+
TTY is a toolbox for developing beautiful command line clients in Ruby. It provides a fluid interface for gathering input from the user, querying system and terminal and displaying information back. It is not another command line options parser, rather a plumbing library that helps in common tasks.
|
14
|
+
|
15
|
+
## Motivation
|
16
|
+
|
17
|
+
All too often libraries that interact with command line create their own interface logic that gathers input from users and displays information back. Many times utility files are created that contain methods for reading system or terminal properties. Shouldn't we focus our energy on building the actual client?
|
18
|
+
|
19
|
+
Even more so, any command line application needs a clear way of communicating its results back to terminal whether in tabular form, column form or colorfully indented text. Our time and energy should be spent in creating the tools not the foundation.
|
13
20
|
|
14
21
|
## Features
|
15
22
|
|
16
23
|
Jump-start development of your command line app:
|
17
24
|
|
18
|
-
* Table rendering with an easy-to-use API. [status:
|
25
|
+
* Table rendering with an easy-to-use API. [status: ✔ ]
|
19
26
|
* Terminal output colorization. [status: ✔ ]
|
20
27
|
* Terminal output paging. [status: ✔ ]
|
21
|
-
* System & command detection utilities. [status:
|
22
|
-
* Text manipulation(wrapping/truncation) [status:
|
28
|
+
* System & command detection utilities. [status: ✔ ]
|
29
|
+
* Text manipulation(wrapping/truncation) [status: ✔ ]
|
23
30
|
* Shell user interface. [status: In Progress]
|
24
31
|
* File diffs. [status: TODO]
|
25
32
|
* Progress bar. [status: TODO]
|
@@ -43,9 +50,25 @@ Or install it yourself as:
|
|
43
50
|
|
44
51
|
$ gem install tty
|
45
52
|
|
53
|
+
## Contents
|
54
|
+
|
55
|
+
* [1. Table](#1-table)
|
56
|
+
* [1.1 Rendering](#11-rendering)
|
57
|
+
* [1.2 Multiline](#12-multiline)
|
58
|
+
* [1.3 Border](#13-border)
|
59
|
+
* [1.4 Alignment](#14-alignment)
|
60
|
+
* [1.5 Padding](#15-padding)
|
61
|
+
* [1.6 Filter](#16-filter)
|
62
|
+
* [1.7 Width](#17-width)
|
63
|
+
* [2. Terminal](#2-terminal)
|
64
|
+
* [2.1 Color](#21-color)
|
65
|
+
* [2.2 Pager](#22-pager)
|
66
|
+
* [3. Shell](#3-shell)
|
67
|
+
* [4. System](#4-system)
|
68
|
+
|
46
69
|
## Usage
|
47
70
|
|
48
|
-
### Table
|
71
|
+
### 1 Table
|
49
72
|
|
50
73
|
To instantiate table pass 2-dimensional array:
|
51
74
|
|
@@ -91,9 +114,9 @@ table = TTY::Table.new do |t|
|
|
91
114
|
end
|
92
115
|
```
|
93
116
|
|
94
|
-
#### Rendering
|
117
|
+
#### 1.1 Rendering
|
95
118
|
|
96
|
-
Once you have an instance of `TTY::Table` you can print it out to the stdout
|
119
|
+
Once you have an instance of `TTY::Table` you can print it out to the stdout like so:
|
97
120
|
|
98
121
|
```ruby
|
99
122
|
table.to_s
|
@@ -124,7 +147,7 @@ width # constrain the table total width, otherwise dynamically
|
|
124
147
|
# calculated from content and terminal size
|
125
148
|
```
|
126
149
|
|
127
|
-
#### Multiline
|
150
|
+
#### 1.2 Multiline
|
128
151
|
|
129
152
|
Renderer options may include `multiline` parameter. The `true` value will cause the table fields wrap at their natural line breaks or in case when the column widths are set the content will wrap.
|
130
153
|
|
@@ -154,7 +177,7 @@ table.render :ascii, multiline: false
|
|
154
177
|
+------------------+-+
|
155
178
|
```
|
156
179
|
|
157
|
-
#### Border
|
180
|
+
#### 1.3 Border
|
158
181
|
|
159
182
|
To print border around data table you need to specify `renderer` type out of `basic`, `ascii`, `unicode`. By default `basic` is used. For instance, to output unicode border:
|
160
183
|
|
@@ -239,7 +262,7 @@ table.render do |renderer|
|
|
239
262
|
end
|
240
263
|
```
|
241
264
|
|
242
|
-
#### Alignment
|
265
|
+
#### 1.4 Alignment
|
243
266
|
|
244
267
|
All columns are left aligned by default. You can enforce per column alignment by passing `column_aligns` option like so
|
245
268
|
|
@@ -265,7 +288,7 @@ table = TTY::Table.new do |t|
|
|
265
288
|
end
|
266
289
|
```
|
267
290
|
|
268
|
-
#### Padding
|
291
|
+
#### 1.5 Padding
|
269
292
|
|
270
293
|
By default padding is not applied. You can add `padding` to table fields like so
|
271
294
|
|
@@ -299,7 +322,7 @@ table.render { |renderer|
|
|
299
322
|
+-----+-------+----+---+-------+-----+
|
300
323
|
```
|
301
324
|
|
302
|
-
#### Filter
|
325
|
+
#### 1.6 Filter
|
303
326
|
|
304
327
|
You can define filters that will modify individual table fields value before they are rendered. A filter can be a callable such as proc. Here's an example that formats
|
305
328
|
|
@@ -334,7 +357,7 @@ table.render do |renderer|
|
|
334
357
|
end
|
335
358
|
```
|
336
359
|
|
337
|
-
#### Width
|
360
|
+
#### 1.7 Width
|
338
361
|
|
339
362
|
To control table's column sizes pass `width`, `resize` options. By default table's natural column widths are calculated from the content. If the total table width does not fit in terminal window then the table is rotated vertically to preserve content.
|
340
363
|
|
@@ -354,7 +377,7 @@ table.render width: 80, resize: true
|
|
354
377
|
+---------+-------+------------+
|
355
378
|
```
|
356
379
|
|
357
|
-
### Terminal
|
380
|
+
### 2 Terminal
|
358
381
|
|
359
382
|
To read general terminal properties you can use on of the helpers
|
360
383
|
|
@@ -367,6 +390,8 @@ term.echo(false) { } # switch off echo for the block
|
|
367
390
|
term.page # page terminal output, on non unix systems falls back to ruby implementation
|
368
391
|
```
|
369
392
|
|
393
|
+
#### 2.1 Color
|
394
|
+
|
370
395
|
To colorize your output do
|
371
396
|
|
372
397
|
```ruby
|
@@ -390,13 +415,15 @@ white
|
|
390
415
|
|
391
416
|
To supply background color simply prefix it with `on_`. For example a green background would be `on_green`.
|
392
417
|
|
418
|
+
#### 2.2 Pager
|
419
|
+
|
393
420
|
To page your output do
|
394
421
|
|
395
422
|
```ruby
|
396
423
|
term.page 'long text...'
|
397
424
|
```
|
398
425
|
|
399
|
-
### Shell
|
426
|
+
### 3 Shell
|
400
427
|
|
401
428
|
Main responsibility is to interact with the prompt and provide convenience methods.
|
402
429
|
|
@@ -424,16 +451,16 @@ answer = shell.ask("What is your name?").read_string
|
|
424
451
|
The library provides small DSL to help with parsing and asking precise questions
|
425
452
|
|
426
453
|
```ruby
|
427
|
-
argument
|
428
|
-
|
429
|
-
clean
|
430
|
-
default
|
431
|
-
echo
|
432
|
-
mask
|
433
|
-
modify
|
434
|
-
range
|
435
|
-
validate
|
436
|
-
valid
|
454
|
+
argument # :required or :optional
|
455
|
+
char # turn character based input, otherwise line (default: false)
|
456
|
+
clean # reset question
|
457
|
+
default # default value used if none is provided
|
458
|
+
echo # turn echo on and off (default: true)
|
459
|
+
mask # mask characters i.e '****' (default: false)
|
460
|
+
modify # apply answer modification :upcase, :downcase, :trim, :chomp etc..
|
461
|
+
range # specify range '0-9', '0..9', '0...9' or negative '-1..-9'
|
462
|
+
validate # regex against which stdin input is checked
|
463
|
+
valid # a list of expected valid options
|
437
464
|
```
|
438
465
|
|
439
466
|
You can chain question methods or configure them inside a block
|
@@ -495,7 +522,7 @@ shell.suggest('sta', ['stage', 'stash', 'commit', 'branch'])
|
|
495
522
|
stash
|
496
523
|
```
|
497
524
|
|
498
|
-
### System
|
525
|
+
### 4 System
|
499
526
|
|
500
527
|
```ruby
|
501
528
|
TTY::System.unix? # check if unix platform
|
@@ -527,4 +554,4 @@ TTY::System.editor.open('file path...')
|
|
527
554
|
|
528
555
|
## Copyright
|
529
556
|
|
530
|
-
Copyright (c) 2012-
|
557
|
+
Copyright (c) 2012-2014 Piotr Murach. See LICENSE for further details.
|
data/Rakefile
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
#
|
2
|
-
$:.unshift File.expand_path('../lib', __FILE__)
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "rspec/core/rake_task"
|
1
|
+
# encoding: utf-8
|
5
2
|
|
6
|
-
|
7
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
8
|
-
end
|
3
|
+
require "bundler/gem_tasks"
|
9
4
|
|
10
|
-
FileList['tasks/**/*.rake'].each
|
5
|
+
FileList['tasks/**/*.rake'].each(&method(:import))
|
11
6
|
|
12
|
-
|
7
|
+
desc 'Run all specs'
|
8
|
+
task ci: %w[ spec ]
|
data/images/tty.png
ADDED
Binary file
|
data/lib/tty.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'tty/version'
|
4
4
|
|
@@ -115,7 +115,12 @@ module TTY
|
|
115
115
|
EMPTY_ARRAY = Array.new.freeze
|
116
116
|
|
117
117
|
class << self
|
118
|
+
def included(base)
|
119
|
+
base.send :extend, ClassMethods
|
120
|
+
end
|
121
|
+
end
|
118
122
|
|
123
|
+
module ClassMethods
|
119
124
|
# Return shared terminal instance
|
120
125
|
#
|
121
126
|
# @return [TTY::Terminal]
|
@@ -153,4 +158,5 @@ module TTY
|
|
153
158
|
end
|
154
159
|
end
|
155
160
|
|
161
|
+
extend ClassMethods
|
156
162
|
end # TTY
|
data/lib/tty/coercer/boolean.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Coercer
|
5
|
-
|
6
5
|
# A class responsible for boolean type coercion
|
7
6
|
class Boolean
|
8
|
-
|
9
7
|
# Coerce value to boolean type including range of strings such as
|
10
8
|
#
|
11
9
|
# @param [Object] value
|
@@ -16,7 +14,8 @@ module TTY
|
|
16
14
|
# other values coerced to true are:
|
17
15
|
# 1, t, T, TRUE, true, True, y, Y, YES, yes, Yes
|
18
16
|
#
|
19
|
-
#
|
17
|
+
# @example
|
18
|
+
# coerce("False") # => false
|
20
19
|
#
|
21
20
|
# other values coerced to false are:
|
22
21
|
# 0, f, F, FALSE, false, False, n, N, No, no, No
|
@@ -24,16 +23,14 @@ module TTY
|
|
24
23
|
# @api public
|
25
24
|
def self.coerce(value)
|
26
25
|
case value.to_s
|
27
|
-
when
|
26
|
+
when /^(yes|y|t(rue)?|1)$/i
|
28
27
|
return true
|
29
|
-
when
|
28
|
+
when /^(no|n|f(alse)?|0)$/i
|
30
29
|
return false
|
31
30
|
else
|
32
|
-
|
31
|
+
fail TypeError, "Expected boolean type, got #{value}"
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
34
|
end # Boolean
|
37
|
-
|
38
35
|
end # Coercer
|
39
36
|
end # TTY
|
data/lib/tty/coercer/float.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Coercer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
5
|
+
# Coerce values into float number
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
class Float
|
9
|
+
def self.coerce(value, strict = true)
|
10
|
+
Kernel.send(:Float, value.to_s)
|
11
|
+
rescue
|
12
|
+
if strict
|
13
|
+
raise InvalidArgument, "#{value} could not be coerced into Float"
|
14
|
+
else
|
15
|
+
value.to_f
|
18
16
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
end
|
18
|
+
end # Float
|
22
19
|
end # Coercer
|
23
20
|
end # TTY
|
data/lib/tty/coercer/integer.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
4
|
class Coercer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
5
|
+
# Coerce value into integer number
|
6
|
+
#
|
7
|
+
# @api public
|
8
|
+
class Integer
|
9
|
+
def self.coerce(value, strict = true)
|
10
|
+
Kernel.send(:Integer, value.to_s)
|
11
|
+
rescue
|
12
|
+
if strict
|
13
|
+
raise InvalidArgument, "#{value} could not be coerced into Integer"
|
14
|
+
else
|
15
|
+
value.to_i
|
18
16
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
end
|
18
|
+
end # Integer
|
22
19
|
end # Coercer
|
23
20
|
end # TTY
|