Working stuff for line

This commit is contained in:
Maix0 2024-07-08 19:43:53 +02:00
parent 7a34a78f16
commit 13ba83d6af

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 16:53:27 by maiboyer #+# #+# */
/* Updated: 2024/07/07 19:22:53 by maiboyer ### ########.fr */
/* Updated: 2024/07/08 19:42:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -298,28 +298,18 @@ void linenoise_refresh_single_line(t_line_state *l, t_line_flags flags)
size_t cursor_pos = l->pos;
t_string str;
str = string_new(16);
string_push_char(&str, '\r');
string_push(&str, "\r\x1b[2K");
if (flags & REFRESH_WRITE)
{
/* Write the prompt and the current buffer content */
string_push(&str, l->prompt);
string_push(&str, input_buf); // , len);
me_printf_str(&str, "\x1b[0G\x1b[%uC", cursor_pos + prompt_len);
}
string_push(&str, "\x1b[0K");
/* Erase to right */
if (flags & REFRESH_WRITE)
{
/* Move cursor to original position. */
me_printf_str(&str, "\r\x1b[%iC", (int)(cursor_pos + prompt_len));
}
me_printf_fd(l->output_fd, "%s", str.buf);
//me_eprintf("refresh single line;\n");
write_fd(l->output_fd, (t_u8 *)str.buf, str.len, NULL);
//printf("cursor_pos = %zu\n", cursor_pos);
string_free(str);
}
@ -358,7 +348,7 @@ t_error linenoise_edit_insert(t_line_state *l, char c)
if (l->len == l->pos)
{
l->buf[l->pos] = c;
//l->pos++;
l->pos++;
l->len++;
l->buf[l->len] = '\0';
linenoise_refresh_line(l);