Class: Vedeu::Editor::Editor Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/editor/editor.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.

Handles keypresses for a named document whilst the terminal is in fake mode.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, name:) ⇒ Vedeu::Editor::Editor

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 a new instance of Vedeu::Editor::Editor.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • input (String|Symbol)


43
44
45
46
# File 'lib/vedeu/editor/editor.rb', line 43

def initialize(input:, name:)
  @input = input
  @name  = name
end

Instance Attribute Details

#inputSymbol|String (readonly, protected)

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:

  • (Symbol|String)


74
75
76
# File 'lib/vedeu/editor/editor.rb', line 74

def input
  @input
end

#nameNilClass|Symbol|String (readonly, protected)

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 name of the model, the target model or the name of the associated model.

Returns:

  • (NilClass|Symbol|String)

    The name of the model, the target model or the name of the associated model.



78
79
80
# File 'lib/vedeu/editor/editor.rb', line 78

def name
  @name
end

Class Method Details

.keypress(input:, name:) ⇒ String|Symbol

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.

Send given input to the named document.

Parameters:

  • name (NilClass|Symbol|String)

    The name of the model or target model to act upon. May default to ‘Vedeu.focus`.

  • input (String|Symbol)

Returns:

  • (String|Symbol)


34
35
36
# File 'lib/vedeu/editor/editor.rb', line 34

def self.keypress(input:, name:)
  new(input: input, name: name).keypress
end

Instance Method Details

#documentVedeu::Editor::Document (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.

Returns the named document from the documents repository.



83
84
85
# File 'lib/vedeu/editor/editor.rb', line 83

def document
  @document ||= Vedeu.documents.by_name(name)
end

#keypressString|Symbol

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.

Send given input to the named document.

Returns:

  • (String|Symbol)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vedeu/editor/editor.rb', line 51

def keypress
  return input unless document

  case input
  when :backspace then delete_character
  when :delete    then delete_line
  when :ctrl_c    then Vedeu.trigger(:_exit_)
  when :down      then down
  when :enter     then insert_line
  when :escape    then Vedeu.trigger(:_mode_switch_)
  when :left      then left
  when :right     then right
  when :tab       then execute
  when :up        then up
  else
    insert_character(input)
  end
end