summaryrefslogtreecommitdiffstats
path: root/src/c_input.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/c_input.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/c_input.c b/src/c_input.c
new file mode 100644
index 0000000..8fb4b72
--- /dev/null
+++ b/src/c_input.c
@@ -0,0 +1,92 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* c_input.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <libft.h>
+#include <signal.h>
+#include <term.h>
+
+#include "c_init.h"
+#include "c_keys.h"
+#include "c_input.h"
+#include "c_utils.h"
+#include "m_prompt.h"
+#include "m_loop.h"
+
+int16_t
+ c_init_line(uint8_t psx, t_caps *tcaps)
+{
+ char *term;
+
+ if (tcaps)
+ {
+ term = getenv("TERM");
+ if (!tgetent(NULL, term))
+ return (-1);
+ c_set_term_raw(1);
+ signal(SIGINT, SIG_IGN);
+ tcaps->cpos = 0;
+ tcaps->lpos = 0;
+ tcaps->nlines = 1;
+ tcaps->psx = psx - 1;
+ return (1);
+ }
+ else
+ return (-1);
+}
+
+uint16_t
+ c_get_win_size(struct winsize *ws)
+{
+ if (!(ioctl(STDOUT_FILENO, TIOCGWINSZ, ws)))
+ return (-1);
+ if (!ws->ws_col)
+ ws->ws_col = 80;
+ if (!ws->ws_row)
+ ws->ws_row = 80;
+ return (1);
+}
+
+uint32_t
+ c_get_line_num(char *line, uint32_t cpos, uint32_t plen, t_caps *tcaps)
+{
+ uint32_t it;
+ uint32_t line_num;
+ uint32_t len;
+
+ it = 0;
+ line_num = 0;
+ tcaps->lpos = 1;
+ len = ft_strlen(line);
+ if ((len) < (tcaps->ws.ws_col - plen))
+ return (1);
+ while (it < len)
+ {
+ it += (it == 0) ? (tcaps->ws.ws_col - plen) : tcaps->ws.ws_col;
+ tcaps->lpos += (it < cpos) ? 1 : 0;
+ line_num++;
+ }
+ return (line_num);
+}
+
+int16_t
+ c_back_slash(char **line, uint32_t plen, t_caps *tcaps)
+{
+ if (tcaps->cpos >= 1)
+ {
+ *line = c_delchar(*line, tcaps->cpos);
+ c_key_left(plen, tcaps);
+ tputs(tgetstr("cd", NULL), 1, ft_putchar);
+ }
+ return (1);
+}