Class: LLM::Repl::Node Private
- Inherits:
-
Object
- Object
- LLM::Repl::Node
- Defined in:
- lib/llm/repl/node.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The LLM::Repl::Node class wraps a piece of text and optional curses attributes.
Instance Attribute Summary collapse
- #attrs ⇒ Integer? readonly private
- #text ⇒ String readonly private
Class Method Summary collapse
-
.slice(text, width) ⇒ String
private
Slices the given text so the returned piece has a display width of at most
widthcolumns. -
.width(text) ⇒ Integer
private
Returns the display width of the given text, counting wide characters such as emoji as two columns.
Instance Method Summary collapse
-
#[](key) ⇒ String, ...
private
Hash-like lookup.
- #initialize(text, attrs = nil) ⇒ LLM::Repl::Node constructor private
-
#size ⇒ Integer
(also: #length)
private
Returns the display width of the text.
Constructor Details
#initialize(text, attrs = nil) ⇒ LLM::Repl::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 |
# File 'lib/llm/repl/node.rb', line 45 def initialize(text, attrs = nil) @text = text.to_s @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Integer? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/llm/repl/node.rb', line 39 def attrs @attrs end |
#text ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/llm/repl/node.rb', line 35 def text @text end |
Class Method Details
.slice(text, width) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Slices the given text so the returned piece has a display width
of at most width columns.
24 25 26 27 28 29 30 31 |
# File 'lib/llm/repl/node.rb', line 24 def self.slice(text, width) out = +"" text.to_s.each_char do |char| break if self.width(out + char) > width out << char end out end |
.width(text) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the display width of the given text, counting wide characters such as emoji as two columns.
14 15 16 |
# File 'lib/llm/repl/node.rb', line 14 def self.width(text) Unicode::DisplayWidth.of(text.to_s) end |
Instance Method Details
#[](key) ⇒ String, ...
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hash-like lookup.
62 63 64 65 66 67 |
# File 'lib/llm/repl/node.rb', line 62 def [](key) case key when :text then @text when :attrs then @attrs end end |
#size ⇒ Integer Also known as: length
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the display width of the text
53 54 55 |
# File 'lib/llm/repl/node.rb', line 53 def size self.class.width(@text) end |