summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_init.c5
-rw-r--r--src/c_init.h4
-rw-r--r--src/c_input.c27
-rw-r--r--src/c_input.h1
4 files changed, 34 insertions, 3 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 9dde271..f4b130d 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -85,7 +85,7 @@ static int16_t
}
int16_t
- c_process_key(t_msh *msh, char *buf)
+ c_process_key(char *buf, t_msh *msh, t_caps *tcaps)
{
int i;
static char *line = NULL;
@@ -129,6 +129,7 @@ int16_t
}
else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
{
+ c_delchar(line, tcaps);
tputs(tgetstr("le", NULL), 1, ft_putchar);
tputs(tgetstr("dc", NULL), 1, ft_putchar);
return (1);
@@ -159,7 +160,7 @@ int16_t c_init_tcaps(t_msh *msh)
if (!(read(STDIN_FILENO, nread, 4)))
return (0);
tputs(tgetstr("vi", NULL), 1, ft_putchar);
- ret = c_process_key(msh, nread);
+ ret = c_process_key(nread, msh, &tcaps);
tputs(tgetstr("ve", NULL), 1, ft_putchar);
}
return (1);
diff --git a/src/c_init.h b/src/c_init.h
index 7924478..281bf72 100644
--- a/src/c_init.h
+++ b/src/c_init.h
@@ -14,11 +14,14 @@
#define U_INIT_H
#include <termios.h>
+#include <sys/ioctl.h>
#include "s_struct.h"
typedef struct s_caps {
struct termios tios;
+ struct winsize ws;
+ uint8_t cpos; /*cursor position (column)*/
char *cm_str; /*cursor mobility*/
char *nl; /*newline, returned by tgoto()*/
char *ks; /*indicate that keys transmit from now on*/
@@ -32,7 +35,6 @@ typedef struct s_caps {
char *DO; /*down one line*/
char *nd; /*right one char*/
char *cl; /*line clear*/
-
} t_caps;
int16_t c_init_tcaps(t_msh *msh);
diff --git a/src/c_input.c b/src/c_input.c
index bd963ad..5c9413b 100644
--- a/src/c_input.c
+++ b/src/c_input.c
@@ -11,13 +11,40 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stdio.h>
#include <term.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
#include "c_init.h"
#include "m_prompt.h"
#include "m_loop.h"
#include "s_struct.h"
+uint16_t
+ c_get_win_size(struct winsize *ws)
+{
+
+ ioctl(STDOUT_FILENO, TIOCGWINSZ, ws);
+ if (!ws->ws_col)
+ ws->ws_col = 80;
+ if (!ws->ws_row)
+ ws->ws_row = 80;
+ return (ws->ws_col);
+}
+
+
+char *c_delchar(char *str, t_caps *tcaps)
+{
+ uint16_t col;
+
+ col = c_get_win_size(&tcaps->ws);
+ ft_printf("%hu\n", col);
+ col =
+ return (str);
+}
+
+/* TODO: pos += 1 lettre / -1 si kl / +1 kr del*/
int16_t
c_redraw_line(char *line, t_msh *msh)
diff --git a/src/c_input.h b/src/c_input.h
index 11bf671..2d8d3ba 100644
--- a/src/c_input.h
+++ b/src/c_input.h
@@ -16,5 +16,6 @@
#include "s_struct.h"
int16_t c_redraw_line(char *line, t_msh *msh);
+char *c_delchar(char *str, t_caps *tcaps);
#endif