Module: VER

Defined in:
lib/rbcurse/core/system/ncurses.rb,
lib/rbcurse/core/system/window.rb,
lib/rbcurse/core/system/keyboard.rb

Overview

include FFI::NCurses # this pollutes many objects and invalidates method_missing

Defined Under Namespace

Modules: Keyboard Classes: Window

Class Method Summary collapse

Class Method Details

.start_ncursesObject

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rbcurse/core/system/ncurses.rb', line 7

def start_ncurses
  return if $ncurses_started
  $ncurses_started = true
  # in case we want a blocking getch, you may want to first
  # set wtimeout to -1, and then reset it to this value.
  # Please first check that we are using this.
  $ncurses_wtimeout = 500 # used by windows for timeout of wgetch

  # 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  ## FFI

#    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.pointer, bf = true) # FFIWINDOW
  #Ncurses.keypad(stdscr, bf = true)
    #Ncurses.stdscr.keypad(true)     # turn on keypad mode FFI
  #Ncurses.keypad(stdscr, bf = 1)

  # 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
  # I have removed cbreak and halfdelay since they were causing C-c
  # to crash if i pressed it in succession

  # 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)
  # See above why switched off

  # 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.
  # I am using the next line for the window when creating, this does not
  # have any impact on window.
  # For this to have any effect your getch should be Ncurses.getch and not
  # wgetch(@window), For that do this with window.
  # I am disableing this 2011-12-20 since it does not work with combinations
  # such as gg. Any routine that does a getch will just immediatelt return an ERR.
  #Ncurses::nodelay(stdscr.pointer, bf = true)

  # added these 2 so we can do resizing based on original and current size when terminal resized
  #  2012-01-8 
  $orig_cols = FFI::NCurses.COLS
  $orig_rows = FFI::NCurses.LINES
end

.stop_ncursesObject

this should happen only in outermost program that started ncurses if a called program does this, the calling program can have a display freeze



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rbcurse/core/system/ncurses.rb', line 112

def stop_ncurses
  Ncurses.echo
  Ncurses.nocbreak
  Ncurses.nl
  Ncurses.endwin
  $ncurses_started = false
  #puts "curses over"
ensure
  return unless error = @last_error
  #log = RbConfig[: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