aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 14:47:46 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 14:47:46 +0000
commitcd55aa462b112896240ab736bf60035fdb30ca2d (patch)
tree4446cee1af4ba561e46b1587f96bb61aecedceb2 /src/main.cc
parentc8479ceff6aea37def538c902324c68930947f21 (diff)
adapt line editor
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc48
1 files changed, 17 insertions, 31 deletions
diff --git a/src/main.cc b/src/main.cc
index 07a3f1a..55f669a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -13,6 +13,7 @@
#include "all.h"
#include "test.h"
+#include "line/line_editor.h"
using namespace std;
using namespace ov4;
@@ -38,22 +39,6 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
exe_option(argv);
- // while ((c = getopt(argc, argv, "hvp")) != EOF) {
- // switch (c) {
- // case 'h': /* print help message */
- // usage();
- // break;
- // case 'v': /* emit additional diagnostic info */
- // verbose = true;
- // break;
- // case 'p': /* don't print a prompt */
- // emit_prompt = 0; /* handy for automatic testing */
- // break;
- // default:
- // usage();
- // }
- // }
-
/* Initialize the job list */
@@ -62,24 +47,25 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
/* Execute the shell's read/eval loop */
while (1) {
- /* Read command line */
- print_prompt();
+ /* Read command line */
+ print_prompt();
- if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin))
- app_error("fgets error");
- if (feof(stdin)) { /* End of file (ctrl-d) */
- fflush(stdout);
- exit(0);
- }
+ T_line_editor line_editor_instance;
+ enable_raw();
+ T_position pos = line_editor_instance.get_cursor_position();
+ line_editor_instance.cursor_row = pos.row;
+ line_editor_instance.cursor_col = pos.col;
+ line_editor_instance.prompt_pos = line_editor_instance.cursor_col;
+ string s = line_editor_instance.readline();
+ disable_raw();
+ cout << "\n\n\n\n" << endl;
+ cout << s << endl;
+ if (s == "quit")
+ break;
+ eval(s.c_str());
- /* Evaluate the command line */
- // trim \n
- if(cmdline[strlen(cmdline)-1] == '\n')
- cmdline[strlen(cmdline)-1] = '\0';
- eval(cmdline);
- fflush(stdout);
- fflush(stdout);
+ fflush(stdout);
}
exit(0); /* control never reaches here */