Add non-canonical mode to the sim
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sun, 3 Mar 2024 10:57:51 +0000 (11:57 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Sun, 15 Dec 2024 08:02:00 +0000 (09:02 +0100)
I want vim-esque modes to switch between schematics and commands.
This is the first step, but it makes FET_sim unsuable as it is now,
because input is not echoed back - one does not see what one enters.
Function get_next_line is not really suitable for non-canonical mode,
so an alternative (capable of parsing single char input, arrow keys
etc.) needs to be implemented.

TODO
src/terminal.c

diff --git a/TODO b/TODO
index f80ad086ea337c54a410240fa4ffe2c39d3594cb..91dfe5cc496d7b409859b15f69eaa523dc8c35c4 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,14 @@
 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
+       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
+               each is controllable from a "mode" (at least 2 modes necessary, more may be usefull later on)
+make it possible to save schematics and use them again
+       use blocks to "condense" the schematics - similar to integrated parts
+               make blocks' schematics openable in another split screen (vim like split command?)
+                       a block opened in another screen should show current simulation state as a part of the whole simulation (or maybe a switch between free mode and bound mode?)
 make build_graph not output
 rewrite command parsing (what I've created is just ugly)
 come up with better file structure
@@ -11,6 +21,10 @@ optimize
 pass 42 norminette
 
 DONE
+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
+               use alternate screen
+               implement non-canonical mode
 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
index d1252a6c23feedbbcf17224dcead59ce47471201..1b977098fb58358f9033aa956239f01b02b3a505 100644 (file)
@@ -1,18 +1,38 @@
 #include "FET_sim.h"
 #include "libft.h"
+#include <termios.h>
+#include <unistd.h>            // for STDIN_FILENO
+#include <stdlib.h>
 
 static const char      alt_term_on[] = "\033[?1049h";
 static const char      alt_term_off[] = "\033[?1049l";
 
+static struct termios  init_termios_set;
+
+static void    termios_settings(void)
+{
+       struct termios                  termios_set;
+
+       tcgetattr(STDIN_FILENO, &termios_set);
+       tcgetattr(STDIN_FILENO, &init_termios_set);
+       termios_set.c_lflag &= !ICANON;
+       termios_set.c_cc[VMIN] = 1;
+       termios_set.c_cc[VTIME] = 0;
+       tcsetattr(STDIN_FILENO, TCSANOW, &termios_set);
+       return ;
+}
+
 void   setup_terminal(void)
 {
        ft_printf("%s", alt_term_on);
        ft_printf("\033[H");
+       termios_settings();
        return ;
 }
 
 void   clean_terminal(void)
 {
        ft_printf("%s", alt_term_off);
+       tcsetattr(STDIN_FILENO, TCSANOW, &init_termios_set);
        return ;
 }