about summary refs log tree commit diff stats
path: root/src/lcurses
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-02-21 17:01:00 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-02-21 17:06:34 -0800
commit52372d1812bc0409fc3cf361e8ef9dbf51e72a2d (patch)
treeb8f0b937dde452afa6c44e845314014c37db6ada /src/lcurses
parentf8f1ec666afd0ec85fd6a7eff5f5b728412b4c98 (diff)
downloadteliva-52372d1812bc0409fc3cf361e8ef9dbf51e72a2d.tar.gz
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.
Diffstat (limited to 'src/lcurses')
-rw-r--r--src/lcurses/curses.c30
-rw-r--r--src/lcurses/window.c54
2 files changed, 7 insertions, 77 deletions
diff --git a/src/lcurses/curses.c b/src/lcurses/curses.c
index 64c7633..c52adc2 100644
--- a/src/lcurses/curses.c
+++ b/src/lcurses/curses.c
@@ -27,25 +27,6 @@
 /***
  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
  use `curses.nl(false)` and `curses.nl(true)` instead of `nonl()` and `nl()`,
  and likewise `curses.echo(false)` and `curses.echo(true)` instead of
@@ -60,12 +41,11 @@
      if c < 256 then c = string.char(c) end
 
  Some Lua functions take a different set of parameters than their C
- counterparts; for example, you should use `str = stdscr.getstr()` and
- `y, x = stdscr.getyx()` instead of `getstr(str)` and `getyx(y, x)`, and
- likewise for `getbegyx` and `getmaxyx` and `getparyx` and `pair_content`.
- The Perl Curses module now uses the C-compatible parameters, so be aware of
- this difference when translating code from Perl into Lua, as well as from C
- into Lua.
+ counterparts; for example, you should use `y, x = stdscr.getyx()` instead of
+ `getstr(str)` and `getyx(y, x)`, and likewise for `getbegyx` and `getmaxyx`
+ and `getparyx` and `pair_content`. The Perl Curses module now uses the
+ C-compatible parameters, so be aware of this difference when translating code
+ from Perl into Lua, as well as from C into Lua.
 
  Many curses functions have variants starting with the prefixes `w-`, `mv-`,
  and/or `wmv-`. These variants differ only in the explicit addition of a
diff --git a/src/lcurses/window.c b/src/lcurses/window.c
index 4ce8bb7..3de25aa 100644
--- a/src/lcurses/window.c
+++ b/src/lcurses/window.c
@@ -1361,56 +1361,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.
 @function winch
 @treturn int attributed character read from input buffer
@@ -1860,7 +1810,7 @@ static const luaL_Reg curses_window_fns[] =
 	LCURSES_FUNC( Wgetch		),
 	LCURSES_FUNC( Wgetmaxyx		),
 	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( Whline		),
 	LCURSES_FUNC( Widcok		),
@@ -1881,7 +1831,7 @@ static const luaL_Reg curses_window_fns[] =
 	LCURSES_FUNC( Wmvaddstr		),
 	LCURSES_FUNC( Wmvdelch		),
 	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( Wmvvline		),
 	LCURSES_FUNC( Wmvwinch		),