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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa48f582822f503a5f6baabe338a3cde4fa5a75c
|
4
|
+
data.tar.gz: c65742283bfea4e4389b2b8efb311a149b106bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f866d26af71516c644c099d4cf799acf70bb86c1f8abaa4621b9c97257c8d0f4be3b53700a1ebfe43e58b32f80754101db4e5fb296766ee6d18393f829c23d
|
7
|
+
data.tar.gz: 7b02be106e54c2885b85a7731bdea9d143214f7eeb288db5285d30015d70fc9085c438a799de9339ceb4f8b46dfb01e8f92fa0a454ba725b46772409e3211699
|
data/.travis.yml
CHANGED
@@ -6,20 +6,18 @@ rvm:
|
|
6
6
|
- 2.0.0
|
7
7
|
- 2.1.0
|
8
8
|
- ruby-head
|
9
|
+
- rbx-2
|
9
10
|
matrix:
|
10
11
|
include:
|
11
12
|
- rvm: jruby-19mode
|
12
13
|
- rvm: jruby-20mode
|
13
14
|
- rvm: jruby-21mode
|
14
15
|
- rvm: jruby-head
|
15
|
-
- rvm: rbx-2
|
16
16
|
allow_failures:
|
17
17
|
- rvm: jruby-20mode
|
18
18
|
- rvm: jruby-21mode
|
19
19
|
- rvm: ruby-head
|
20
20
|
- rvm: jruby-head
|
21
|
-
- rvm: rbx
|
22
|
-
- rvm: rbx-2
|
23
21
|
fast_finish: true
|
24
22
|
branches:
|
25
23
|
only: master
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.1.1 (November 23, 2014)
|
2
|
+
|
3
|
+
* Add TTY::ProgressBar
|
4
|
+
* Add TTY::Spinner
|
5
|
+
* Remove TTY::Terminal::Color and replace with Pastel
|
6
|
+
* Change to depend on Equatable library
|
7
|
+
* Change to depend on TTY::Screen library for screen size detection
|
8
|
+
|
1
9
|
0.1.0 (21 September, 2014)
|
2
10
|
|
3
11
|
* Simplify development dependency mangement
|
data/README.md
CHANGED
@@ -4,13 +4,14 @@
|
|
4
4
|
[![Build Status](https://secure.travis-ci.org/peter-murach/tty.png?branch=master)][travis]
|
5
5
|
[![Code Climate](https://codeclimate.com/github/peter-murach/tty.png)][codeclimate]
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/peter-murach/tty/badge.png?branch=master)][coveralls]
|
7
|
+
[![Inline docs](http://inch-ci.org/github/peter-murach/tty.png?branch=master)](http://inch-ci.org/github/peter-murach/tty)
|
7
8
|
|
8
9
|
[gem]: http://badge.fury.io/rb/tty
|
9
10
|
[travis]: http://travis-ci.org/peter-murach/tty
|
10
11
|
[codeclimate]: https://codeclimate.com/github/peter-murach/tty
|
11
12
|
[coveralls]: https://coveralls.io/r/peter-murach/tty
|
12
13
|
|
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
|
+
> 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
|
|
15
16
|
## Motivation
|
16
17
|
|
@@ -22,19 +23,20 @@ Even more so, any command line application needs a clear way of communicating it
|
|
22
23
|
|
23
24
|
Jump-start development of your command line app:
|
24
25
|
|
25
|
-
*
|
26
|
+
* Terminal ASCII and Unicode tables. [status: ✔ ]
|
26
27
|
* Terminal output colorization. [status: ✔ ]
|
27
28
|
* Terminal output paging. [status: ✔ ]
|
28
|
-
* System
|
29
|
+
* System detection utilities. [status: ✔ ]
|
30
|
+
* Command detection utilities. [status: ✔ ]
|
29
31
|
* Text manipulation(wrapping/truncation) [status: ✔ ]
|
30
|
-
*
|
32
|
+
* Terminal progress bars drawing. [status: ✔ ]
|
33
|
+
* Terminal spinners. [status: ✔ ]
|
34
|
+
* Prompt user interface. [status: In Progress]
|
31
35
|
* File diffs. [status: TODO]
|
32
|
-
* Progress bar. [status: TODO]
|
33
36
|
* Configuration file management. [status: TODO]
|
34
37
|
* Logging [status: In Progress]
|
35
38
|
* Plugin ecosystem [status: TODO]
|
36
39
|
* Fully tested with major ruby interpreters.
|
37
|
-
* No dependencies to allow for easy gem vendoring.
|
38
40
|
|
39
41
|
## Installation
|
40
42
|
|
@@ -60,15 +62,49 @@ Or install it yourself as:
|
|
60
62
|
* [1.5 Padding](#15-padding)
|
61
63
|
* [1.6 Filter](#16-filter)
|
62
64
|
* [1.7 Width](#17-width)
|
63
|
-
* [2.
|
64
|
-
|
65
|
-
|
66
|
-
* [
|
67
|
-
* [
|
65
|
+
* [2. Color](#2-color)
|
66
|
+
* [3. ProgressBar](#3-progressbar)
|
67
|
+
* [4. Spinner](#4-spinner)
|
68
|
+
* [5. Screen](#5-screen)
|
69
|
+
* [6. Terminal](#6-terminal)
|
70
|
+
* [6.1 Pager](#61-pager)
|
71
|
+
* [7. Shell](#7-shell)
|
72
|
+
* [8. System](#8-system)
|
68
73
|
|
69
74
|
## Usage
|
70
75
|
|
71
|
-
|
76
|
+
**TTY** provides you with many tools to get the job done in terminal.
|
77
|
+
|
78
|
+
To print tabular output use `TTY::Table`:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
table = TTY::Table[['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
|
82
|
+
table.to_s # => a1 a2 a3
|
83
|
+
b1 b2 b3
|
84
|
+
```
|
85
|
+
|
86
|
+
To colorize your strings use `Pastel`:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
pastel = Pastel.new
|
90
|
+
pastel.green.on_red.bold('Piotr')
|
91
|
+
```
|
92
|
+
|
93
|
+
To create a progress bar use `TTY::ProgressBar`:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
bar = TTY::ProgressBar.new("downloading [:bar]", total: 30)
|
97
|
+
30.times { bar.advance }
|
98
|
+
```
|
99
|
+
|
100
|
+
To create a spinner use `TTY::Spinner`:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
spinner = TTY::Spinner.new('Loading ... ', format: :spin_2)
|
104
|
+
30.times { spinner.spin }
|
105
|
+
```
|
106
|
+
|
107
|
+
## 1 Table
|
72
108
|
|
73
109
|
To instantiate table pass 2-dimensional array:
|
74
110
|
|
@@ -293,7 +329,7 @@ end
|
|
293
329
|
By default padding is not applied. You can add `padding` to table fields like so
|
294
330
|
|
295
331
|
```ruby
|
296
|
-
|
332
|
+
header = ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra']
|
297
333
|
rows = [['id', 'int(11)', 'YES', 'nil', 'NULL', '']]
|
298
334
|
table = TTY::Table.new(header, rows)
|
299
335
|
table.render { |renderer| renderer.padding= [0,1,0,1] }
|
@@ -377,45 +413,41 @@ table.render width: 80, resize: true
|
|
377
413
|
+---------+-------+------------+
|
378
414
|
```
|
379
415
|
|
380
|
-
|
416
|
+
## 2 Color
|
381
417
|
|
382
|
-
To
|
418
|
+
To colorize your output you can use **Pastel** like so:
|
383
419
|
|
384
420
|
```ruby
|
385
|
-
|
386
|
-
|
387
|
-
term.height # => 60
|
388
|
-
term.color? # => true or false
|
389
|
-
term.echo(false) { } # switch off echo for the block
|
390
|
-
term.page # page terminal output, on non unix systems falls back to ruby implementation
|
421
|
+
pastel = Pastel.new
|
422
|
+
pastel.red.on_green.bold 'text...' # => red bold text on green background
|
391
423
|
```
|
392
424
|
|
393
|
-
|
425
|
+
Please refer to [documentation](https://github.com/peter-murach/pastel) for complete API.
|
394
426
|
|
395
|
-
|
427
|
+
## 3. ProgressBar
|
396
428
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
429
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-progressbar) for complete API.
|
430
|
+
|
431
|
+
## 4. Spinner
|
432
|
+
|
433
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-spinner) for complete API.
|
434
|
+
|
435
|
+
## 5. Screen
|
402
436
|
|
403
|
-
|
437
|
+
Please refer to [documentation](https://github.com/peter-murach/tty-screen) for complete API.
|
438
|
+
|
439
|
+
|
440
|
+
## 6 Terminal
|
441
|
+
|
442
|
+
To read general terminal properties you can use on of the helpers
|
404
443
|
|
405
444
|
```ruby
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
yellow
|
410
|
-
blue
|
411
|
-
magenta
|
412
|
-
cyan
|
413
|
-
white
|
445
|
+
term = TTY::Terminal.new
|
446
|
+
term.echo(false) { } # switch off echo for the block
|
447
|
+
term.page # page terminal output, on non unix systems falls back to ruby implementation
|
414
448
|
```
|
415
449
|
|
416
|
-
|
417
|
-
|
418
|
-
#### 2.2 Pager
|
450
|
+
### 6.1 Pager
|
419
451
|
|
420
452
|
To page your output do
|
421
453
|
|
@@ -423,7 +455,7 @@ To page your output do
|
|
423
455
|
term.page 'long text...'
|
424
456
|
```
|
425
457
|
|
426
|
-
|
458
|
+
## 7 Shell
|
427
459
|
|
428
460
|
Main responsibility is to interact with the prompt and provide convenience methods.
|
429
461
|
|
@@ -522,7 +554,7 @@ shell.suggest('sta', ['stage', 'stash', 'commit', 'branch'])
|
|
522
554
|
stash
|
523
555
|
```
|
524
556
|
|
525
|
-
|
557
|
+
## 8 System
|
526
558
|
|
527
559
|
```ruby
|
528
560
|
TTY::System.unix? # check if unix platform
|
data/lib/tty.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'equatable'
|
4
|
+
require 'pastel'
|
5
|
+
require 'tty-screen'
|
6
|
+
require 'tty-spinner'
|
7
|
+
require 'tty-progressbar'
|
8
|
+
|
3
9
|
require 'tty/version'
|
4
10
|
|
11
|
+
require 'tty/conversion'
|
5
12
|
require 'tty/support/utils'
|
6
13
|
require 'tty/support/delegatable'
|
7
|
-
require 'tty/support/conversion'
|
8
14
|
require 'tty/support/coercion'
|
9
|
-
require 'tty/support/equatable'
|
10
15
|
require 'tty/support/unicode'
|
11
16
|
|
12
17
|
require 'tty/terminal'
|
@@ -15,17 +20,11 @@ require 'tty/table'
|
|
15
20
|
require 'tty/text'
|
16
21
|
require 'tty/vector'
|
17
22
|
require 'tty/shell'
|
18
|
-
require 'tty/coercer'
|
19
23
|
require 'tty/logger'
|
20
24
|
require 'tty/plugins'
|
21
25
|
|
22
26
|
require 'tty/plugins/plugin'
|
23
27
|
|
24
|
-
require 'tty/coercer/range'
|
25
|
-
require 'tty/coercer/integer'
|
26
|
-
require 'tty/coercer/float'
|
27
|
-
require 'tty/coercer/boolean'
|
28
|
-
|
29
28
|
require 'tty/shell/response_delegation'
|
30
29
|
require 'tty/shell/question'
|
31
30
|
require 'tty/shell/question/validation'
|
@@ -35,7 +34,6 @@ require 'tty/shell/suggestion'
|
|
35
34
|
require 'tty/shell/reader'
|
36
35
|
require 'tty/shell/response'
|
37
36
|
|
38
|
-
require 'tty/terminal/color'
|
39
37
|
require 'tty/terminal/echo'
|
40
38
|
require 'tty/terminal/home'
|
41
39
|
require 'tty/terminal/pager'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
module Conversion
|
5
|
+
TypeError = Class.new(StandardError)
|
6
|
+
|
7
|
+
# Raised when cannot conver to a given type
|
8
|
+
NoTypeConversionAvailable = Class.new(StandardError)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'tty/conversion/converter/array'
|
13
|
+
require 'tty/conversion/converter/boolean'
|
14
|
+
require 'tty/conversion/converter/float'
|
15
|
+
require 'tty/conversion/converter/integer'
|
16
|
+
require 'tty/conversion/converter/range'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
module Conversion
|
5
|
+
class ArrayConverter
|
6
|
+
|
7
|
+
attr_reader :target
|
8
|
+
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source = String)
|
12
|
+
@source = source
|
13
|
+
@target = Array
|
14
|
+
end
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
def convert(value, copy = false)
|
18
|
+
case value
|
19
|
+
when Array
|
20
|
+
copy ? value.dup : value
|
21
|
+
when Hash
|
22
|
+
Array(value)
|
23
|
+
else
|
24
|
+
begin
|
25
|
+
converted = value.to_ary
|
26
|
+
rescue Exception => e
|
27
|
+
raise TTY::TypeError,
|
28
|
+
"Cannot convert #{value.class} into an Array (#{e.message})"
|
29
|
+
end
|
30
|
+
converted
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end # ArrayConverter
|
34
|
+
end # Conversion
|
35
|
+
end # TTY
|
@@ -1,10 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Conversion
|
5
|
+
class BooleanConverter
|
6
|
+
|
7
|
+
attr_reader :target
|
8
|
+
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source = String)
|
12
|
+
@source = source
|
13
|
+
@target = [TrueClass, FalseClass]
|
14
|
+
end
|
15
|
+
|
16
|
+
def boolean?(value)
|
17
|
+
target.any? { |klass| value.is_a?(klass) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Convert value to boolean type including range of strings such as
|
8
21
|
#
|
9
22
|
# @param [Object] value
|
10
23
|
#
|
@@ -21,7 +34,7 @@ module TTY
|
|
21
34
|
# 0, f, F, FALSE, false, False, n, N, No, no, No
|
22
35
|
#
|
23
36
|
# @api public
|
24
|
-
def
|
37
|
+
def convert(value)
|
25
38
|
case value.to_s
|
26
39
|
when /^(yes|y|t(rue)?|1)$/i
|
27
40
|
return true
|
@@ -31,6 +44,6 @@ module TTY
|
|
31
44
|
fail TypeError, "Expected boolean type, got #{value}"
|
32
45
|
end
|
33
46
|
end
|
34
|
-
end #
|
35
|
-
end #
|
47
|
+
end # BooleanConverter
|
48
|
+
end # Conversion
|
36
49
|
end # TTY
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
module Conversion
|
5
|
+
class FloatConverter
|
6
|
+
|
7
|
+
attr_reader :target
|
8
|
+
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source = String)
|
12
|
+
@source = source
|
13
|
+
@target = Float
|
14
|
+
end
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
def convert(value, strict = false)
|
18
|
+
Kernel.send(target.name.to_sym, value.to_s)
|
19
|
+
rescue
|
20
|
+
if strict
|
21
|
+
raise InvalidArgument, "#{value} could not be coerced into #{target.name}"
|
22
|
+
else
|
23
|
+
value.to_f
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # IntegerConverter
|
27
|
+
end # Conversion
|
28
|
+
end # TTY
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TTY
|
4
|
+
module Conversion
|
5
|
+
class IntegerConverter
|
6
|
+
|
7
|
+
attr_reader :target
|
8
|
+
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source = String)
|
12
|
+
@source = source
|
13
|
+
@target = Integer
|
14
|
+
end
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
def convert(value, strict = false)
|
18
|
+
Kernel.send(target.name.to_sym, value.to_s)
|
19
|
+
rescue
|
20
|
+
if strict
|
21
|
+
raise InvalidArgument, "#{value} could not be coerced into #{target.name}"
|
22
|
+
else
|
23
|
+
value.to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # IntegerConverter
|
27
|
+
end # Conversion
|
28
|
+
end # TTY
|
@@ -1,10 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module TTY
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Conversion
|
5
|
+
class RangeConverter
|
6
|
+
|
7
|
+
attr_reader :target
|
8
|
+
|
9
|
+
attr_reader :source
|
10
|
+
|
11
|
+
def initialize(source = String)
|
12
|
+
@source = source
|
13
|
+
@target = Range
|
14
|
+
end
|
15
|
+
|
16
|
+
# Convert value to Range type with possible ranges
|
8
17
|
#
|
9
18
|
# @param [Object] value
|
10
19
|
#
|
@@ -15,7 +24,7 @@ module TTY
|
|
15
24
|
# coerce('0-9') # => (0..9)
|
16
25
|
#
|
17
26
|
# @api public
|
18
|
-
def
|
27
|
+
def convert(value)
|
19
28
|
case value.to_s
|
20
29
|
when /\A(\-?\d+)\Z/
|
21
30
|
::Range.new($1.to_i, $1.to_i)
|
@@ -27,6 +36,6 @@ module TTY
|
|
27
36
|
fail InvalidArgument, "#{value} could not be coerced into Range type"
|
28
37
|
end
|
29
38
|
end
|
30
|
-
end #
|
31
|
-
end #
|
39
|
+
end # RangeConverter
|
40
|
+
end # Conversion
|
32
41
|
end # TTY
|