Module: FFI::NCurses::EmulatedFunctions

Included in:
FFI::NCurses, FFI::NCurses
Defined in:
lib/ffi-ncurses.rb

Overview

These following functions are implemented as macros in ncurses.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fixup(function, &block) ⇒ Object



281
282
283
284
285
# File 'lib/ffi-ncurses.rb', line 281

def self.fixup(function, &block)
  if NCurses.unattached_functions.include?(function)
    block.call
  end
end

Instance Method Details

#getbegyx(win, y = nil, x = nil) ⇒ Object



231
232
233
234
235
236
237
238
# File 'lib/ffi-ncurses.rb', line 231

def getbegyx(win, y = nil, x = nil)
  res = [NCurses.getbegy(win), NCurses.getbegx(win)]
  if y && y.kind_of?(Array) && x.kind_of?(Array)
    y.replace([res[0]])
    x.replace([res[1]])
  end
  res
end

#getmaxyx(win, y = nil, x = nil) ⇒ Object



249
250
251
252
253
254
255
256
# File 'lib/ffi-ncurses.rb', line 249

def getmaxyx(win, y = nil, x = nil)
  res = [NCurses.getmaxy(win), NCurses.getmaxx(win)]
  if y && y.kind_of?(Array) && x.kind_of?(Array)
    y.replace([res[0]])
    x.replace([res[1]])
  end
  res
end

#getparyx(win, y = nil, x = nil) ⇒ Object



240
241
242
243
244
245
246
247
# File 'lib/ffi-ncurses.rb', line 240

def getparyx(win, y = nil, x = nil)
  res = [NCurses.getpary(win), NCurses.getparx(win)]
  if y && y.kind_of?(Array) && x.kind_of?(Array)
    y.replace([res[0]])
    x.replace([res[1]])
  end
  res
end

#getsyx(y = nil, x = nil) ⇒ Object

These have been transliterated from ‘ncurses.h`.



259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/ffi-ncurses.rb', line 259

def getsyx(y = nil, x = nil)
  if is_leaveok(newscr)
    res = [-1, -1]
  else
    res = getyx(newscr)
  end
  if y && y.kind_of?(Array) && x.kind_of?(Array)
    y.replace([res[0]])
    x.replace([res[1]])
  end
  res
end

#getyx(win, y = nil, x = nil) ⇒ Object

Note that I’m departing from the NCurses API here - it makes no sense to force people to use pointer return values when these methods have been implemented as macros to make them easy to use in C. We have multiple return values in Ruby, so let’s use them. Call like this:

y, x = getyx(win)

For compatibility with the existing Ncurses lib, you can also call these functions like so:

y = [nil]
x = [nil]
getyx(win, y, x)


222
223
224
225
226
227
228
229
# File 'lib/ffi-ncurses.rb', line 222

def getyx(win, y = nil, x = nil)
  res = [NCurses.getcury(win), NCurses.getcurx(win)]
  if y && y.kind_of?(Array) && x.kind_of?(Array)
    y.replace([res[0]])
    x.replace([res[1]])
  end
  res
end

#setsyx(y, x) ⇒ Object



272
273
274
275
276
277
278
279
# File 'lib/ffi-ncurses.rb', line 272

def setsyx(y, x)
  if y == -1 && x == -1
    leaveok(newscr, true)
  else
    leaveok(newscr, false)
	  wmove(newscr, y, x)
  end
end