Module: Ncurses

Defined in:
lib/sup/colormap.rb,
lib/sup/util/ncurses.rb

Defined Under Namespace

Modules: Form Classes: CharCode

Constant Summary collapse

COLOR_DEFAULT =
-1
NUM_COLORS =
`tput colors`.to_i
MAX_PAIRS =
`tput pairs`.to_i
KEY_ENTER =
10
KEY_CANCEL =

ctrl-g

7
KEY_TAB =
9

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.color!(name, value) ⇒ Object



7
8
9
# File 'lib/sup/colormap.rb', line 7

def self.color! name, value
  const_set "COLOR_#{name.to_s.upcase}", value
end

.colsObject



186
187
188
189
190
# File 'lib/sup/util/ncurses.rb', line 186

def cols
  lame, lamer = [], []
  stdscr.getmaxyx lame, lamer
  lamer.first
end

.curxObject



192
193
194
195
196
# File 'lib/sup/util/ncurses.rb', line 192

def curx
  lame, lamer = [], []
  stdscr.getyx lame, lamer
  lamer.first
end

.mutexObject



237
# File 'lib/sup/util/ncurses.rb', line 237

def mutex; @mutex ||= Mutex.new; end

.prepare_form_driverObject

Create replacement wrapper for form_driver_w (), which is not (yet) a standard function in ncurses. Some systems (Mac OS X) does not have a working form_driver that accepts wide chars. We are just falling back to form_driver, expect problems.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/sup/util/ncurses.rb', line 201

def prepare_form_driver
  if not defined? Form.form_driver_w
    warn "Your Ncursesw does not have a form_driver_w function (wide char aware), " \
         "non-ASCII chars may not work on your system."
    Form.module_eval "      def form_driver_w form, status, c\n        form_driver form, c\n      end\n      module_function :form_driver_w\n      module DriverHelpers\n        def form_driver c\n          if !c.dumb? && c.printable?\n            c.each_byte do |code|\n              Ncurses::Form.form_driver @form, code\n            end\n          else\n            Ncurses::Form.form_driver @form, c.code\n          end\n        end\n      end\n    FRM_DRV\n  end # if not defined? Form.form_driver_w\n  if not defined? Ncurses.get_wch\n    warn \"Your Ncursesw does not have a get_wch function (wide char aware), \" \\\n         \"non-ASCII chars may not work on your system.\"\n    Ncurses.module_eval <<-GET_WCH, __FILE__, __LINE__ + 1\n      def get_wch\n        c = getch\n        c == Ncurses::ERR ? [c, 0] : [Ncurses::OK, c]\n      end\n      module_function :get_wch\n    GET_WCH\n    CharCode.dumb!\n  end # if not defined? Ncurses.get_wch\nend\n", __FILE__, __LINE__ + 1

.rowsObject

class CharCode



180
181
182
183
184
# File 'lib/sup/util/ncurses.rb', line 180

def rows
  lame, lamer = [], []
  stdscr.getmaxyx lame, lamer
  lame.first
end

.sync(&b) ⇒ Object



238
# File 'lib/sup/util/ncurses.rb', line 238

def sync &b; mutex.synchronize(&b); end

Instance Method Details

#xObject

xterm 24-shade grayscale



12
# File 'lib/sup/colormap.rb', line 12

Ncurses::NUM_COLORS.times { |x| color! x, x }