Module: VER
- Includes:
- ColorMap
- Defined in:
- lib/ver/keyboard2.rb,
lib/ver/window.rb,
lib/ver/ncurses.rb,
lib/ver/keyboard.rb
Overview
Usage:
VER::Keyboard2.focus = self
or whatever class you have created.
DEPENDENCIES:
press(key) - a method that takes an int key and processes it
stopping? returns true of false. if false, this prgram returns control
window - gives window of caller, responding to getch
2008-11-24 12:41
this differs from original in that i try to return an int so it can just replace
existing loops without any modification
I thus return an int not a string
Defined Under Namespace
Modules: Keyboard, Keyboard2 Classes: Pad, SubWindow, Window
Class Method Summary collapse
-
.start_ncurses ⇒ Object
Setup ncurses, nicely documented by the curses manpages.
- .stop_ncurses ⇒ Object
Methods included from ColorMap
colors, get_color, get_color_const, install_color, setup
Class Method Details
.start_ncurses ⇒ Object
Setup ncurses, nicely documented by the curses manpages
7 8 9 10 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 44 45 46 47 48 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 |
# File 'lib/ver/ncurses.rb', line 7 def start_ncurses # The initscr code determines the terminal type and initializes all curses # data structures. # initscr also causes the first call to refresh to clear the screen. # If errors occur, initscr writes an appropriate error message to standard # error and exits; otherwise, a pointer is returned to stdscr. stdscr = Ncurses.initscr # Color.start if Ncurses.has_colors? Ncurses.start_color(); ColorMap.setup # added by RK 2008-11-30 00:48 # The keypad option enables the keypad of the user's terminal. # If enabled (bf is TRUE), the user can press a function key (such as an # arrow key) and wgetch returns a single value representing the function # key, as in KEY_LEFT. # If disabled (bf is FALSE), curses does not treat function keys specially # and the program has to interpret the escape sequences itself. # If the keypad in the terminal can be turned on (made to transmit) and off # (made to work locally), turning on this option causes the terminal keypad # to be turned on when wgetch is called. # The default value for keypad is false. Ncurses.keypad(stdscr, bf = true) # The nl and nonl routines control whether the underlying display device # translates the return key into newline on input, and whether it # translates newline into return and line-feed on output (in either case, # the call addch('\n') does the equivalent of return and line feed on the # virtual screen). # Initially, these translations do occur. # If you disable them using nonl, curses will be able to make better use of # the line-feed capability, resulting in faster cursor motion. # Also, curses will then be able to detect the return key. Ncurses.nonl # The raw and noraw routines place the terminal into or out of raw mode. # Raw mode is similar to cbreak mode, in that characters typed are # immediately passed through to the user program. # The differences are that in raw mode, the interrupt, quit, suspend, and # flow control characters are all passed through uninterpreted, instead of # generating a signal. # The behavior of the BREAK key depends on other bits in the tty driver # that are not set by curses. Ncurses.raw # Normally, the tty driver buffers typed characters until a newline or # carriage return is typed. # The cbreak routine disables line buffering and # erase/kill character-processing (interrupt and flow control characters # are unaffected), making characters typed by the user immediately # available to the program. Ncurses.cbreak # The echo and noecho routines control whether characters typed by the user # are echoed by getch as they are typed. # Echoing by the tty driver is always disabled, but initially getch is in # echo mode, so characters typed are echoed. Ncurses.noecho # The curs_set routine sets the cursor state is set to invisible, normal, # or very visible for visibility equal to 0, 1, or 2 respectively. # If the terminal supports the visibility requested, the previous cursor # state is returned; otherwise, ERR is returned. Ncurses.curs_set(1) # The halfdelay routine is used for half-delay mode, which is similar to # cbreak mode in that characters typed by the user are immediately # available to the program. # However, after blocking for tenths tenths of seconds, ERR is returned if # nothing has been typed. # The value of tenths must be a number between 1 and 255. # Use nocbreak to leave half-delay mode. Ncurses::halfdelay(tenths = 10) # The nodelay option causes getch to be a non-blocking call. If no input is # ready, getch returns ERR. If disabled (bf is FALSE), getch waits until a # key is pressed. # Ncurses::nodelay(Ncurses::stdscr, bf = true) end |
.stop_ncurses ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ver/ncurses.rb', line 86 def stop_ncurses Ncurses.echo Ncurses.nocbreak Ncurses.nl Ncurses.endwin ensure return unless error = @last_error log = Config[:logfile].value Kernel.warn "There may have been fatal errors logged to: #{log}." Kernel.warn "The most recent was:" $stderr.puts '' $stderr.puts @last_error_message if @last_error_message $stderr.puts @last_error, *@last_error.backtrace end |