tty_string 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +27 -13
- data/lib/tty_string.rb +11 -1
- data/lib/tty_string/code_definitions.rb +5 -5
- data/lib/tty_string/csi_code_definitions.rb +14 -14
- data/lib/tty_string/cursor.rb +0 -1
- data/lib/tty_string/version.rb +1 -1
- data/tty_string.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1b227f64f424b3dc76c088e9caa52639a5070e0543d022ffd920b01d830f78e
|
4
|
+
data.tar.gz: 6ddcd309f2b26d2a43251fcd0d7d673c72b5576e7e13c8d86df420a84b8d8c52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1db0493d2d8c027517b531d6997ddc52c47d0f9de6f375efab05f781d30db0e2c63d98f5933d62f471cb882f3248d4798aa1a5b6018158453e13d6be7045ab8
|
7
|
+
data.tar.gz: 97bef4800b9e802e5aa5d12afc86483bf570dc3913b9cf7b7b6530f2c6d58adba935a772d6f1b16626c6ffe0096a59dcea715ab017a252dd36bcf93092dd3913
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/robotdana/tty_string.svg?branch=master)](https://travis-ci.org/robotdana/tty_string)
|
4
4
|
|
5
|
-
Render a string like your terminal does by (narrowly) parsing ANSI TTY codes.
|
6
|
-
This is useful for testing CLI's
|
5
|
+
Render to a string like your terminal does by (narrowly) parsing ANSI TTY codes.
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- supports ruby 2.4 - 2.7, and jruby
|
10
|
+
- has no dependencies outside ruby stdlib
|
11
11
|
|
12
|
-
Supported codes
|
12
|
+
## Supported codes
|
13
13
|
|
14
14
|
- `\a` # BEL, just removed.
|
15
15
|
- `\b` # backspace
|
@@ -27,7 +27,7 @@ Supported codes
|
|
27
27
|
- `\e[nJ` # n=0: clear the screen forward, n=1: clear backward, n=2 or 3: clear the screen. default 0
|
28
28
|
- `\e[nK` # n=0: clear the line forward, n=1: clear the line backward, n=2: clear the line. default 0
|
29
29
|
- `\e[n;mf` # jump to row n, column m, default: 1,1
|
30
|
-
- `\e[m` # styling codes, optionally suppressed with clear_style: false
|
30
|
+
- `\e[m` # styling codes, optionally suppressed with `clear_style: false`
|
31
31
|
- `\e[nS` # scroll down n rows, default 1
|
32
32
|
- `\e[nT` # scroll up n rows, default 1
|
33
33
|
|
@@ -36,7 +36,7 @@ Supported codes
|
|
36
36
|
Add this line to your application's Gemfile:
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
gem 'tty_string'
|
39
|
+
gem 'tty_string', '~> 1.0'
|
40
40
|
```
|
41
41
|
|
42
42
|
And then execute:
|
@@ -50,26 +50,40 @@ Or install it yourself as:
|
|
50
50
|
## Usage
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
TTYString.
|
53
|
+
TTYString.parse("th\ta string\e[3Gis is")
|
54
54
|
=> "this is a string"
|
55
55
|
```
|
56
56
|
|
57
57
|
Styling information is suppressed by default:
|
58
58
|
```ruby
|
59
|
-
TTYString.
|
59
|
+
TTYString.parse("th\ta \e[31mstring\e[0m\e[3Gis is")
|
60
60
|
=> "this is a string"
|
61
61
|
```
|
62
62
|
But can be passed through:
|
63
63
|
```ruby
|
64
|
-
TTYString.
|
64
|
+
TTYString.parse("th\ta \e[31mstring\e[0m\e[3Gis is", clear_style: false)
|
65
65
|
=> "this is a \e[31mstring\e[0m"
|
66
66
|
```
|
67
67
|
|
68
|
+
Just for fun TTYString.to_proc provides the `parse` method as a lambda, so:
|
69
|
+
```ruby
|
70
|
+
"th\ta string\e[3Gis is".yield_self(&TTYString)
|
71
|
+
=> "this is a string"
|
72
|
+
```
|
73
|
+
|
74
|
+
## Limitations
|
75
|
+
|
76
|
+
Various terminals are wildly variously permissive with what they accept,
|
77
|
+
so this doesn't even try to cover all possible cases,
|
78
|
+
instead it covers the narrowest possible case, and leaves the codes in place when unrecognized
|
79
|
+
|
80
|
+
`clear_style: false` treats the style codes as regular text which may work differently when rendering codes that move the cursor.
|
81
|
+
|
68
82
|
## Development
|
69
83
|
|
70
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
84
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests and linters. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
85
|
|
72
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
86
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
73
87
|
|
74
88
|
## Contributing
|
75
89
|
|
data/lib/tty_string.rb
CHANGED
@@ -3,8 +3,18 @@
|
|
3
3
|
require_relative 'tty_string/parser'
|
4
4
|
|
5
5
|
# Renders a string taking into ANSI escape codes and \t\r\n etc
|
6
|
-
# Usage: TTYString.
|
6
|
+
# Usage: TTYString.parse("This\r\e[KThat") => "That"
|
7
7
|
class TTYString
|
8
|
+
class << self
|
9
|
+
def parse(input_string, clear_style: true)
|
10
|
+
new(input_string, clear_style: clear_style).to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_proc
|
14
|
+
method(:parse).to_proc
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
def initialize(input_string, clear_style: true)
|
9
19
|
@parser = Parser.new(input_string)
|
10
20
|
@parser.clear_style = clear_style
|
@@ -5,11 +5,11 @@ require_relative 'csi_code'
|
|
5
5
|
|
6
6
|
class TTYString
|
7
7
|
class Code
|
8
|
-
class SlashA < TTYString::Code
|
8
|
+
class SlashA < TTYString::Code # leftovers:allow
|
9
9
|
char "\a"
|
10
10
|
end
|
11
11
|
|
12
|
-
class SlashB < TTYString::Code
|
12
|
+
class SlashB < TTYString::Code # leftovers:allow
|
13
13
|
char "\b"
|
14
14
|
|
15
15
|
def self.match?(scanner)
|
@@ -26,7 +26,7 @@ class TTYString
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
class SlashN < TTYString::Code
|
29
|
+
class SlashN < TTYString::Code # leftovers:allow
|
30
30
|
char "\n"
|
31
31
|
|
32
32
|
def action
|
@@ -36,7 +36,7 @@ class TTYString
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
class SlashR < TTYString::Code
|
39
|
+
class SlashR < TTYString::Code # leftovers:allow
|
40
40
|
char "\r"
|
41
41
|
|
42
42
|
def action
|
@@ -44,7 +44,7 @@ class TTYString
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
class SlashT < TTYString::Code
|
47
|
+
class SlashT < TTYString::Code # leftovers:allow
|
48
48
|
char "\t"
|
49
49
|
|
50
50
|
def action
|
@@ -4,52 +4,52 @@ require_relative 'csi_code'
|
|
4
4
|
|
5
5
|
class TTYString
|
6
6
|
class CSICode
|
7
|
-
class A < TTYString::CSICode
|
7
|
+
class A < TTYString::CSICode # leftovers:allow
|
8
8
|
def action(rows = 1)
|
9
9
|
cursor.up(rows)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
class B < TTYString::CSICode
|
13
|
+
class B < TTYString::CSICode # leftovers:allow
|
14
14
|
def action(rows = 1)
|
15
15
|
cursor.down(rows)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
class C < TTYString::CSICode
|
19
|
+
class C < TTYString::CSICode # leftovers:allow
|
20
20
|
def action(cols = 1)
|
21
21
|
cursor.right(cols)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
class D < TTYString::CSICode
|
25
|
+
class D < TTYString::CSICode # leftovers:allow
|
26
26
|
def action(cols = 1)
|
27
27
|
cursor.left(cols)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
class E < TTYString::CSICode
|
31
|
+
class E < TTYString::CSICode # leftovers:allow
|
32
32
|
def action(rows = 1)
|
33
33
|
cursor.down(rows)
|
34
34
|
cursor.col = 0
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
class F < TTYString::CSICode
|
38
|
+
class F < TTYString::CSICode # leftovers:allow
|
39
39
|
def action(rows = 1)
|
40
40
|
cursor.up(rows)
|
41
41
|
cursor.col = 0
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
class G < TTYString::CSICode
|
45
|
+
class G < TTYString::CSICode # leftovers:allow
|
46
46
|
def action(col = 1)
|
47
47
|
# cursor is zero indexed, arg is 1 indexed
|
48
48
|
cursor.col = col.to_i - 1
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
class H < TTYString::CSICode
|
52
|
+
class H < TTYString::CSICode # leftovers:allow
|
53
53
|
def action(row = 1, col = 1)
|
54
54
|
# cursor is zero indexed, arg is 1 indexed
|
55
55
|
cursor.row = row.to_i - 1
|
@@ -57,11 +57,11 @@ class TTYString
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
class LowF < TTYString::CSICode::H
|
60
|
+
class LowF < TTYString::CSICode::H # leftovers:allow
|
61
61
|
char 'f'
|
62
62
|
end
|
63
63
|
|
64
|
-
class J < TTYString::CSICode
|
64
|
+
class J < TTYString::CSICode # leftovers:allow
|
65
65
|
default_arg 0
|
66
66
|
|
67
67
|
def self.args_re
|
@@ -79,7 +79,7 @@ class TTYString
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
class K < TTYString::CSICode
|
82
|
+
class K < TTYString::CSICode # leftovers:allow
|
83
83
|
default_arg 0
|
84
84
|
|
85
85
|
def self.arg_re
|
@@ -97,7 +97,7 @@ class TTYString
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
class LowM < TTYString::CSICode
|
100
|
+
class LowM < TTYString::CSICode # leftovers:allow
|
101
101
|
char 'm'
|
102
102
|
|
103
103
|
def self.arg_re
|
@@ -112,13 +112,13 @@ class TTYString
|
|
112
112
|
def action(*args); end
|
113
113
|
end
|
114
114
|
|
115
|
-
class S < TTYString::CSICode
|
115
|
+
class S < TTYString::CSICode # leftovers:allow
|
116
116
|
def action(rows = 1)
|
117
117
|
rows.times { screen.scroll_up }
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
class T < TTYString::CSICode
|
121
|
+
class T < TTYString::CSICode # leftovers:allow
|
122
122
|
def action(rows = 1)
|
123
123
|
rows.times { screen.scroll_down }
|
124
124
|
end
|
data/lib/tty_string/cursor.rb
CHANGED
data/lib/tty_string/version.rb
CHANGED
data/tty_string.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'leftovers', '>= 0.2.0'
|
28
29
|
spec.add_development_dependency 'pry', '~> 0.12'
|
29
30
|
spec.add_development_dependency 'rake', '>= 12.3.3'
|
30
31
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -32,4 +33,5 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.add_development_dependency 'rubocop-performance', '~> 1.4'
|
33
34
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.35'
|
34
35
|
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
36
|
+
spec.add_development_dependency 'spellr', '>= 0.8.1'
|
35
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: leftovers
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: 0.18.5
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: spellr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.8.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.8.1
|
125
153
|
description:
|
126
154
|
email:
|
127
155
|
- robot@dana.sh
|