Working stuff for line
This commit is contained in:
parent
7a34a78f16
commit
13ba83d6af
1 changed files with 10 additions and 20 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/07 16:53:27 by maiboyer #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ t_error linenoise_get_cursor_position(t_fd *input, t_fd *output, t_u32 *column_o
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
||||||
/* Report cursor location */
|
/* Report cursor location */
|
||||||
if (write_fd(output, (t_u8*)"\x1b[6n", 4, NULL))
|
if (write_fd(output, (t_u8 *)"\x1b[6n", 4, NULL))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
||||||
/* Read the response: ESC [ rows ; cols R */
|
/* Read the response: ESC [ rows ; cols R */
|
||||||
|
|
@ -280,7 +280,7 @@ t_usize linenoise_get_prompt_len(t_const_str s)
|
||||||
i++;
|
i++;
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
//printf("ret = %zu\n", ret);
|
// printf("ret = %zu\n", ret);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,28 +298,18 @@ void linenoise_refresh_single_line(t_line_state *l, t_line_flags flags)
|
||||||
size_t cursor_pos = l->pos;
|
size_t cursor_pos = l->pos;
|
||||||
t_string str;
|
t_string str;
|
||||||
|
|
||||||
|
|
||||||
str = string_new(16);
|
str = string_new(16);
|
||||||
string_push_char(&str, '\r');
|
string_push(&str, "\r\x1b[2K");
|
||||||
|
|
||||||
if (flags & REFRESH_WRITE)
|
if (flags & REFRESH_WRITE)
|
||||||
{
|
{
|
||||||
/* Write the prompt and the current buffer content */
|
/* Write the prompt and the current buffer content */
|
||||||
string_push(&str, l->prompt);
|
string_push(&str, l->prompt);
|
||||||
string_push(&str, input_buf); // , len);
|
string_push(&str, input_buf); // , len);
|
||||||
|
me_printf_str(&str, "\x1b[0G\x1b[%uC", cursor_pos + prompt_len);
|
||||||
}
|
}
|
||||||
string_push(&str, "\x1b[0K");
|
me_printf_fd(l->output_fd, "%s", str.buf);
|
||||||
/* 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_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);
|
string_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,7 +348,7 @@ t_error linenoise_edit_insert(t_line_state *l, char c)
|
||||||
if (l->len == l->pos)
|
if (l->len == l->pos)
|
||||||
{
|
{
|
||||||
l->buf[l->pos] = c;
|
l->buf[l->pos] = c;
|
||||||
//l->pos++;
|
l->pos++;
|
||||||
l->len++;
|
l->len++;
|
||||||
l->buf[l->len] = '\0';
|
l->buf[l->len] = '\0';
|
||||||
linenoise_refresh_line(l);
|
linenoise_refresh_line(l);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue