Class: UI::Canvas
- Inherits:
-
Object
- Object
- UI::Canvas
- Defined in:
- lib/ektoplayer/ui.rb
Class Method Summary collapse
- .enable_resize_detection ⇒ Object
- .run ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
- .sub(cls, **opts) ⇒ Object
- .update_screen(force_redraw = false, force_resize = false) ⇒ Object
- .widget ⇒ Object
- .widget=(w) ⇒ Object
Class Method Details
.enable_resize_detection ⇒ Object
27 28 29 |
# File 'lib/ektoplayer/ui.rb', line 27 def self.enable_resize_detection Signal.trap('WINCH') { @@want_resize = true } end |
.run ⇒ Object
66 67 68 69 70 71 |
# File 'lib/ektoplayer/ui.rb', line 66 def self.run self.start yield ensure self.stop end |
.start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ektoplayer/ui.rb', line 13 def self.start @@widget = nil @@want_resize = false @@updating = Mutex.new %w(initscr cbreak noecho start_color use_default_colors). each(&ICurses.method(:send)) ICurses.mousemask(ICurses::ALL_MOUSE_EVENTS | ICurses::REPORT_MOUSE_POSITION) ICurses.stdscr.getch1(1) # first getch() clears screen? UI::Colors.start self.enable_resize_detection end |
.sub(cls, **opts) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/ektoplayer/ui.rb', line 35 def self.sub(cls, **opts) opts[:size] ||= UI::Size.new(height: ICurses.lines, width: ICurses.cols) opts[:pos] ||= UI::Point.new = cls.new(**opts) @@widget ||= end |
.update_screen(force_redraw = false, force_resize = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ektoplayer/ui.rb', line 43 def self.update_screen(force_redraw=false, force_resize=false) if @@updating.try_lock begin if @@want_resize or force_resize @@want_resize = false h, w = IO.console.winsize() ICurses.resizeterm(h, w) @@widget.size=(Size.new(height: h, width: w)) if @@widget @@widget.display(true, true, true) if @@widget else @@widget.display(true, force_redraw) if @@widget end rescue UI::WidgetSizeError ICurses.stdscr.clear ICurses.stdscr.addstr('terminal too small!') rescue Ektoplayer::Application.log(self, $!) end @@updating.unlock end end |
.widget ⇒ Object
31 |
# File 'lib/ektoplayer/ui.rb', line 31 def self.; @@widget end |
.widget=(w) ⇒ Object
32 |
# File 'lib/ektoplayer/ui.rb', line 32 def self.(w) @@widget = w end |