delete curses primitives to read whole lines
They make it seem like you can use them to create simple REPL apps, but you can't, because standard Teliva shortcuts won't work. I _could_ make them work by emulating them using getch(), but that feels like an unnecessary abstraction for now.
This commit is contained in:
parent
f8f1ec666a
commit
52372d1812
|
@ -193,6 +193,7 @@ Teliva also introduces some incompatibilities to protect computer owners:
|
||||||
start out as stdin/stdout.
|
start out as stdin/stdout.
|
||||||
- `io.input`, `io.read`
|
- `io.input`, `io.read`
|
||||||
- `io.output`, `io.write`, `io.flush`
|
- `io.output`, `io.write`, `io.flush`
|
||||||
|
- `curses.getstr()`, `curses.mvgetstr()`
|
||||||
* Some functions in lcurses have [additional smarts](https://github.com/lcurses/lcurses/blob/master/lib/curses.lua).
|
* Some functions in lcurses have [additional smarts](https://github.com/lcurses/lcurses/blob/master/lib/curses.lua).
|
||||||
Teliva is [consistent with the underlying ncurses](https://github.com/akkartik/teliva/blob/main/src/lcurses/curses.lua).
|
Teliva is [consistent with the underlying ncurses](https://github.com/akkartik/teliva/blob/main/src/lcurses/curses.lua).
|
||||||
|
|
||||||
|
|
|
@ -27,25 +27,6 @@
|
||||||
/***
|
/***
|
||||||
Full-screen Text Terminal Manipulation.
|
Full-screen Text Terminal Manipulation.
|
||||||
|
|
||||||
In the underlying curses C library, the following functions:
|
|
||||||
|
|
||||||
getstr() (and wgetstr(), mvgetstr(), and mvwgetstr())
|
|
||||||
inchstr() (and winchstr(), mvinchstr(), and mvwinchstr())
|
|
||||||
instr() (and winstr(), mvinstr(), and mvwinstr())
|
|
||||||
|
|
||||||
are subject to buffer overflow attack. This is because you pass in the
|
|
||||||
buffer to be filled in, which has to be of finite length. But in this
|
|
||||||
Lua module, a buffer is assigned automatically and the function returns
|
|
||||||
the string, so there is no security issue. You may still use the alternate
|
|
||||||
functions:
|
|
||||||
|
|
||||||
s = stdscr:getnstr()
|
|
||||||
s = stdscr:inchnstr()
|
|
||||||
s = stdscr:innstr()
|
|
||||||
|
|
||||||
which take an extra "size of buffer" argument, in order to impose a maximum
|
|
||||||
length on the string the user may type in.
|
|
||||||
|
|
||||||
Some of the C functions beginning with "no" do not exist in Lua. You should
|
Some of the C functions beginning with "no" do not exist in Lua. You should
|
||||||
use `curses.nl(false)` and `curses.nl(true)` instead of `nonl()` and `nl()`,
|
use `curses.nl(false)` and `curses.nl(true)` instead of `nonl()` and `nl()`,
|
||||||
and likewise `curses.echo(false)` and `curses.echo(true)` instead of
|
and likewise `curses.echo(false)` and `curses.echo(true)` instead of
|
||||||
|
@ -60,12 +41,11 @@
|
||||||
if c < 256 then c = string.char(c) end
|
if c < 256 then c = string.char(c) end
|
||||||
|
|
||||||
Some Lua functions take a different set of parameters than their C
|
Some Lua functions take a different set of parameters than their C
|
||||||
counterparts; for example, you should use `str = stdscr.getstr()` and
|
counterparts; for example, you should use `y, x = stdscr.getyx()` instead of
|
||||||
`y, x = stdscr.getyx()` instead of `getstr(str)` and `getyx(y, x)`, and
|
`getstr(str)` and `getyx(y, x)`, and likewise for `getbegyx` and `getmaxyx`
|
||||||
likewise for `getbegyx` and `getmaxyx` and `getparyx` and `pair_content`.
|
and `getparyx` and `pair_content`. The Perl Curses module now uses the
|
||||||
The Perl Curses module now uses the C-compatible parameters, so be aware of
|
C-compatible parameters, so be aware of this difference when translating code
|
||||||
this difference when translating code from Perl into Lua, as well as from C
|
from Perl into Lua, as well as from C into Lua.
|
||||||
into Lua.
|
|
||||||
|
|
||||||
Many curses functions have variants starting with the prefixes `w-`, `mv-`,
|
Many curses functions have variants starting with the prefixes `w-`, `mv-`,
|
||||||
and/or `wmv-`. These variants differ only in the explicit addition of a
|
and/or `wmv-`. These variants differ only in the explicit addition of a
|
||||||
|
|
|
@ -1360,56 +1360,6 @@ Wmvgetch(lua_State *L)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
Read characters up to the next newline from the window input.
|
|
||||||
@function getstr
|
|
||||||
@int[opt] n
|
|
||||||
@treturn string string read from input buffer
|
|
||||||
@see wgetnstr(3x)
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
Wgetstr(lua_State *L)
|
|
||||||
{
|
|
||||||
WINDOW *w = checkwin(L, 1);
|
|
||||||
int n = optint(L, 2, 0);
|
|
||||||
char buf[LUAL_BUFFERSIZE];
|
|
||||||
|
|
||||||
if (n == 0 || n >= LUAL_BUFFERSIZE)
|
|
||||||
n = LUAL_BUFFERSIZE - 1;
|
|
||||||
if (wgetnstr(w, buf, n) == ERR)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return pushstringresult(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
Call @{move} then @{getstr}.
|
|
||||||
@function mvgetstr
|
|
||||||
@int y
|
|
||||||
@int x
|
|
||||||
@int[opt=-1] n
|
|
||||||
@treturn string string read from input buffer
|
|
||||||
@see mvwgetnstr(3x)
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
Wmvgetstr(lua_State *L)
|
|
||||||
{
|
|
||||||
WINDOW *w = checkwin(L, 1);
|
|
||||||
int y = checkint(L, 2);
|
|
||||||
int x = checkint(L, 3);
|
|
||||||
int n = optint(L, 4, -1);
|
|
||||||
char buf[LUAL_BUFFERSIZE];
|
|
||||||
|
|
||||||
if (n == 0 || n >= LUAL_BUFFERSIZE)
|
|
||||||
n = LUAL_BUFFERSIZE - 1;
|
|
||||||
if (mvwgetnstr(w, y, x, buf, n) == ERR)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return pushstringresult(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Fetch the attributed character at the current cursor position.
|
Fetch the attributed character at the current cursor position.
|
||||||
@function winch
|
@function winch
|
||||||
|
@ -1860,7 +1810,7 @@ static const luaL_Reg curses_window_fns[] =
|
||||||
LCURSES_FUNC( Wgetch ),
|
LCURSES_FUNC( Wgetch ),
|
||||||
LCURSES_FUNC( Wgetmaxyx ),
|
LCURSES_FUNC( Wgetmaxyx ),
|
||||||
LCURSES_FUNC( Wgetparyx ),
|
LCURSES_FUNC( Wgetparyx ),
|
||||||
LCURSES_FUNC( Wgetstr ),
|
/* no 'getstr' because there's no way to hook standard Teliva hotkeys into it */
|
||||||
LCURSES_FUNC( Wgetyx ),
|
LCURSES_FUNC( Wgetyx ),
|
||||||
LCURSES_FUNC( Whline ),
|
LCURSES_FUNC( Whline ),
|
||||||
LCURSES_FUNC( Widcok ),
|
LCURSES_FUNC( Widcok ),
|
||||||
|
@ -1881,7 +1831,7 @@ static const luaL_Reg curses_window_fns[] =
|
||||||
LCURSES_FUNC( Wmvaddstr ),
|
LCURSES_FUNC( Wmvaddstr ),
|
||||||
LCURSES_FUNC( Wmvdelch ),
|
LCURSES_FUNC( Wmvdelch ),
|
||||||
LCURSES_FUNC( Wmvgetch ),
|
LCURSES_FUNC( Wmvgetch ),
|
||||||
LCURSES_FUNC( Wmvgetstr ),
|
/* no 'mvgetstr' because there's no way to hook standard Teliva hotkeys into it */
|
||||||
LCURSES_FUNC( Wmvhline ),
|
LCURSES_FUNC( Wmvhline ),
|
||||||
LCURSES_FUNC( Wmvvline ),
|
LCURSES_FUNC( Wmvvline ),
|
||||||
LCURSES_FUNC( Wmvwinch ),
|
LCURSES_FUNC( Wmvwinch ),
|
||||||
|
|
Loading…
Reference in New Issue