Class: Popup
Overview
A simple centralized popup on the terminal.
Instance Attribute Summary
Attributes inherited from Screen
Instance Method Summary collapse
-
#initialize(title, text) ⇒ Popup
constructor
Creates a Popup with ‘title` and inner `text`.
-
#show ⇒ Object
Makes the Popup appear on the screen and wait for any key.
Methods inherited from Screen
#background, #box, #clear, #move, #mvaddch, #mvaddstr, #mvaddstr_center, #mvaddstr_left, #mvaddstr_right, #refresh, #resize, #set_color, #timeout, #with_color
Constructor Details
#initialize(title, text) ⇒ Popup
Creates a Popup with ‘title` and inner `text`.
It resizes to contain the whole text plus a 1x1 border around itself.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tabscroll/popup.rb', line 11 def initialize(title, text) @title = title @text = [] text.each_line do |line| @text += [line.chomp] end max_width = title.length max_height = 1 @text.each do |line| max_width = line.length if line.length > max_width max_height += 1 end max_width += 2 # left-right borders max_height += 1 # down border x = Curses::cols/2 - max_width/2 y = Curses::lines/2 - max_height/2 super(x, y, max_width, max_height) self.background ' ' self.box self.mvaddstr_center(0, title, Engine::Colors[:cyan]) y = 1 @text.each do |line| self.mvaddstr(1, y, line) y += 1 end end |
Instance Method Details
#show ⇒ Object
Makes the Popup appear on the screen and wait for any key. When it exits, clears the screen erasing itself.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tabscroll/popup.rb', line 47 def show finished = false while not finished c = Curses::getch case c when 'q' return true when 'h' finished = true end end Curses::stdscr.clear Curses::stdscr.refresh return false end |