about summary refs log tree commit diff stats
path: root/src/lcurses/curses.lua
blob: bba9d12555e54261fa537ae740649a06e66aeeb5 (plain) (blame)
1
2
3
4
5
6
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
--- Lua bindings for curses
local M = curses

-- These Lua functions detect number of args, like Unified Funcs in Perl Curses
-- see http://pjb.com.au/comp/lua/lcurses.html
-- see http://search.cpan.org/perldoc?Curses

function M.addch (...)
  if #{...} == 3 then
    return curses.stdscr():mvaddch(...)
  else
    return curses.stdscr():addch(...)
  end
end

function M.addstr(...) -- detect number of args, like Unified Funcs in Perl Curses
  if #{...} == 3 then
    return curses.stdscr():mvaddstr(...)
  else
    return curses.stdscr():addstr(...)
  end
end

function M.attrset (a) return curses.stdscr():attrset(a) end
function M.clear ()    return curses.stdscr():clear() end
function M.clrtobot () return curses.stdscr():clrtobot() end
function M.clrtoeol () return curses.stdscr():clrtoeol() end

function M.getch (...)
  local c
  if #{...} == 2 then
    c = curses.stdscr():mvgetch(...)
  else
    c = curses.stdscr():getch()
  end
  if c < 256 then
    return string.char(c)
  end
  -- could kludge-test for utf8, e.g. c3 a9 20  c3 aa 20  c3 ab 20  e2 82 ac 0a
  return c
end

function M.getstr (...)
  if #{...} > 1 then
    return curses.stdscr():mvgetstr(...)
  else
    return curses.stdscr():getstr(...)
  end
end
M.getnstr = M.getstr

function M.getyx ()    return curses.stdscr():getyx() end
function M.keypad (b)  return curses.stdscr():keypad(b) end
function M.move (y,x)  return curses.stdscr():move(y,x) end
function M.refresh ()  return curses.stdscr():refresh() end
function M.timeout (t) return curses.stdscr():timeout(t) end

return M