aboutsummaryrefslogtreecommitdiffstats
path: root/noice.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2015-11-20 11:38:19 +0000
committersin <sin@2f30.org>2015-11-20 11:39:07 +0000
commitf77b6a3fa6830c4e52e5ab7c4c07eb310743c75f (patch)
tree7fda28a04adbf242e3b19ddc8ad3379d2ae65cfb /noice.c
parentd6e89ef07f46895077807c0db78ffd27334de392 (diff)
downloadnoice-f77b6a3fa6830c4e52e5ab7c4c07eb310743c75f.tar.gz
Simplify readln()
Use getnstr() and be done with it. It will even beep now!
Diffstat (limited to 'noice.c')
-rw-r--r--noice.c46
1 files changed, 4 insertions, 42 deletions
diff --git a/noice.c b/noice.c
index 7192f48..17a0cea 100644
--- a/noice.c
+++ b/noice.c
@@ -327,52 +327,14 @@ nextsel(char **run)
char *
readln(void)
{
- int c;
- int i = 0;
- char *ln = NULL;
- int y, x, x0;
+ char ln[LINE_MAX];
echo();
curs_set(TRUE);
-
- /* Starting point */
- getyx(stdscr, y, x);
- x0 = x;
-
- while ((c = getch()) != ERR) {
- if (c == KEY_ENTER || c == '\r')
- break;
- if (c == KEY_BACKSPACE || c == CONTROL('H')) {
- getyx(stdscr, y, x);
- if (x >= x0) {
- i--;
- if (i > 0) {
- ln = xrealloc(ln, i * sizeof(*ln));
- } else {
- free(ln);
- ln = NULL;
- }
- move(y, x);
- printw("%c", ' ');
- move(y, x);
- } else {
- move(y, x0);
- }
- continue;
- }
- ln = xrealloc(ln, (i + 1) * sizeof(*ln));
- ln[i] = c;
- i++;
- }
- if (ln != NULL) {
- ln = xrealloc(ln, (i + 1) * sizeof(*ln));
- ln[i] = '\0';
- }
-
- curs_set(FALSE);
+ getnstr(ln, sizeof(ln));
noecho();
-
- return ln;
+ curs_set(FALSE);
+ return strdup(ln);
}
/*
Un proyecto texto-plano.xyz