Class: Twterm::Notifier
- Inherits:
-
Object
- Object
- Twterm::Notifier
- Includes:
- Curses, Singleton
- Defined in:
- lib/twterm/notifier.rb
Instance Method Summary collapse
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #resize ⇒ Object
- #show(notification = nil) ⇒ Object
- #show_error(message) ⇒ Object
- #show_message(message) ⇒ Object
Constructor Details
#initialize ⇒ Notifier
Returns a new instance of Notifier.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/twterm/notifier.rb', line 6 def initialize @window = stdscr.subwin(1, stdscr.maxx, stdscr.maxy - 2, 0) @queue = Queue.new Thread.new do while notification = @queue.pop show(notification) sleep 3 show end end end |
Instance Method Details
#resize ⇒ Object
19 20 21 22 |
# File 'lib/twterm/notifier.rb', line 19 def resize @window.resize(1, stdscr.maxx) @window.move(stdscr.maxy - 2, 0) end |
#show(notification = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/twterm/notifier.rb', line 36 def show(notification = nil) loop do break unless closed? sleep 0.5 end @window.clear if notification.is_a? Notification::Base @window.with_color(notification.fg_color, notification.bg_color) do @window.setpos(0, 0) @window.addstr(' ' * @window.maxx) @window.setpos(0, 1) time = notification.time.strftime('[%H:%M:%S]') = notification.show_with_width(@window.maxx) @window.addstr("#{time} #{}") end end @window.refresh end |
#show_error(message) ⇒ Object
24 25 26 27 28 |
# File 'lib/twterm/notifier.rb', line 24 def show_error() notification = Notification::Error.new() @queue.push(notification) self end |
#show_message(message) ⇒ Object
30 31 32 33 34 |
# File 'lib/twterm/notifier.rb', line 30 def () notification = Notification::Message.new() @queue.push(notification) self end |