Class: LessCurse::Widgets::TextArea

Inherits:
Base
  • Object
show all
Defined in:
lib/less_curse/widgets/text_area.rb

Instance Attribute Summary

Attributes inherited from Base

#actions, #data, #title

Instance Method Summary collapse

Methods inherited from Base

#focused?, #initialize, #set_default_actions, #unfocus

Constructor Details

This class inherits a constructor from LessCurse::Widgets::Base

Instance Method Details

#draw(window) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/less_curse/widgets/text_area.rb', line 4

def draw window
  LessCurse::Renderer::bold_if(focused?, window) do
    LessCurse::Renderer::box_with_title window, @title
  end
  FFI::NCurses.wmove window, 1, 1
  @data.to_s.split("\n").each_with_index do |line, idx|
    FFI::NCurses.mvwaddstr window, idx + 1, 1, line
  end
end

#focusObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/less_curse/widgets/text_area.rb', line 25

def focus
  @focus = true
  ## Initial experiments where done with cbreak and echo
  #FFI::NCurses.echo
  #FFI::NCurses.nocbreak # can ctrl-c, not waiting for newlines to end input.
  ##@data = ... but master.refresh afterwards ..
  #window = LessCurse.screen.windows[self]
  ##FFI::NCurses::mvwgetstr window, 4, 3, @data
  ##@data += FFI::NCurses::wget_wstr window
  #@data += FFI::NCurses::wgetch(window).chr
  ## from ffi/ncurses getkey example
  # #buffer = FFI::Buffer.new(FFI::NCurses.find_type(:wint_t))
  refresh
end

#handle_input(key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/less_curse/widgets/text_area.rb', line 14

def handle_input key
  # Its a PITA to redo all the readline loveliness, but it gets us right
  # into doing things.  Would be cool to have moving cursor on ENTER
  if key == FFI::NCurses::KEY_BACKSPACE
    @data = @data[0..-2]
  else
    # Handle out of range stuff
    @data += key.chr rescue false
  end
end