eskimo-ascii 3.0.0.pre.2 → 3.0.0.pre.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b560606ad14050f8a1fb5e2e6e458704c2416573283896381cc550095535bcb9
4
- data.tar.gz: 3d7c37b94d9b4304d542cacae2c29133001aca1b32cd5fb31b0714d749ef5352
3
+ metadata.gz: 77c7011dd75b1e275fb94531d839512948e3ca92144b4ddbef0f870374358366
4
+ data.tar.gz: d2684e0564cb79124700ef925a58895c70d15e6a4990f230f41803c8e3a8c3c7
5
5
  SHA512:
6
- metadata.gz: bf7503f1a782a81c73c79742119b9ed9d015129a99ee8066eded71179da5f7b23bf954e339a2d1444c42d4e70e46c4a23f819780591683571c72635f80a4c55a
7
- data.tar.gz: 68caff0f59eb4056045eab9f7864e591ef008246351fdfe2006df9edb31797841c8b2265265da1ffa5449b72f307843746f4c45aa21185134d8650bba458d8da
6
+ metadata.gz: 8be5a37bac7af74c8779ce4b0dcec516158472a7848d2954b109da0884abde12507835a7ef7085ef69fbe161b3a6bbd6b7083194b4e38088b6520f60563f023d
7
+ data.tar.gz: 2bb90b39558f64422d1f4a2f2055401e054aee9b727bc901960fefcbe96ea70e29848d2adc2dbb74406b35bb14d28cc5c02d84d9c6364a89a5ad20dfe470f859
data/lib/eskimo/ascii.rb CHANGED
@@ -1,8 +1,3 @@
1
- module Eskimo
2
- module ASCII
3
- end
4
- end
5
-
6
1
  begin
7
2
  require 'did_you_mean'
8
3
  rescue LoadError
@@ -12,6 +7,11 @@ require 'pastel'
12
7
  require 'strings'
13
8
  require 'tty-screen'
14
9
 
10
+ module Eskimo
11
+ module ASCII
12
+ end
13
+ end
14
+
15
15
  require 'eskimo/ascii/version'
16
16
  require 'eskimo/ascii/constants'
17
17
  require 'eskimo/ascii/component'
@@ -1,35 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A base component class that renders child components defined in a block into
4
- # a String for further formatting.
5
- #
6
- # class MyComponent < Eskimo::ASCII::Component
7
- # def render(**)
8
- # text = super
9
- # text.is_a?(String) # => true
10
- # end
11
- # end
12
- #
13
- # Use of this class is optional. What's happening under the hood is:
14
- #
15
- # 1. Component maintains a reference to the Proc passed to {#initialize}. That
16
- # Proc can potentially return a list of child components to render.
17
- #
18
- # 2. {Component#render} (called via "super" from sub-classes) invokes the
19
- # `render` prop provided by {Core::Renderer#apply} with the tracked children
20
- # which converts them to a String and returns them.
21
- class Eskimo::ASCII::Component
22
- def initialize(*, **, &children_gen)
23
- @children = children_gen
24
- end
3
+ module Eskimo::ASCII
4
+ # A base component class that renders child components defined in a block into
5
+ # a String for further formatting.
6
+ #
7
+ # class MyComponent < Eskimo::ASCII::Component
8
+ # def render(**)
9
+ # text = super
10
+ # text.is_a?(String) # => true
11
+ # end
12
+ # end
13
+ #
14
+ # Use of this class is optional. What's happening under the hood is:
15
+ #
16
+ # 1. Component maintains a reference to the Proc passed to {#initialize}. That
17
+ # Proc can potentially return a list of child components to render.
18
+ #
19
+ # 2. {Component#render} (called via "super" from sub-classes) invokes the
20
+ # `render` prop provided by {Core::Renderer#apply} with the tracked children
21
+ # which converts them to a String and returns them.
22
+ class Component
23
+ def initialize(*, **, &children_gen)
24
+ @children = children_gen
25
+ end
25
26
 
26
- def render(render:, **)
27
- render[@children]
28
- end
27
+ def render(render:, **)
28
+ render[@children]
29
+ end
29
30
 
30
- protected
31
+ protected
31
32
 
32
- def pastel
33
- @pastel ||= Pastel.new
33
+ def pastel
34
+ @pastel ||= Pastel.new
35
+ end
34
36
  end
35
37
  end
@@ -1,30 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Present the user with the closest possible correction, if any.
4
- #
5
- # DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'abd')
6
- # # => "hint: Did you mean? abc"
7
- #
8
- # DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'asdfasdf')
9
- # # => ""
10
- #
11
- # See https://github.com/yuki24/did_you_mean#using-the-didyoumeanspellchecker
12
- class Eskimo::ASCII::DidYouMean < Eskimo::ASCII::Component
13
- attr_reader :corrections, :separator
3
+ module Eskimo::ASCII
4
+ # Present the user with the closest possible correction, if any.
5
+ #
6
+ # DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'abd')
7
+ # # => "hint: Did you mean? abc"
8
+ #
9
+ # DidYouMean.new(dictionary: [ 'abc', 'bca' ], item: 'asdfasdf')
10
+ # # => ""
11
+ #
12
+ # See https://github.com/yuki24/did_you_mean#using-the-didyoumeanspellchecker
13
+ class DidYouMean < Component
14
+ attr_reader :corrections, :separator
14
15
 
15
- def initialize(dictionary:, item:, separator: " or ", &children)
16
- @corrections = ::DidYouMean::SpellChecker.new(
17
- dictionary: dictionary
18
- ).correct(item)
16
+ def initialize(dictionary:, item:, separator: " or ", &children)
17
+ @corrections = ::DidYouMean::SpellChecker.new(
18
+ dictionary: dictionary
19
+ ).correct(item)
19
20
 
20
- @separator = separator
21
+ @separator = separator
21
22
 
22
- super
23
- end
23
+ super
24
+ end
24
25
 
25
- def render(**)
26
- if corrections.any?
27
- "Did you mean? #{corrections.join(separator)}"
26
+ def render(**)
27
+ if corrections.any?
28
+ "Did you mean? #{corrections.join(separator)}"
29
+ end
28
30
  end
29
31
  end
30
32
  end
@@ -1,26 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Render a fallback component in case the first one evaluates to an empty
4
- # String.
5
- #
6
- # Either.new(->(**) { false }, "Fallback here")
7
- # # => "Fallback here"
8
- #
9
- # Either.new(->(**) { "Hi!" }, "Fallback here")
10
- # # => "Hi!"
11
- #
12
- class Eskimo::ASCII::Either
13
- attr_reader :children
3
+ module Eskimo::ASCII
4
+ # Render a fallback component in case the first one evaluates to an empty
5
+ # String.
6
+ #
7
+ # Either.new(->(**) { false }, "Fallback here")
8
+ # # => "Fallback here"
9
+ #
10
+ # Either.new(->(**) { "Hi!" }, "Fallback here")
11
+ # # => "Hi!"
12
+ #
13
+ class Either
14
+ attr_reader :children
14
15
 
15
- def initialize(primary, fallback)
16
- @children = [ primary, fallback ]
17
- end
16
+ def initialize(primary, fallback)
17
+ @children = [ primary, fallback ]
18
+ end
18
19
 
19
- def render(render:, **)
20
- for child in children do
21
- rendered = render[child]
20
+ def render(render:, **)
21
+ for child in children do
22
+ rendered = render[child]
22
23
 
23
- return rendered unless rendered.empty?
24
+ return rendered unless rendered.empty?
25
+ end
24
26
  end
25
27
  end
26
28
  end
@@ -1,29 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Prepend each line with a character or symbol.
4
- #
5
- # Gutter.new(char: '| ') do
6
- # [ "Hello", "\n", "World!" ]
7
- # end
8
- # # => "| Hello"
9
- # # "| World!"
10
- class Eskimo::ASCII::Gutter < Eskimo::ASCII::Component
11
- attr_reader :char, :spacing
3
+ module Eskimo::ASCII
4
+ # Prepend each line with a character or symbol.
5
+ #
6
+ # Gutter.new(char: '| ') do
7
+ # [ "Hello", "\n", "World!" ]
8
+ # end
9
+ # # => "| Hello"
10
+ # # "| World!"
11
+ class Gutter < Component
12
+ attr_reader :char, :spacing
12
13
 
13
- def initialize(char:, spacing: 0, &children)
14
- @char = char
15
- @spacing = spacing
14
+ def initialize(char:, spacing: 0, &children)
15
+ @char = char
16
+ @spacing = spacing
16
17
 
17
- super
18
- end
18
+ super
19
+ end
19
20
 
20
- def render(**)
21
- spacer = Array.new(spacing, char)
21
+ def render(**)
22
+ spacer = Array.new(spacing, char)
22
23
 
23
- [
24
- *spacer,
25
- super.lines.map { |s| s.prepend(char) }.join,
26
- *spacer
27
- ].join("\n")
24
+ [
25
+ *spacer,
26
+ super.lines.map { |s| s.prepend(char) }.join,
27
+ *spacer
28
+ ].join("\n")
29
+ end
28
30
  end
29
31
  end
@@ -1,27 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Highlight a substring with ASCII arrows.
4
- #
5
- # Highlight.new(pattern: /lol/) do
6
- # "- include: lol://file.yml"
7
- # end
8
- # # => "- include: lol://file.yml"
9
- # # ^^^
10
- #
11
- class Eskimo::ASCII::Highlight < Eskimo::ASCII::Component
12
- attr_reader :pastel, :pattern, :style
3
+ module Eskimo::ASCII
4
+ # Highlight a substring with ASCII arrows.
5
+ #
6
+ # Highlight.new(pattern: /lol/) do
7
+ # "- include: lol://file.yml"
8
+ # end
9
+ # # => "- include: lol://file.yml"
10
+ # # ^^^
11
+ #
12
+ class Highlight < Component
13
+ attr_reader :pastel, :pattern, :style
13
14
 
14
- def initialize(pattern:, style: [:red, :bold, :underline], &children)
15
- @pastel = Pastel.new
16
- @pattern = pattern
17
- @style = style
15
+ def initialize(pattern:, style: [:red, :bold, :underline], &children)
16
+ @pastel = Pastel.new
17
+ @pattern = pattern
18
+ @style = style
18
19
 
19
- super(&children)
20
- end
20
+ super(&children)
21
+ end
21
22
 
22
- def render(**)
23
- super.sub(pattern) do |substring|
24
- pastel.decorate(substring, *style)
23
+ def render(**)
24
+ super.sub(pattern) do |substring|
25
+ pastel.decorate(substring, *style)
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -1,57 +1,59 @@
1
- # Highlight a particular character of a string with an ASCII arrow.
2
- #
3
- # HighlightColumn.new(line: 0, column: 14) do
4
- # "- include: lol://wut.yml"
5
- # end
6
- # => "- include: lol://wut.yml"
7
- # " ^ "
8
- # " here "
9
- class Eskimo::ASCII::HighlightColumn < Eskimo::ASCII::Component
10
- def initialize(
11
- column:,
12
- line:,
13
- markers: ['^', 'here'],
14
- style: [:bold, :red],
15
- &children
16
- )
17
- pastel = Pastel.new
18
-
19
- @colorize = ->(str) { pastel.decorate(str, *style) }
20
- @column = column
21
- @line = line
22
- @marker_padding = ' ' * @column
23
- @markers = markers
24
-
25
- super
26
- end
1
+ module Eskimo::ASCII
2
+ # Highlight a particular character of a string with an ASCII arrow.
3
+ #
4
+ # HighlightColumn.new(line: 0, column: 14) do
5
+ # "- include: lol://wut.yml"
6
+ # end
7
+ # => "- include: lol://wut.yml"
8
+ # " ^ "
9
+ # " here "
10
+ class HighlightColumn < Component
11
+ def initialize(
12
+ column:,
13
+ line:,
14
+ markers: ['^', 'here'],
15
+ style: [:bold, :red],
16
+ &children
17
+ )
18
+ pastel = Pastel.new
19
+
20
+ @colorize = ->(str) { pastel.decorate(str, *style) }
21
+ @column = column
22
+ @line = line
23
+ @marker_padding = ' ' * @column
24
+ @markers = markers
25
+
26
+ super
27
+ end
27
28
 
28
- def render(**)
29
- lines = super.lines
30
- line = lines[@line]
29
+ def render(**)
30
+ lines = super.lines
31
+ line = lines[@line]
31
32
 
32
- unless line.nil? || line[@column].nil?
33
- lines[@line] = transform_line!(line, @column, &@colorize)
33
+ unless line.nil? || line[@column].nil?
34
+ lines[@line] = transform_line!(line, @column, &@colorize)
35
+ end
36
+
37
+ lines.join
34
38
  end
35
39
 
36
- lines.join
37
- end
40
+ protected
38
41
 
39
- protected
42
+ def create_markers()
43
+ buf = ''
40
44
 
41
- def create_markers()
42
- buf = ''
45
+ for marker in @markers do
46
+ buf << @marker_padding + @colorize[marker] + "\n"
47
+ end
43
48
 
44
- for marker in @markers do
45
- buf << @marker_padding + @colorize[marker] + "\n"
49
+ buf
46
50
  end
47
51
 
48
- buf
49
- end
50
-
51
- def transform_line!(line, column, &fn)
52
- line[column] = fn[line[column]]
53
- line << "\n" unless line.end_with?("\n")
54
- line << create_markers
55
- line
52
+ def transform_line!(line, column, &fn)
53
+ line[column] = fn[line[column]]
54
+ line << "\n" unless line.end_with?("\n")
55
+ line << create_markers
56
+ line
57
+ end
56
58
  end
57
59
  end
@@ -1,21 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Indent text from the left.
4
- #
5
- # Indent.new(width: 8) do
6
- # [ "Hello", SoftBreak.new, "World!" ]
7
- # end
8
- # # => " Hello"
9
- # # " World!"
10
- class Eskimo::ASCII::Indent < Eskimo::ASCII::Component
11
- attr_reader :width
3
+ module Eskimo::ASCII
4
+ # Indent text from the left.
5
+ #
6
+ # Indent.new(width: 8) do
7
+ # [ "Hello", SoftBreak.new, "World!" ]
8
+ # end
9
+ # # => " Hello"
10
+ # # " World!"
11
+ class Indent < Component
12
+ attr_reader :width
12
13
 
13
- def initialize(width: 4, &children)
14
- @width = width
15
- super
16
- end
14
+ def initialize(width: 4, &children)
15
+ @width = width
16
+ super
17
+ end
17
18
 
18
- def render(**)
19
- Strings.pad(super, [0,0,0,width])
19
+ def render(**)
20
+ Strings.pad(super, [0,0,0,width])
21
+ end
20
22
  end
21
23
  end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Insert a paragraph-like line-break.
4
- #
5
- # [ "Hello", LineBreak.new, "World!" ]
6
- # # => "Hello"
7
- # # ""
8
- # # ""
9
- # # "World!"
10
- class Eskimo::ASCII::LineBreak
11
- def render(**)
12
- "\n \n"
3
+ module Eskimo::ASCII
4
+ # Insert a paragraph-like line-break.
5
+ #
6
+ # [ "Hello", LineBreak.new, "World!" ]
7
+ # # => "Hello"
8
+ # # ""
9
+ # # ""
10
+ # # "World!"
11
+ class LineBreak
12
+ def render(**)
13
+ "\n \n"
14
+ end
13
15
  end
14
16
  end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Insert a soft line-break.
4
- #
5
- # [ "Hello", SoftBreak.new, "World!" ]
6
- # # => "Hello"
7
- # # "World!"
8
- class Eskimo::ASCII::SoftBreak
9
- def render(**)
10
- "\n"
3
+ module Eskimo::ASCII
4
+ # Insert a soft line-break.
5
+ #
6
+ # [ "Hello", SoftBreak.new, "World!" ]
7
+ # # => "Hello"
8
+ # # "World!"
9
+ class SoftBreak
10
+ def render(**)
11
+ "\n"
12
+ end
11
13
  end
12
14
  end
@@ -1,29 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Space consecutive components with soft breaks.
4
- #
5
- # Spacer.new([
6
- # "Hello",
7
- # "World!"
8
- # ])
9
- # # => "Hello"
10
- # # "World!"
11
- #
12
- # The soft breaks for each conditional component will be preserved only
13
- # if they do render some content.
14
- class Eskimo::ASCII::Spacer
15
- def initialize(children)
16
- if !children.is_a?(Array) || block_given?
17
- raise ArgumentError.new("Spacer works only with an Array of components")
18
- end
3
+ module Eskimo::ASCII
4
+ # Space consecutive components with soft breaks.
5
+ #
6
+ # Spacer.new([
7
+ # "Hello",
8
+ # "World!"
9
+ # ])
10
+ # # => "Hello"
11
+ # # "World!"
12
+ #
13
+ # The soft breaks for each conditional component will be preserved only
14
+ # if they do render some content.
15
+ class Spacer
16
+ def initialize(children)
17
+ if !children.is_a?(Array) || block_given?
18
+ raise ArgumentError.new("Spacer works only with an Array of components")
19
+ end
19
20
 
20
- @children = children
21
- end
21
+ @children = children
22
+ end
22
23
 
23
- def render(**props)
24
- rendered = @children.map(&props[:render])
24
+ def render(**props)
25
+ rendered = @children.map(&props[:render])
25
26
 
26
- without_blanks = rendered.reject(&:empty?)
27
- without_blanks.join("\n")
27
+ without_blanks = rendered.reject(&:empty?)
28
+ without_blanks.join("\n")
29
+ end
28
30
  end
29
31
  end
@@ -1,39 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Squeeze immediate consecutive soft breaks.
4
- #
5
- # Squeeze.new do
6
- # [
7
- # SoftBreak.new,
8
- # ConditionalComponent.new,
9
- #
10
- # SoftBreak.new,
11
- # false && SomeOtherComponent.new,
12
- #
13
- # SoftBreak.new,
14
- # 'hello',
15
- # ]
16
- # end
17
- # # => ""
18
- # # "hello"
19
- #
20
- # The soft breaks for each conditional component will be preserved only
21
- # if they do render some content.
22
- class Eskimo::ASCII::Squeeze
23
- def initialize(children)
24
- if !children.is_a?(Array) || block_given?
25
- raise ArgumentError.new("Squeeze works only with an Array of components")
26
- end
3
+ module Eskimo::ASCII
4
+ # Squeeze immediate consecutive soft breaks.
5
+ #
6
+ # Squeeze.new do
7
+ # [
8
+ # SoftBreak.new,
9
+ # ConditionalComponent.new,
10
+ #
11
+ # SoftBreak.new,
12
+ # false && SomeOtherComponent.new,
13
+ #
14
+ # SoftBreak.new,
15
+ # 'hello',
16
+ # ]
17
+ # end
18
+ # # => ""
19
+ # # "hello"
20
+ #
21
+ # The soft breaks for each conditional component will be preserved only
22
+ # if they do render some content.
23
+ class Squeeze
24
+ def initialize(children)
25
+ if !children.is_a?(Array) || block_given?
26
+ raise ArgumentError.new("Squeeze works only with an Array of components")
27
+ end
27
28
 
28
- @children = children
29
- end
29
+ @children = children
30
+ end
30
31
 
31
- def render(**props)
32
- rendered = @children.map(&props[:render])
32
+ def render(**props)
33
+ rendered = @children.map(&props[:render])
33
34
 
34
- without_blanks = rendered.reject(&:empty?)
35
- without_blanks.reject.with_index do |element, index|
36
- element == "\n" && without_blanks[index+1] == "\n"
35
+ without_blanks = rendered.reject(&:empty?)
36
+ without_blanks.reject.with_index do |element, index|
37
+ element == "\n" && without_blanks[index+1] == "\n"
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Remove surrounding whitespace.
4
- #
5
- # Strip.new { " hello world " }
6
- # # => "hello world"
7
- class Eskimo::ASCII::Strip < Eskimo::ASCII::Component
8
- def render(**)
9
- super.strip
3
+ module Eskimo::ASCII
4
+ # Remove surrounding whitespace.
5
+ #
6
+ # Strip.new { " hello world " }
7
+ # # => "hello world"
8
+ class Strip < Component
9
+ def render(**)
10
+ super.strip
11
+ end
10
12
  end
11
13
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Remove whitespace from the beginning.
4
- #
5
- # StripLeft.new { " hello world " }
6
- # # => "hello world "
7
- class Eskimo::ASCII::StripLeft < Eskimo::ASCII::Component
8
- def render(**)
9
- super.lstrip
3
+ module Eskimo::ASCII
4
+ # Remove whitespace from the beginning.
5
+ #
6
+ # StripLeft.new { " hello world " }
7
+ # # => "hello world "
8
+ class StripLeft < Component
9
+ def render(**)
10
+ super.lstrip
11
+ end
10
12
  end
11
13
  end
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Remove whitespace from the end.
4
- #
5
- # StripRight.new { " hello world " }
6
- # # => " hello world"
7
- class Eskimo::ASCII::StripRight < Eskimo::ASCII::Component
8
- def render(**)
9
- super.rstrip
3
+ module Eskimo::ASCII
4
+ # Remove whitespace from the end.
5
+ #
6
+ # StripRight.new { " hello world " }
7
+ # # => " hello world"
8
+ class StripRight < Component
9
+ def render(**)
10
+ super.rstrip
11
+ end
10
12
  end
11
13
  end
@@ -1,21 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Style text with colors and custom formatting.
4
- #
5
- # See [Pastel's documentation][pastel] for the accepted styles.
6
- #
7
- # [pastel]: https://github.com/piotrmurach/pastel
8
- class Eskimo::ASCII::Style < Eskimo::ASCII::Component
9
- attr_reader :pastel, :style
3
+ module Eskimo::ASCII
4
+ # Style text with colors and custom formatting.
5
+ #
6
+ # See [Pastel's documentation][pastel] for the accepted styles.
7
+ #
8
+ # [pastel]: https://github.com/piotrmurach/pastel
9
+ class Style < Component
10
+ attr_reader :pastel, :style
10
11
 
11
- def initialize(*style, &children)
12
- @style = style.flatten
13
- @pastel = Pastel.new
12
+ def initialize(*style, &children)
13
+ @style = style.flatten
14
+ @pastel = Pastel.new
14
15
 
15
- super
16
- end
16
+ super
17
+ end
17
18
 
18
- def render(**)
19
- pastel.decorate(super, *style)
19
+ def render(**)
20
+ pastel.decorate(super, *style)
21
+ end
20
22
  end
21
23
  end
@@ -1,27 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Truncate text from the beginning if it exceeds a certain width.
4
- #
5
- # Truncate.new(width: 3) do
6
- # "foo bar"
7
- # end
8
- # # => "... bar"
9
- class Eskimo::ASCII::Truncate < Eskimo::ASCII::Component
10
- attr_reader :maxlen
3
+ module Eskimo::ASCII
4
+ # Truncate text from the beginning if it exceeds a certain width.
5
+ #
6
+ # Truncate.new(width: 3) do
7
+ # "foo bar"
8
+ # end
9
+ # # => "... bar"
10
+ class Truncate < Component
11
+ attr_reader :maxlen
11
12
 
12
- def initialize(reserve: 0, width: Constants::SCREEN_COLUMNS, &children)
13
- @maxlen = [0, width - reserve].max
13
+ def initialize(reserve: 0, width: Constants::SCREEN_COLUMNS, &children)
14
+ @maxlen = [0, width - reserve].max
14
15
 
15
- super
16
- end
16
+ super
17
+ end
17
18
 
18
- def render(**)
19
- text = super
19
+ def render(**)
20
+ text = super
20
21
 
21
- if text.length >= maxlen
22
- '...' + text[text.length - maxlen - 1 .. -1]
23
- else
24
- text
22
+ if text.length >= maxlen
23
+ '...' + text[text.length - maxlen - 1 .. -1]
24
+ else
25
+ text
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -2,20 +2,22 @@
2
2
 
3
3
  require 'eskimo/ascii/components/truncate'
4
4
 
5
- # Truncate text from the rear if it exceeds a certain width.
6
- #
7
- # TruncateRear.new(width: 3) do
8
- # "foo bar"
9
- # end
10
- # # => "foo..."
11
- class Eskimo::ASCII::TruncateRear < Eskimo::ASCII::Truncate
12
- def render(render:, **)
13
- text = render[@children]
5
+ module Eskimo::ASCII
6
+ # Truncate text from the rear if it exceeds a certain width.
7
+ #
8
+ # TruncateRear.new(width: 3) do
9
+ # "foo bar"
10
+ # end
11
+ # # => "foo..."
12
+ class TruncateRear < Truncate
13
+ def render(render:, **)
14
+ text = render[@children]
14
15
 
15
- if text.length >= maxlen
16
- text[0..maxlen - 1] + '...'
17
- else
18
- text
16
+ if text.length >= maxlen
17
+ text[0..maxlen - 1] + '...'
18
+ else
19
+ text
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Eskimo::ASCII::Constants
4
- SCREEN_COLUMNS = [TTY::Screen.width, 72].min
3
+ module Eskimo::ASCII
4
+ module Constants
5
+ SCREEN_COLUMNS = [TTY::Screen.width, 72].min
6
+ end
5
7
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Eskimo
4
4
  module ASCII
5
- VERSION = '3.0.0.pre.2'
5
+ VERSION = '3.0.0.pre.3'
6
6
  end
7
7
  end
@@ -10,4 +10,10 @@ RSpec.describe Eskimo::ASCII::Component do
10
10
  }
11
11
  ).to eq("hello\nworld!")
12
12
  end
13
+
14
+ it 'provides a pastel for giggles' do
15
+ expect(
16
+ Eskimo::ASCII::Component.new.send(:pastel)
17
+ ).to be_a(Pastel::Delegator)
18
+ end
13
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eskimo-ascii
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.2
4
+ version: 3.0.0.pre.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmad Amireh
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: eskimo-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0.pre.2
19
+ version: 3.0.0.pre.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0.pre.2
26
+ version: 3.0.0.pre.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pastel
29
29
  requirement: !ruby/object:Gem::Requirement