eskimo 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/eskimo.rb +20 -4
- data/lib/eskimo/component.rb +2 -2
- data/lib/eskimo/components/did_you_mean.rb +34 -0
- data/lib/eskimo/components/either.rb +30 -0
- data/lib/eskimo/components/highlight.rb +31 -0
- data/lib/eskimo/components/highlight_column.rb +61 -0
- data/lib/eskimo/components/indent.rb +25 -0
- data/lib/eskimo/components/line_break.rb +18 -0
- data/lib/eskimo/components/soft_break.rb +16 -0
- data/lib/eskimo/components/squeeze.rb +43 -0
- data/lib/eskimo/components/strip.rb +15 -0
- data/lib/eskimo/components/strip_left.rb +15 -0
- data/lib/eskimo/components/strip_right.rb +15 -0
- data/lib/eskimo/components/style.rb +25 -0
- data/lib/eskimo/components/truncate.rb +31 -0
- data/lib/eskimo/components/truncate_rear.rb +25 -0
- data/lib/eskimo/components/wrap.rb +26 -0
- data/lib/eskimo/constants.rb +7 -0
- data/lib/eskimo/renderer.rb +15 -17
- data/lib/eskimo/version.rb +1 -1
- data/spec/component_spec.rb +13 -0
- data/spec/components/did_you_mean_spec.rb +21 -0
- data/spec/components/either_spec.rb +21 -0
- data/spec/components/highlight_column_spec.rb +63 -0
- data/spec/components/highlight_spec.rb +25 -0
- data/spec/components/indent_spec.rb +15 -0
- data/spec/components/line_break_spec.rb +17 -0
- data/spec/components/soft_break_spec.rb +17 -0
- data/spec/components/squeeze_spec.rb +61 -0
- data/spec/components/strip_left_spec.rb +15 -0
- data/spec/components/strip_right_spec.rb +15 -0
- data/spec/components/strip_spec.rb +15 -0
- data/spec/components/style_spec.rb +25 -0
- data/spec/components/truncate_rear_spec.rb +35 -0
- data/spec/components/truncate_spec.rb +35 -0
- data/spec/components/wrap_spec.rb +15 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/component_suite.rb +15 -0
- metadata +52 -5
- data/lib/eskimo/components.rb +0 -114
- data/spec/components_spec.rb +0 -159
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::Components::Truncate do
|
6
|
+
it 'truncates a string from the beginning if it exceeds the length' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
ESK::Truncate.new(width: 5) do
|
10
|
+
("hello world")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
).to eq("... world")
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'reserves chars from the width' do
|
17
|
+
expect(
|
18
|
+
renderer.apply do
|
19
|
+
ESK::Truncate.new(width: 10, reserve: 5) do
|
20
|
+
("hello world")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
).to eq("... world")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is a no-op if text fits' do
|
27
|
+
expect(
|
28
|
+
renderer.apply do
|
29
|
+
ESK::Truncate.new(width: 62, reserve: 5) do
|
30
|
+
("hello world")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
).to eq("hello world")
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::Components::Wrap do
|
6
|
+
it 'wraps text' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
ESK::Wrap.new(width: 5) do
|
10
|
+
'hello world'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
).to eq("\nhello \nworld")
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,9 @@ SimpleCov.start do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'eskimo'
|
11
|
+
require_relative './support/component_suite'
|
12
|
+
|
13
|
+
ESK = Eskimo::Components
|
11
14
|
|
12
15
|
RSpec.configure do |config|
|
13
16
|
config.expect_with :rspec do |expectations|
|
@@ -29,6 +32,11 @@ RSpec.configure do |config|
|
|
29
32
|
config.default_formatter = 'doc' if config.files_to_run.one?
|
30
33
|
|
31
34
|
config.order = :random
|
35
|
+
config.define_derived_metadata(file_path: %r{/spec/components/}) do |metadata|
|
36
|
+
metadata[:type] = :component
|
37
|
+
end
|
38
|
+
|
39
|
+
config.include EskimoTest::ComponentSuite, type: :component
|
32
40
|
|
33
41
|
Kernel.srand config.seed
|
34
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eskimo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmad Amireh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -88,12 +88,43 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- lib/eskimo.rb
|
90
90
|
- lib/eskimo/component.rb
|
91
|
-
- lib/eskimo/components.rb
|
91
|
+
- lib/eskimo/components/did_you_mean.rb
|
92
|
+
- lib/eskimo/components/either.rb
|
93
|
+
- lib/eskimo/components/highlight.rb
|
94
|
+
- lib/eskimo/components/highlight_column.rb
|
95
|
+
- lib/eskimo/components/indent.rb
|
96
|
+
- lib/eskimo/components/line_break.rb
|
97
|
+
- lib/eskimo/components/soft_break.rb
|
98
|
+
- lib/eskimo/components/squeeze.rb
|
99
|
+
- lib/eskimo/components/strip.rb
|
100
|
+
- lib/eskimo/components/strip_left.rb
|
101
|
+
- lib/eskimo/components/strip_right.rb
|
102
|
+
- lib/eskimo/components/style.rb
|
103
|
+
- lib/eskimo/components/truncate.rb
|
104
|
+
- lib/eskimo/components/truncate_rear.rb
|
105
|
+
- lib/eskimo/components/wrap.rb
|
106
|
+
- lib/eskimo/constants.rb
|
92
107
|
- lib/eskimo/renderer.rb
|
93
108
|
- lib/eskimo/version.rb
|
94
|
-
- spec/
|
109
|
+
- spec/component_spec.rb
|
110
|
+
- spec/components/did_you_mean_spec.rb
|
111
|
+
- spec/components/either_spec.rb
|
112
|
+
- spec/components/highlight_column_spec.rb
|
113
|
+
- spec/components/highlight_spec.rb
|
114
|
+
- spec/components/indent_spec.rb
|
115
|
+
- spec/components/line_break_spec.rb
|
116
|
+
- spec/components/soft_break_spec.rb
|
117
|
+
- spec/components/squeeze_spec.rb
|
118
|
+
- spec/components/strip_left_spec.rb
|
119
|
+
- spec/components/strip_right_spec.rb
|
120
|
+
- spec/components/strip_spec.rb
|
121
|
+
- spec/components/style_spec.rb
|
122
|
+
- spec/components/truncate_rear_spec.rb
|
123
|
+
- spec/components/truncate_spec.rb
|
124
|
+
- spec/components/wrap_spec.rb
|
95
125
|
- spec/renderer_spec.rb
|
96
126
|
- spec/spec_helper.rb
|
127
|
+
- spec/support/component_suite.rb
|
97
128
|
homepage: https://github.com/amireh/eskimo
|
98
129
|
licenses:
|
99
130
|
- MIT
|
@@ -119,6 +150,22 @@ signing_key:
|
|
119
150
|
specification_version: 4
|
120
151
|
summary: Declarative text formatting
|
121
152
|
test_files:
|
153
|
+
- spec/components/strip_spec.rb
|
154
|
+
- spec/components/highlight_column_spec.rb
|
155
|
+
- spec/components/truncate_rear_spec.rb
|
156
|
+
- spec/components/indent_spec.rb
|
157
|
+
- spec/components/did_you_mean_spec.rb
|
158
|
+
- spec/components/line_break_spec.rb
|
159
|
+
- spec/components/style_spec.rb
|
160
|
+
- spec/components/squeeze_spec.rb
|
161
|
+
- spec/components/soft_break_spec.rb
|
162
|
+
- spec/components/either_spec.rb
|
163
|
+
- spec/components/strip_left_spec.rb
|
164
|
+
- spec/components/truncate_spec.rb
|
165
|
+
- spec/components/wrap_spec.rb
|
166
|
+
- spec/components/strip_right_spec.rb
|
167
|
+
- spec/components/highlight_spec.rb
|
168
|
+
- spec/support/component_suite.rb
|
122
169
|
- spec/spec_helper.rb
|
123
170
|
- spec/renderer_spec.rb
|
124
|
-
- spec/
|
171
|
+
- spec/component_spec.rb
|
data/lib/eskimo/components.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Eskimo
|
4
|
-
module Components
|
5
|
-
SCREEN_COLUMNS = [TTY::Screen.width, 72].min
|
6
|
-
|
7
|
-
# Indent text from the left.
|
8
|
-
class Indent < Component
|
9
|
-
attr_reader :width
|
10
|
-
|
11
|
-
def initialize(width: 4, &children)
|
12
|
-
@width = width
|
13
|
-
super(&children)
|
14
|
-
end
|
15
|
-
|
16
|
-
def render(**)
|
17
|
-
Strings.pad(super, [0,0,0,width]).rstrip
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Insert a hard line-break (paragraph-like.)
|
22
|
-
class LineBreak
|
23
|
-
def render(**)
|
24
|
-
"\n \n"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Insert a soft line-break.
|
29
|
-
class SoftBreak
|
30
|
-
def render(**)
|
31
|
-
"\n"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Strip text of surrounding whitespace.
|
36
|
-
class Strip < Component
|
37
|
-
def render(**)
|
38
|
-
super.strip
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Style text with colors and custom formatting.
|
43
|
-
#
|
44
|
-
# See [Pastel's documentation][pastel] for the accepted styles.
|
45
|
-
#
|
46
|
-
# [pastel]: https://github.com/piotrmurach/pastel
|
47
|
-
class Style < Component
|
48
|
-
attr_reader :pastel, :style
|
49
|
-
|
50
|
-
def initialize(*style, &children)
|
51
|
-
@style = style.flatten
|
52
|
-
@pastel = Pastel.new
|
53
|
-
|
54
|
-
super(&children)
|
55
|
-
end
|
56
|
-
|
57
|
-
def render(**)
|
58
|
-
pastel.decorate(super, *style)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Truncate text from the beginning if it exceeds a certain width.
|
63
|
-
#
|
64
|
-
# ...bar
|
65
|
-
class Truncate < Component
|
66
|
-
attr_reader :maxlen
|
67
|
-
|
68
|
-
def initialize(reserve: 0, width: SCREEN_COLUMNS, &children)
|
69
|
-
@maxlen = [0, width - reserve].max
|
70
|
-
|
71
|
-
super(&children)
|
72
|
-
end
|
73
|
-
|
74
|
-
def render(**)
|
75
|
-
text = super
|
76
|
-
|
77
|
-
if text.length >= maxlen
|
78
|
-
'...' + text[text.length - maxlen - 1 .. -1]
|
79
|
-
else
|
80
|
-
text
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Truncate text from the rear if it exceeds a certain width.
|
86
|
-
#
|
87
|
-
# foo...
|
88
|
-
class TruncateRear < Truncate
|
89
|
-
def render(render:, **)
|
90
|
-
text = render[@children]
|
91
|
-
|
92
|
-
if text.length >= maxlen
|
93
|
-
text[0..maxlen - 1] + '...'
|
94
|
-
else
|
95
|
-
text
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Wrap a block text with newlines at a certain threshold.
|
101
|
-
class Wrap < Component
|
102
|
-
attr_reader :width
|
103
|
-
|
104
|
-
def initialize(width: SCREEN_COLUMNS, &children)
|
105
|
-
@width = width
|
106
|
-
super(&children)
|
107
|
-
end
|
108
|
-
|
109
|
-
def render(**)
|
110
|
-
Strings.wrap(super, width)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
data/spec/components_spec.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe Eskimo::Renderer do
|
6
|
-
ESK = Eskimo::Components
|
7
|
-
|
8
|
-
describe 'SOFT_BREAK' do
|
9
|
-
it 'inserts a soft linebreak' do
|
10
|
-
expect(
|
11
|
-
subject.apply {
|
12
|
-
[
|
13
|
-
'hello',
|
14
|
-
ESK::SoftBreak.new,
|
15
|
-
'world'
|
16
|
-
]
|
17
|
-
}
|
18
|
-
).to eq("hello\nworld")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe 'BR' do
|
23
|
-
it 'inserts a hard linebreak' do
|
24
|
-
expect(
|
25
|
-
subject.apply {
|
26
|
-
[
|
27
|
-
'hello',
|
28
|
-
ESK::LineBreak.new,
|
29
|
-
'world'
|
30
|
-
]
|
31
|
-
}
|
32
|
-
).to eq("hello\n \nworld")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'STYLE' do
|
37
|
-
it 'applies ANSI styling to text' do
|
38
|
-
expect(
|
39
|
-
subject.apply {
|
40
|
-
[
|
41
|
-
ESK::Style.new([:bold, :green]) { 'hai' },
|
42
|
-
]
|
43
|
-
}
|
44
|
-
).to eq("\e[1;32mhai\e[0m")
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'accepts a splat' do
|
48
|
-
expect(
|
49
|
-
subject.apply {
|
50
|
-
[
|
51
|
-
ESK::Style.new(:bold, :green) { 'hai' },
|
52
|
-
]
|
53
|
-
}
|
54
|
-
).to eq("\e[1;32mhai\e[0m")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'WRAP' do
|
59
|
-
it 'wraps text' do
|
60
|
-
expect(
|
61
|
-
subject.apply do
|
62
|
-
ESK::Wrap.new(width: 5) do
|
63
|
-
'hello world'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
).to eq("\nhello \nworld")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'INDENT' do
|
71
|
-
it 'indents each line' do
|
72
|
-
expect(
|
73
|
-
subject.apply do
|
74
|
-
ESK::Indent.new(width: 2) do
|
75
|
-
"hello\nworld"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
).to eq(" hello\n world")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 'STRIP' do
|
83
|
-
it 'strips surrounding whitespace' do
|
84
|
-
expect(
|
85
|
-
subject.apply do
|
86
|
-
ESK::Strip.new do
|
87
|
-
ESK::Indent.new(width: 2) do
|
88
|
-
("hello world")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
).to eq("hello world")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'TRUNCATE' do
|
97
|
-
it 'truncates a string from the beginning if it exceeds the length' do
|
98
|
-
expect(
|
99
|
-
subject.apply do
|
100
|
-
ESK::Truncate.new(width: 5) do
|
101
|
-
("hello world")
|
102
|
-
end
|
103
|
-
end
|
104
|
-
).to eq("... world")
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'reserves chars from the width' do
|
108
|
-
expect(
|
109
|
-
subject.apply do
|
110
|
-
ESK::Truncate.new(width: 10, reserve: 5) do
|
111
|
-
("hello world")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
).to eq("... world")
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'is a no-op if text fits' do
|
118
|
-
expect(
|
119
|
-
subject.apply do
|
120
|
-
ESK::Truncate.new(width: 62, reserve: 5) do
|
121
|
-
("hello world")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
).to eq("hello world")
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe 'TruncateRear' do
|
129
|
-
it 'truncates a string from the rear if it exceeds the length' do
|
130
|
-
expect(
|
131
|
-
subject.apply do
|
132
|
-
ESK::TruncateRear.new(width: 5) do
|
133
|
-
"hello world"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
).to eq("hello...")
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'reserves chars from the width' do
|
140
|
-
expect(
|
141
|
-
subject.apply do
|
142
|
-
ESK::TruncateRear.new(width: 10, reserve: 5) do
|
143
|
-
("hello world")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
).to eq("hello...")
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'is a no-op if text fits' do
|
150
|
-
expect(
|
151
|
-
subject.apply do
|
152
|
-
ESK::TruncateRear.new(width: 62, reserve: 5) do
|
153
|
-
("hello world")
|
154
|
-
end
|
155
|
-
end
|
156
|
-
).to eq("hello world")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|