about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/lua.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/lua.c b/src/lua.c
index 59be9de..7ab07d1 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -5,6 +5,7 @@
 */
 
 
+#include <ncurses.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,7 +41,7 @@ static void laction (int i) {
 
 
 static void print_usage (void) {
-  fprintf(stderr,
+  printw(
   "usage: %s [options] [script [args]].\n"
   "Available options are:\n"
   "  -e stat  execute string " LUA_QL("stat") "\n"
@@ -51,14 +52,14 @@ static void print_usage (void) {
   "  -        execute stdin and stop handling options\n"
   ,
   progname);
-  fflush(stderr);
+  refresh();
 }
 
 
 static void l_message (const char *pname, const char *msg) {
-  if (pname) fprintf(stderr, "%s: ", pname);
-  fprintf(stderr, "%s\n", msg);
-  fflush(stderr);
+  if (pname) printw("%s: ", pname);
+  printw("%s\n", msg);
+  refresh();
 }
 
 
@@ -179,10 +180,9 @@ static int pushline (lua_State *L, int firstline) {
   char *b = buffer;
   size_t l;
   const char *prmt = get_prompt(L, firstline);
-  fputs(prmt, stdout);
-  fflush(stdout);
-  if (fgets(buffer, LUA_MAXINPUT, stdin) == NULL)
-    return 0;  /* no input */
+  addstr(prmt);
+  refresh();
+  getnstr(b, LUA_MAXINPUT);
   l = strlen(b);
   if (l > 0 && b[l-1] == '\n')  /* line ends with newline? */
     b[l-1] = '\0';  /* remove it */
@@ -231,7 +231,7 @@ static void dotty (lua_State *L) {
   }
   lua_settop(L, 0);  /* clear stack */
   fputs("\n", stdout);
-  fflush(stdout);
+  refresh();
   progname = oldprogname;
 }
 
@@ -352,6 +352,7 @@ static int pmain (lua_State *L) {
   script = collectargs(argv, &has_i, &has_v, &has_e);
   if (script < 0) {  /* invalid args? */
     print_usage();
+    getch();
     s->status = 1;
     return 0;
   }
@@ -382,11 +383,15 @@ int main (int argc, char **argv) {
     l_message(argv[0], "cannot create state: not enough memory");
     return EXIT_FAILURE;
   }
+  initscr();
+  echo();
   s.argc = argc;
   s.argv = argv;
   status = lua_cpcall(L, &pmain, &s);
   report(L, status);
   lua_close(L);
+  getch();
+  endwin();
   return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
n class='oid'>ab02bb66 ^
02684e8d ^









8950915a ^

c442a5ad ^
02684e8d ^
47a15082 ^
02684e8d ^

47a15082 ^
02684e8d ^


3ae1fd00 ^
02684e8d ^




3ae1fd00 ^

02684e8d ^





f7f0d631 ^
e92fa89e ^


f7f0d631 ^









120a7408 ^
f7f0d631 ^
120a7408 ^
f7f0d631 ^










1f0f3813 ^
f7f0d631 ^
02684e8d ^
8ba17d83 ^



a2593892 ^

8ba17d83 ^
a2593892 ^
8ba17d83 ^





02684e8d ^







































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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149