Class: Vedeu::Editor::Document Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Document
- Extended by:
- Forwardable
- Includes:
- Repositories::Defaults, Repositories::Model
- Defined in:
- lib/vedeu/editor/document.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.
A collection of keypresses ordered by input.
Instance Attribute Summary collapse
- #attributes ⇒ Hash<Symbol => String|Symbol| Vedeu::Repositories::Repository> readonly private
- #data ⇒ String
-
#name ⇒ NilClass|Symbol|String
The name of the model, the target model or the name of the associated model.
Attributes included from Repositories::Model
Instance Method Summary collapse
-
#cursor ⇒ Vedeu::Editor::Cursor
private
private
Return a virtual cursor to track the cursor position within the document.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#delete_character ⇒ Vedeu::Editor::Document
private
Deletes the character from the line where the cursor is currently positioned.
-
#delete_line ⇒ Vedeu::Editor::Document
private
Delete a line.
- #document_start? ⇒ Boolean private private
-
#down ⇒ Vedeu::Editor::Document
private
Move the virtual cursor down.
-
#execute ⇒ String
private
Returns the document as a string with line breaks if there is more than one line.
- #first_char? ⇒ Boolean private private
- #first_line? ⇒ Boolean private private
-
#insert_character(character) ⇒ Vedeu::Editor::Document
private
Inserts the given character in to the line where the cursor is currently positioned.
-
#insert_line ⇒ Vedeu::Editor::Document
private
Insert an empty line.
- #last_char? ⇒ Boolean private private
- #last_line? ⇒ Boolean private private
-
#left ⇒ Vedeu::Editor::Document
private
Move the virtual cursor left.
-
#line(index = y) ⇒ Array<String|void>
private
Returns the current line from the collection of lines.
-
#lines ⇒ Array<String|void>
private
Returns the collection of lines which constitutes the document content.
- #next_line_size ⇒ Fixnum private private
-
#output ⇒ Array<Vedeu::Cells::Char>
private
private
Return the data needed to render the document, based on the current virtual cursor position.
- #prev_line_size ⇒ Fixnum private private
-
#refresh ⇒ Vedeu::Editor::Document
private
Store the document in the documents repository, clear and send the content to the terminal.
-
#reset! ⇒ Vedeu::Editor::Document
private
Reset the document to the empty state.
-
#right ⇒ Vedeu::Editor::Document
private
Move the virtual cursor right.
-
#up ⇒ Vedeu::Editor::Document
private
Move the virtual cursor up.
Methods included from Repositories::Model
Methods included from Repositories::Defaults
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Attribute Details
#attributes ⇒ Hash<Symbol => String|Symbol| Vedeu::Repositories::Repository> (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.
26 27 28 |
# File 'lib/vedeu/editor/document.rb', line 26 def attributes @attributes end |
#data ⇒ String
30 31 32 |
# File 'lib/vedeu/editor/document.rb', line 30 def data @data end |
#name ⇒ NilClass|Symbol|String
Returns The name of the model, the target model or the name of the associated model.
34 35 36 |
# File 'lib/vedeu/editor/document.rb', line 34 def name @name end |
Instance Method Details
#cursor ⇒ Vedeu::Editor::Cursor (private)
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.
Return a virtual cursor to track the cursor position within the document.
215 216 217 |
# File 'lib/vedeu/editor/document.rb', line 215 def cursor @cursor ||= Vedeu::Editor::Cursor.new(name: name) end |
#defaults ⇒ Hash<Symbol => void> (private)
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.
The default options/attributes for a new instance of this class.
220 221 222 223 224 225 226 |
# File 'lib/vedeu/editor/document.rb', line 220 def defaults { data: Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new]), name: nil, repository: Vedeu.documents, } end |
#delete_character ⇒ Vedeu::Editor::Document
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.
Deletes the character from the line where the cursor is currently positioned.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vedeu/editor/document.rb', line 56 def delete_character return self if document_start? if first_char? && y > 0 delete_line return else @lines = lines.delete_character(y, x - 1) left end refresh end |
#delete_line ⇒ Vedeu::Editor::Document
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.
Delete a line.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vedeu/editor/document.rb', line 77 def delete_line @lines = lines.delete_line(y) up cursor.x = line.size cursor.refresh refresh end |
#document_start? ⇒ Boolean (private)
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.
207 208 209 |
# File 'lib/vedeu/editor/document.rb', line 207 def document_start? first_char? && first_line? end |
#down ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor down.
196 197 198 199 200 201 202 |
# File 'lib/vedeu/editor/document.rb', line 196 def down return self if last_line? cursor.down(next_line_size).refresh self end |
#execute ⇒ 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.
Returns the document as a string with line breaks if there is more than one line.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vedeu/editor/document.rb', line 40 def execute command = lines.map(&:to_s).join("\n") reset! Vedeu.clear_content_by_name(name) if Vedeu.ready? Vedeu.trigger(:_command_, command) command end |
#first_char? ⇒ Boolean (private)
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.
229 230 231 |
# File 'lib/vedeu/editor/document.rb', line 229 def first_char? x - 1 < 0 end |
#first_line? ⇒ Boolean (private)
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.
234 235 236 |
# File 'lib/vedeu/editor/document.rb', line 234 def first_line? y - 1 < 0 end |
#insert_character(character) ⇒ Vedeu::Editor::Document
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.
Inserts the given character in to the line where the cursor is currently positioned.
94 95 96 97 98 99 100 101 102 |
# File 'lib/vedeu/editor/document.rb', line 94 def insert_character(character) return self if symbol?(character) @lines = lines.insert_character(character, y, x) right refresh end |
#insert_line ⇒ Vedeu::Editor::Document
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.
Insert an empty line.
107 108 109 110 111 112 113 |
# File 'lib/vedeu/editor/document.rb', line 107 def insert_line @lines = lines.insert_line(y + 1) down refresh end |
#last_char? ⇒ Boolean (private)
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.
239 240 241 |
# File 'lib/vedeu/editor/document.rb', line 239 def last_char? x + 1 > line.size end |
#last_line? ⇒ Boolean (private)
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.
244 245 246 |
# File 'lib/vedeu/editor/document.rb', line 244 def last_line? y + 1 >= lines.size end |
#left ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor left.
163 164 165 166 167 168 169 |
# File 'lib/vedeu/editor/document.rb', line 163 def left return self if first_char? cursor.left.refresh self end |
#line(index = y) ⇒ Array<String|void>
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 current line from the collection of lines.
119 120 121 |
# File 'lib/vedeu/editor/document.rb', line 119 def line(index = y) lines.line(index) end |
#lines ⇒ Array<String|void>
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 collection of lines which constitutes the document content.
127 128 129 |
# File 'lib/vedeu/editor/document.rb', line 127 def lines @lines ||= Vedeu::Editor::Lines.coerce(data) end |
#next_line_size ⇒ Fixnum (private)
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.
249 250 251 |
# File 'lib/vedeu/editor/document.rb', line 249 def next_line_size line(y + 1).size end |
#output ⇒ Array<Vedeu::Cells::Char> (private)
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.
Return the data needed to render the document, based on the current virtual cursor position. This output may be a cropped representation of the full document depending on the size of the interface.
259 260 261 262 263 264 |
# File 'lib/vedeu/editor/document.rb', line 259 def output Vedeu::Editor::Cropper.new(lines: lines, name: name, ox: ox, oy: oy). end |
#prev_line_size ⇒ Fixnum (private)
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.
267 268 269 |
# File 'lib/vedeu/editor/document.rb', line 267 def prev_line_size line(y - 1).size end |
#refresh ⇒ Vedeu::Editor::Document
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.
Store the document in the documents repository, clear and send the content to the terminal.
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/vedeu/editor/document.rb', line 148 def refresh store Vedeu.clear_content_by_name(name) if Vedeu.ready? Vedeu.buffer_update(output) Vedeu.direct_write(output.map(&:to_s).join) self end |
#reset! ⇒ Vedeu::Editor::Document
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.
Reset the document to the empty state.
134 135 136 137 138 139 140 141 142 |
# File 'lib/vedeu/editor/document.rb', line 134 def reset! @cursor = cursor.reset! @lines = defaults[:data] cursor.refresh refresh end |
#right ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor right.
174 175 176 177 178 179 180 |
# File 'lib/vedeu/editor/document.rb', line 174 def right return self if last_char? cursor.right.refresh self end |
#up ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor up.
185 186 187 188 189 190 191 |
# File 'lib/vedeu/editor/document.rb', line 185 def up return self if first_line? cursor.up(prev_line_size).refresh self end |