Class: LessCurse::Screen
- Inherits:
-
Object
- Object
- LessCurse::Screen
- Defined in:
- lib/less_curse/screen.rb
Instance Attribute Summary collapse
-
#focused_widget ⇒ Object
Returns the value of attribute focused_widget.
-
#footer ⇒ Object
Returns the value of attribute footer.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#header ⇒ Object
Returns the value of attribute header.
-
#popups ⇒ Object
Returns the value of attribute popups.
-
#size ⇒ Object
Returns the value of attribute size.
-
#windows ⇒ Object
Returns the value of attribute windows.
Instance Method Summary collapse
- #add(widget_or_grid) ⇒ Object
-
#focus_next ⇒ Object
Focus next element in #widgets.
-
#focus_previous ⇒ Object
Focus next element in #widgets.
-
#initialize ⇒ Screen
constructor
A new instance of Screen.
-
#repaint ⇒ Object
Repaint the screen and all contained widgets.
- #show ⇒ Object
- #show_popup(type = :info, content = 'Popup') ⇒ Object
- #widgets ⇒ Object
Constructor Details
#initialize ⇒ Screen
Returns a new instance of Screen.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/less_curse/screen.rb', line 11 def initialize # Need to initialize screen to access the terminal size FFI::NCurses.initscr height,width = FFI::NCurses::getmaxyx(FFI::NCurses::stdscr) @size = LessCurse::Geometry::Size.new(width,height) @windows = {} @focused_widget = nil @grid = LessCurse::Grid.new [[]] @popups = {} end |
Instance Attribute Details
#focused_widget ⇒ Object
Returns the value of attribute focused_widget.
6 7 8 |
# File 'lib/less_curse/screen.rb', line 6 def @focused_widget end |
#footer ⇒ Object
Returns the value of attribute footer.
8 9 10 |
# File 'lib/less_curse/screen.rb', line 8 def @footer end |
#grid ⇒ Object
Returns the value of attribute grid.
3 4 5 |
# File 'lib/less_curse/screen.rb', line 3 def grid @grid end |
#header ⇒ Object
Returns the value of attribute header.
7 8 9 |
# File 'lib/less_curse/screen.rb', line 7 def header @header end |
#popups ⇒ Object
Returns the value of attribute popups.
9 10 11 |
# File 'lib/less_curse/screen.rb', line 9 def popups @popups end |
#size ⇒ Object
Returns the value of attribute size.
5 6 7 |
# File 'lib/less_curse/screen.rb', line 5 def size @size end |
#windows ⇒ Object
Returns the value of attribute windows.
4 5 6 |
# File 'lib/less_curse/screen.rb', line 4 def windows @windows end |
Instance Method Details
#add(widget_or_grid) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/less_curse/screen.rb', line 23 def add if .is_a? LessCurse::Grid @grid = else @grid.add end recalc_window_sizes end |
#focus_next ⇒ Object
Focus next element in #widgets
89 90 91 |
# File 'lib/less_curse/screen.rb', line 89 def focus_next cycle_focus(+1) end |
#focus_previous ⇒ Object
Focus next element in #widgets
94 95 96 |
# File 'lib/less_curse/screen.rb', line 94 def focus_previous cycle_focus(-1) end |
#repaint ⇒ Object
Repaint the screen and all contained widgets
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/less_curse/screen.rb', line 50 def repaint FFI::NCurses.refresh # 'Draw' header and/or footer if @header && !@header.empty? FFI::NCurses::mvaddstr 0, 0, @header end if @footer && !@footer.empty? FFI::NCurses::mvaddstr @size.height - 1, 0, @footer end # Let all Widgets redraw themselfes .each do || window = @windows[] FFI::NCurses.wclear window .draw window FFI::NCurses.wrefresh window end @popups.each do |popup, window| FFI::NCurses.wclear window popup.draw window FFI::NCurses.wrefresh window end end |
#show ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/less_curse/screen.rb', line 36 def show @focused_widget = .first @focused_widget.focus if @focused_widget # Note that FFI::NCurses.initscr is called in initialize FFI::NCurses.cbreak # can ctrl-c, not waiting for newlines to end input. #FFI::NCurses.raw # TODO this overrides cbreak ... FFI::NCurses.noecho # do not echo input in win. FFI::NCurses.keypad FFI::NCurses::stdscr, true # recognize KEY_UP etc. FFI::NCurses.clear FFI::NCurses.refresh repaint end |
#show_popup(type = :info, content = 'Popup') ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/less_curse/screen.rb', line 76 def show_popup type=:info, content='Popup' # Lets take up quarter of screen and draw a boxed window = LessCurse::Widgets::Button.new title: content.to_s .focus = true area = LessCurse::Geometry::Rectangle.new @size.width / 4, @size.height / 4, @size.width / 2, @size.height / 2 @popups[] = LessCurse.window area end |
#widgets ⇒ Object
32 33 34 |
# File 'lib/less_curse/screen.rb', line 32 def @grid. end |