The structure makes manipulation of windows easier.
t_arg argv[MAX_ARGS];
} t_input;
+typedef struct s_windows
+{
+ WINDOW *command_win;
+ WINDOW *schematics_win;
+ WINDOW *border_win;
+} t_windows;
void add_node(t_vec *nodes, t_state set_state);
void add_mosfet(t_vec *mosfets, t_type type);
int should_open(t_type type, t_state state);
int sim_step(t_vec *nodes, t_vec *mosfets);
-void setup_terminal(WINDOW **command_win, WINDOW **schematics_win);
-void clean_terminal(WINDOW *command_win, WINDOW *schematics_win);
+void setup_terminal(t_windows *windows);
+void clean_terminal(t_windows *windows);
void print_start(WINDOW *command_win);
void command_not_found(WINDOW *command_win, const char *input);
void print_help(WINDOW *command_win, t_command c);
return (res);
}
-void cleanup(t_vec *nodes, t_vec *mosfets, WINDOW *command_win, WINDOW *schematics_win)
+void cleanup(t_vec *nodes, t_vec *mosfets, t_windows *windows)
{
update_nodes(NULL);
ft_vec_free(nodes, free_node);
ft_vec_free(mosfets, NULL);
- clean_terminal(command_win, schematics_win);
+ clean_terminal(windows);
return ;
}
int main(void)
{
- t_vec nodes;
- t_vec mosfets;
- WINDOW *command_win;
- WINDOW *schematics_win;
+ t_vec nodes;
+ t_vec mosfets;
+ t_windows windows;
ft_vec_init(&nodes, sizeof(t_node));
ft_vec_init(&mosfets, sizeof(t_mosfet));
- setup_terminal(&command_win, &schematics_win);
- print_start(command_win);
+ setup_terminal(&windows);
+ print_start(windows.command_win);
//if (argc > 1)
// build_graph(argv[1], &nodes, &mosfets);
- while (process_input(command_win, &nodes, &mosfets));
- cleanup(&nodes, &mosfets, command_win, schematics_win);
+ while (process_input(windows.command_win, &nodes, &mosfets));
+ cleanup(&nodes, &mosfets, &windows);
return (0);
}
#define INPUT_BUFFER_SIZE 100
#define COMMAND_WIN_COLS 60
-void setup_terminal(WINDOW **command_win, WINDOW **schematics_win)
+void setup_terminal(t_windows *windows)
{
initscr();
init_colors();
- *schematics_win = newwin(0, COLS - COMMAND_WIN_COLS, 0, 0);
- *command_win = newwin(0, COMMAND_WIN_COLS, 0, COLS - COMMAND_WIN_COLS);
- keypad(*command_win, TRUE);
+ windows->command_win = newwin(0, COMMAND_WIN_COLS, 0, COLS - COMMAND_WIN_COLS);
+ windows->schematics_win = newwin(0, COLS - COMMAND_WIN_COLS - 2, 0, 0);
+ windows->border_win = newwin(0, 1, 0, COLS - COMMAND_WIN_COLS - 1);
+ keypad(windows->command_win, TRUE);
nonl();
cbreak();
echo();
- scrollok(*command_win, TRUE);
+ scrollok(windows->command_win, TRUE);
+ wborder(windows->border_win, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE, ACS_VLINE);
+ wrefresh(windows->border_win);
return ;
}
}
-void clean_terminal(WINDOW *command_win, WINDOW *schematics_win)
+void clean_terminal(t_windows *windows)
{
- delwin(schematics_win);
- delwin(command_win);
+ delwin(windows->command_win);
+ delwin(windows->schematics_win);
+ delwin(windows->border_win);
endwin();
return ;
}