class Minder::TaskEditor

Attributes

cursor_position[R]

Public Class Methods

new(task, parent) click to toggle source
# File lib/minder/cli/task_editor.rb, line 9
def initialize(task, parent)
  @original_text = task.description.dup
  @cursor_position = 0
  @task = task
  @parent = parent
end

Public Instance Methods

handle_char_keypress(key) click to toggle source
# File lib/minder/cli/task_editor.rb, line 60
def handle_char_keypress(key)
  @task.description.insert(@cursor_position, key)
  @cursor_position += 1

  changed
  notify_observers(:redraw)
end
handle_keypress(key) click to toggle source
# File lib/minder/cli/task_editor.rb, line 20
def handle_keypress(key)
  return unless key

  if key.is_a?(Fixnum)
      handle_non_char_keypress(key)
  else
    handle_char_keypress(key)
  end
end
handle_non_char_keypress(key) click to toggle source
# File lib/minder/cli/task_editor.rb, line 30
def handle_non_char_keypress(key)
  return unless key

  data = {}

  event =
    case key
    when Curses::Key::LEFT
      @cursor_position -= 1 unless cursor_position == 0
      :redraw
    when Curses::Key::RIGHT
      @cursor_position += 1 unless cursor_position > text.length - 1
      :redraw
    when *Curses::Key::BACKSPACE, 127
      return if @cursor_position == 0
      @task.description.slice!(@cursor_position - 1)
      @cursor_position -= 1 unless cursor_position == 0
      :redraw
    when 27, 9
      @task.description = @original_text
      :stop_editing
    when 10
      data = { description: @task.description }
      :update_task
    end

  changed
  notify_observers(event, data)
end
text() click to toggle source
# File lib/minder/cli/task_editor.rb, line 16
def text
  @task.description
end