normed most of the line lib
This commit is contained in:
parent
2cfce88274
commit
79e039c94a
12 changed files with 751 additions and 597 deletions
71
line/src/line_edit_actions.c
Normal file
71
line/src/line_edit_actions.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* line_edit_actions.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/11 18:24:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/11 18:24:20 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "line/_line_functions.h"
|
||||
#include "line/_line_structs.h"
|
||||
|
||||
/* Insert the character 'c' at cursor current position.
|
||||
*
|
||||
* On error writing to the terminal -1 is returned, otherwise 0. */
|
||||
t_error line_edit_insert(t_line_state *state, char c)
|
||||
{
|
||||
if (state->pos == state->buf.len)
|
||||
{
|
||||
if (string_push_char(&state->buf, c))
|
||||
return (ERROR);
|
||||
}
|
||||
else if (string_insert_char(&state->buf, state->pos, c))
|
||||
return (ERROR);
|
||||
state->pos++;
|
||||
line_refresh_line(state);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
/* Move cursor on the left. */
|
||||
void line_edit_move_left(t_line_state *state)
|
||||
{
|
||||
if (state->pos > 0)
|
||||
{
|
||||
state->pos--;
|
||||
line_refresh_line(state);
|
||||
}
|
||||
}
|
||||
|
||||
/* Move cursor on the right. */
|
||||
void line_edit_move_right(t_line_state *state)
|
||||
{
|
||||
if (state->pos != state->buf.len)
|
||||
{
|
||||
state->pos++;
|
||||
line_refresh_line(state);
|
||||
}
|
||||
}
|
||||
|
||||
/* Move cursor to the start of the line. */
|
||||
void line_edit_move_home(t_line_state *state)
|
||||
{
|
||||
if (state->pos != 0)
|
||||
{
|
||||
state->pos = 0;
|
||||
line_refresh_line(state);
|
||||
}
|
||||
}
|
||||
|
||||
/* Move cursor to the end of the line. */
|
||||
void line_edit_move_end(t_line_state *state)
|
||||
{
|
||||
if (state->pos != state->buf.len)
|
||||
{
|
||||
state->pos = state->buf.len;
|
||||
line_refresh_line(state);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue