Class: Alchemist::Curses::GlyphWindow
- Includes:
- FFI::NCurses
- Defined in:
- lib/alchemist-server/curses/glyph_window.rb
Constant Summary collapse
- ROWS =
21
- COLS =
48
Instance Method Summary collapse
- #characters ⇒ Object
- #draw ⇒ Object
- #have_user_select ⇒ Object
-
#initialize(line, col) ⇒ GlyphWindow
constructor
A new instance of GlyphWindow.
- #range_end ⇒ Object
- #range_start ⇒ Object
- #reset_cursor ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(line, col) ⇒ GlyphWindow
Returns a new instance of GlyphWindow.
9 10 11 12 13 14 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 9 def initialize(line,col) @width = (COLS + 2)*2 @win = newwin ROWS, @width, line, col @starting_char = 0 @cursor_offset = 0 end |
Instance Method Details
#characters ⇒ Object
29 30 31 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 29 def characters Glyphs.strings[range_start..range_end] || [] end |
#draw ⇒ Object
16 17 18 19 20 21 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 16 def draw wmove @win, 0, 0 wclear @win wprintw @win, rows.pad_to_unicode_monospace reset_cursor end |
#have_user_select ⇒ Object
49 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 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 49 def have_user_select draw wmove @win, 0, 0 wrefresh @win while (c = getch) != KEY_RETURN y,x = getyx @win case c when KEY_ESCAPE return nil when KEY_LEFT @cursor_offset = [@cursor_offset - 1, 0].max reset_cursor when KEY_RIGHT @cursor_offset = [@cursor_offset + 1, (ROWS*COLS)].min reset_cursor when KEY_UP @cursor_offset = [@cursor_offset - COLS, 0].max reset_cursor when KEY_DOWN @cursor_offset = [@cursor_offset + COLS, (ROWS*COLS)].min reset_cursor when '0'.ord @starting_char += ROWS*COLS draw when '9'.ord @starting_char = [@starting_char-ROWS*COLS,0].max draw end end characters[@cursor_offset] ensure wclear @win wrefresh @win end |
#range_end ⇒ Object
45 46 47 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 45 def range_end @starting_char + ROWS*COLS end |
#range_start ⇒ Object
41 42 43 |
# File 'lib/alchemist-server/curses/glyph_window.rb', line 41 def range_start @starting_char end |