TODO
implement vim-esque modes and gdb-like split screen/window for commands and schematics (TUI?)
implement new method of input - echoing commands, moving cursor and more
+ handle the behaviour better
+ sync a char *str_inp to what the user sees in terminal
implement "split screen" - one for commands, one for schematics (gdb like)
commands screen should work just similarly to normal terminal usage
schematics should use vim like controls
implement new method of input - echoing commands, moving cursor and more
use alternate screen
implement non-canonical mode
+ return input
rewrite t_fet and t_node to store indexes insted of pointers to connected parts
- goal shifted a bit, nodes store their ID and FETs have no use for havind ID so far
foundations of logic
return (1);
}
-int get_input(t_input *input, int fd)
+t_mode process_input_string(t_input *input, char *str_inp)
{
- int res;
- char *str_inp;
char **split_inp;
- str_inp = get_next_line(fd);
- if (!str_inp)
- {
- input->command = exitsim;
- input->argc = 0;
- return (1);
- }
if (str_inp[0] == '\n')
{
free(str_inp);
- return (1);
+ return (mode_command);
}
if (str_inp[0] && str_inp[ft_strlen(str_inp) - 1] == '\n')
str_inp[ft_strlen(str_inp) - 1] = '\0';
split_inp = ft_split(str_inp, " ");
- res = construct_input(input, split_inp);
- if (!res)
+ if (!construct_input(input, split_inp))
{
command_not_found(str_inp);
}
- free(str_inp);
free_split(split_inp);
+ return (mode_command);
+}
+
+int handle_escape_code(__attribute__((unused)) t_input *input, __attribute__((unused)) const char *code)
+{
+ return (1);
+}
+
+t_mode get_input(t_input *input, int fd)
+{
+ int res;
+ static char *str_inp;
+ char buff[10];
+ size_t len;
+
+ while(1)
+ {
+ len = read(fd, buff, 10);
+ buff[len] = '\0';
+ if (buff[0] == '\033' && len == 1)
+ return (mode_schema);
+ else if (buff[0] == '\033')
+ {
+ if (handle_escape_code(input, buff))
+ ft_printf("%s", buff);
+ }
+ else
+ ft_printf("%s", buff);
+ }
+ if (!str_inp)
+ return (mode_exit);
+ process_input_string(input, str_inp);
+ free(str_inp);
return (res);
}
-int process_input(t_vec *nodes, t_vec *mosfets, int fd)
+t_mode process_input(t_vec *nodes, t_vec *mosfets, int fd)
{
- int res;
+ t_mode res;
+ int success;
static t_input input = {.command = help, .argc = 0};
ft_printf("FET_sim> ");
- if (!get_input(&input, fd))
- return (1);
- res = 1;
+ res = get_input(&input, fd);
+ if (res != mode_command)
+ return (res);
+ success = 1;
if (input.command == next)
- res = c_next(input, nodes, mosfets);
+ success = c_next(input, nodes, mosfets);
else if (input.command == draw)
- res = c_draw(input, mosfets);
+ success = c_draw(input, mosfets);
else if (input.command == setnode)
- res = c_setnode(input, nodes);
+ success = c_setnode(input, nodes);
else if (input.command == addnode)
- res = c_addnode(input, nodes);
+ success = c_addnode(input, nodes);
else if (input.command == addfet)
- res = c_addfet(input, mosfets);
+ success = c_addfet(input, mosfets);
else if (input.command == bind)
- res = c_bind(input, nodes, mosfets);
+ success = c_bind(input, nodes, mosfets);
else if (input.command == help)
- res = c_help(input);
+ success = c_help(input);
else if (input.command == exitsim)
- res = 0;
- return (res);
+ res = mode_exit;
+ if (success)
+ return (res);
+ return (mode_error);
}
void cleanup(t_vec *nodes, t_vec *mosfets)
{
t_vec nodes;
t_vec mosfets;
+ t_mode mode;
setup_terminal();
print_start();
ft_vec_init(&mosfets, sizeof(t_mosfet));
if (argc > 1)
build_graph(argv[1], &nodes, &mosfets);
- while (process_input(&nodes, &mosfets, STDIN_FILENO));
+ mode = mode_command;
+ while (mode != mode_exit && mode != mode_error)
+ {
+ if (mode == mode_command)
+ mode = process_input(&nodes, &mosfets, STDIN_FILENO);
+// else if (mode == mode_schema)
+// mode = schema_mode(&nodes, &mosfets, STDIN_FILENO);
+ }
cleanup(&nodes, &mosfets);
return (0);
}