Group WINDOW* to a struct, add border
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sun, 15 Dec 2024 15:07:52 +0000 (16:07 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sun, 15 Dec 2024 15:07:52 +0000 (16:07 +0100)
The structure makes manipulation of windows easier.

inc/FET_sim.h
src/main.c
src/terminal.c

index e8efc85a2353296f10dc26bc1a83b469309b3fb6..f4cc3afaac979338bd0a18615da26eb839b3d0a8 100644 (file)
@@ -95,6 +95,12 @@ typedef struct s_input
        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);
@@ -114,8 +120,8 @@ void        update_nodes(t_vec *nodes);
 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);
index 146baeb13b1e4049b2d9b0a1a198b2a6877841f2..3e54974a1f5511ed504c906d3622f44c2afed6b8 100644 (file)
@@ -242,29 +242,28 @@ int       process_input(WINDOW *command_win, t_vec *nodes, t_vec *mosfets)
        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);
 }
index 4afea4dd95403e3c326fb666dc4fda60dfd2e788..14fe9c1edb7412c33a26cc3f5fb83ec70fc05f13 100644 (file)
@@ -6,17 +6,20 @@
 #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 ;
 }
 
@@ -62,10 +65,11 @@ int get_input(WINDOW *command_win, t_input *input)
 }
 
 
-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 ;
 }