summaryrefslogtreecommitdiffstats
path: root/src/c_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c_init.c')
-rw-r--r--src/c_init.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/c_init.c b/src/c_init.c
index 454e70a..35296e4 100644
--- a/src/c_init.c
+++ b/src/c_init.c
@@ -85,10 +85,10 @@ static int16_t
}
int16_t
- c_process_key(char *buf, t_msh *msh, t_caps *tcaps)
+ c_process_key(char *buf, t_caps *tcaps, t_msh *msh)
{
- int i;
static char *line = NULL;
+ int i;
i = -1;
if (line == NULL)
@@ -96,47 +96,54 @@ int16_t
return (0);
if (ft_isprint(buf[0]))
{
- if (*buf == 'q')
- {
- tputs(tgetstr("ve", NULL), 1, ft_putchar);
- c_set_term_raw(0);
- exit(0);
- }
line = ft_strjoin_m(line, buf);
c_redraw_line(line, tcaps->cpos, msh);
tcaps->cpos++;
}
else
{
+ /* if (!(c_catch_tcaps(buf, tcaps, msh)) */
+ /* return (-1); */
if (strncmp(buf, tgetstr("kr", NULL), ft_strlen(tgetstr("kr", NULL))) == 0)
{
- tputs(tgetstr("nd", NULL), 1, ft_putchar);
- tcaps->cpos++;
+ if (tcaps->cpos <= ft_strlen(line))
+ {
+ tputs(tgetstr("nd", NULL), 1, ft_putchar);
+ tcaps->cpos++;
+ }
return (1);
}
else if (buf[0] == '\n')
{
write(1, buf, ft_strlen(buf));
tputs(tgetstr("cr", NULL), 1, ft_putchar);
+ c_set_term_raw(0);
m_parse_and_run_line(line, msh);
line = NULL;
tcaps->cpos = 0;
tputs(tgetstr("cr", NULL), 1, ft_putchar);
+ c_set_term_raw(1);
m_prompt_psx(1, msh);
return (1);
}
else if (strncmp(buf, tgetstr("kl", NULL), ft_strlen(tgetstr("kl", NULL))) == 0)
{
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- tcaps->cpos--;
- return (1);
+ if (tcaps->cpos >= 1)
+ {
+ tputs(tgetstr("le", NULL), 1, ft_putchar);
+ tcaps->cpos--;
+ return (1);
+ }
}
else if (strncmp(buf, tgetstr("kb", NULL), ft_strlen(tgetstr("kb", NULL))) == 0)
{
- line = c_delchar(line, tcaps->cpos);
- tcaps->cpos -= 1;
- tputs(tgetstr("le", NULL), 1, ft_putchar);
- tputs(tgetstr("dc", NULL), 1, ft_putchar);
+ if (tcaps->cpos >= 1)
+ {
+ line = c_delchar(line, tcaps->cpos);
+ tcaps->cpos -= 1;
+ tputs(tgetstr("le", NULL), 1, ft_putchar);
+ tputs(tgetstr("dc", NULL), 1, ft_putchar);
+ }
return (1);
}
}
@@ -156,7 +163,6 @@ int16_t c_init_tcaps(t_msh *msh)
if (!tgetent(bp, term))
return (-1);
tcaps.cpos = 0;
- ft_printf("my term is %s", term);
c_set_term_raw(1);
c_get_struct(1, &tcaps);
if (!(c_get_win_size(&tcaps.ws)))
@@ -167,7 +173,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(nread, msh, &tcaps);
+ ret = c_process_key(nread, &tcaps, msh);
tputs(tgetstr("ve", NULL), 1, ft_putchar);
}
return (1);