started the norminette
This commit is contained in:
parent
46e96a2120
commit
f4a5c0984e
7 changed files with 318 additions and 295 deletions
|
|
@ -11,16 +11,16 @@
|
|||
/* ************************************************************************** */
|
||||
|
||||
#ifndef _LINE_FUNCTIONS_H
|
||||
#define _LINE_FUNCTIONS_H
|
||||
# define _LINE_FUNCTIONS_H
|
||||
|
||||
#include "line/_line_structs.h"
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
# include "line/_line_structs.h"
|
||||
# include "me/fs/fs.h"
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_str.h"
|
||||
|
||||
|
||||
t_error line_edit_insert(t_line_state *state, char c);
|
||||
t_error line_edit_start(t_line_state *state, t_fd *stdin_fd, t_fd *stdout_fd, t_const_str prompt);
|
||||
t_error line_edit_insert(t_line_state *state, char c);
|
||||
t_error line_edit_start(t_line_state *state, t_fd *stdin_fd, t_fd *stdout_fd,
|
||||
t_const_str prompt);
|
||||
t_str line_edit_feed(t_line_state *state);
|
||||
void line_edit_backspace(t_line_state *state);
|
||||
void line_edit_delete(t_line_state *state);
|
||||
|
|
@ -31,16 +31,16 @@ void line_edit_move_left(t_line_state *state);
|
|||
void line_edit_move_right(t_line_state *state);
|
||||
void line_edit_stop(t_line_state *state);
|
||||
|
||||
t_str linenoise(t_const_str prompt);
|
||||
t_str line_blocking_edit(t_fd *stdin_fd, t_fd *stdout_fd, t_const_str prompt);
|
||||
t_str linenoise(t_const_str prompt);
|
||||
t_str line_blocking_edit(t_fd *stdin_fd, t_fd *stdout_fd, t_const_str prompt);
|
||||
|
||||
bool line_history_add(t_const_str line);
|
||||
t_error line_history_load(t_str name);
|
||||
t_error line_history_save(t_str name);
|
||||
t_error line_history_load(t_str name);
|
||||
t_error line_history_save(t_str name);
|
||||
|
||||
void line_clear_screen(t_fd *output);
|
||||
void line_refresh(t_line_state *state, t_line_flags flags);
|
||||
void line_hide(t_line_state *state);
|
||||
void line_show(t_line_state *state);
|
||||
void line_clear_screen(t_fd *output);
|
||||
void line_refresh(t_line_state *state, t_line_flags flags);
|
||||
void line_hide(t_line_state *state);
|
||||
void line_show(t_line_state *state);
|
||||
|
||||
#endif /* _LINE_FUNCTIONS_H */
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _line_interal.h :+: :+: :+: */
|
||||
/* _line_internal.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/10 15:37:40 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/10 15:38:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/10 15:48:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef _LINE_INTERAL_H
|
||||
#define _LINE_INTERAL_H
|
||||
#ifndef _LINE_INTERNAL_H
|
||||
# define _LINE_INTERNAL_H
|
||||
|
||||
#include "line/_line_functions.h"
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
# include "line/_line_functions.h"
|
||||
# include "me/fs/fs.h"
|
||||
# include "me/string/string.h"
|
||||
# include "me/types.h"
|
||||
# include "me/vec/vec_str.h"
|
||||
|
||||
t_const_str get_unfinished_str(void);
|
||||
t_raw_mode_state *get_raw_mode_state(void);
|
||||
t_vec_str *get_history(void);
|
||||
void free_history(void);
|
||||
t_const_str get_unfinished_str(void);
|
||||
t_raw_mode_state *get_raw_mode_state(void);
|
||||
t_vec_str *get_history(void);
|
||||
void free_history(void);
|
||||
|
||||
t_error gnl_wrapper(t_fd *fd, t_string *out);
|
||||
void line_uninit_lib(void);
|
||||
t_error line_get_cursor_position(t_fd *input, t_fd *output, t_u32 *column_out);
|
||||
t_u32 line_get_columns(t_fd *input, t_fd *output);
|
||||
t_usize line_get_prompt_len(t_const_str s);
|
||||
t_str line_no_tty_impl(void);
|
||||
void line_print_key_codes(void);
|
||||
t_error gnl_wrapper(t_fd *fd, t_string *out);
|
||||
void line_uninit_lib(void);
|
||||
t_error line_get_cursor_position(t_fd *input, t_fd *output,
|
||||
t_u32 *column_out);
|
||||
t_u32 line_get_columns(t_fd *input, t_fd *output);
|
||||
t_usize line_get_prompt_len(t_const_str s);
|
||||
t_str line_no_tty_impl(void);
|
||||
void line_print_key_codes(void);
|
||||
|
||||
t_error line_enable_raw_mode(t_fd *fd);
|
||||
void line_disable_raw_mode(t_fd *fd);
|
||||
t_error line_enable_raw_mode(t_fd *fd);
|
||||
void line_disable_raw_mode(t_fd *fd);
|
||||
|
||||
#endif /* _LINE_INTERAL_H */
|
||||
|
|
|
|||
|
|
@ -6,74 +6,82 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/10 15:24:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/07/10 15:32:35 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/07/10 15:53:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef _LINE_STRUCTS_H
|
||||
#define _LINE_STRUCTS_H
|
||||
# define _LINE_STRUCTS_H
|
||||
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/types.h"
|
||||
#include <termios.h>
|
||||
# include "me/fs/fs.h"
|
||||
# include "me/string/string.h"
|
||||
# include "me/types.h"
|
||||
# include <termios.h>
|
||||
|
||||
typedef struct s_line_state t_line_state;
|
||||
typedef struct s_raw_mode_state t_raw_mode_state;
|
||||
typedef enum e_line_flags t_line_flags;
|
||||
typedef enum e_key_action t_key_action;
|
||||
typedef enum e_history_direction t_history_direction;
|
||||
typedef struct s_line_state t_line_state;
|
||||
typedef struct s_raw_mode_state t_raw_mode_state;
|
||||
typedef enum e_line_flags t_line_flags;
|
||||
typedef enum e_key_action t_key_action;
|
||||
typedef enum e_history_direction t_history_direction;
|
||||
|
||||
struct s_line_state
|
||||
/// @param input_fd Terminal stdin file descriptor.
|
||||
/// @param output_fd Terminal stdout file descriptor.
|
||||
/// @param buf Edited line buffer.
|
||||
/// @param prompt_len Prompt to display.
|
||||
/// @param pos Prompt length.
|
||||
/// @param prompt_len Current cursor position.
|
||||
/// @param columns Number of columns in terminal.
|
||||
/// @param history_index The history index we are currently editing.
|
||||
struct s_line_state
|
||||
{
|
||||
t_fd *input_fd; /* Terminal stdin file descriptor. */
|
||||
t_fd *output_fd; /* Terminal stdout file descriptor. */
|
||||
t_string buf; /* Edited line buffer. */
|
||||
t_const_str prompt; /* Prompt to display. */
|
||||
t_usize prompt_len; /* Prompt length. */
|
||||
t_usize pos; /* Current cursor position. */
|
||||
t_usize columns; /* Number of columns in terminal. */
|
||||
t_i32 history_index; /* The history index we are currently editing. */
|
||||
t_fd *input_fd;
|
||||
t_fd *output_fd;
|
||||
t_string buf;
|
||||
t_const_str prompt;
|
||||
t_usize prompt_len;
|
||||
t_usize pos;
|
||||
t_usize columns;
|
||||
t_i32 history_index;
|
||||
};
|
||||
|
||||
struct s_raw_mode_state
|
||||
struct s_raw_mode_state
|
||||
{
|
||||
bool enabled;
|
||||
struct termios state;
|
||||
bool enabled;
|
||||
struct termios state;
|
||||
};
|
||||
|
||||
enum e_key_action
|
||||
enum e_key_action
|
||||
{
|
||||
K_KEY_NULL = 0, /* NULL */
|
||||
K_CTRL_A = 1, /* Ctrl+a */
|
||||
K_CTRL_B = 2, /* Ctrl-b */
|
||||
K_CTRL_C = 3, /* Ctrl-c */
|
||||
K_CTRL_D = 4, /* Ctrl-d */
|
||||
K_CTRL_E = 5, /* Ctrl-e */
|
||||
K_CTRL_F = 6, /* Ctrl-f */
|
||||
K_CTRL_H = 8, /* Ctrl-h */
|
||||
K_TAB = 9, /* Tab */
|
||||
K_NEWLINE = 10, /* Newline */
|
||||
K_CTRL_K = 11, /* Ctrl+k */
|
||||
K_CTRL_L = 12, /* Ctrl+l */
|
||||
K_ENTER = 13, /* Enter */
|
||||
K_CTRL_N = 14, /* Ctrl-n */
|
||||
K_CTRL_P = 16, /* Ctrl-p */
|
||||
K_CTRL_T = 20, /* Ctrl-t */
|
||||
K_CTRL_U = 21, /* Ctrl+u */
|
||||
K_CTRL_W = 23, /* Ctrl+w */
|
||||
K_ESC = 27, /* Escape */
|
||||
K_BACKSPACE = 127 /* Backspace */
|
||||
K_KEY_NULL = 0,
|
||||
K_CTRL_A = 1,
|
||||
K_CTRL_B = 2,
|
||||
K_CTRL_C = 3,
|
||||
K_CTRL_D = 4,
|
||||
K_CTRL_E = 5,
|
||||
K_CTRL_F = 6,
|
||||
K_CTRL_H = 8,
|
||||
K_TAB = 9,
|
||||
K_NEWLINE = 10,
|
||||
K_CTRL_K = 11,
|
||||
K_CTRL_L = 12,
|
||||
K_ENTER = 13,
|
||||
K_CTRL_N = 14,
|
||||
K_CTRL_P = 16,
|
||||
K_CTRL_T = 20,
|
||||
K_CTRL_U = 21,
|
||||
K_CTRL_W = 23,
|
||||
K_ESC = 27,
|
||||
K_BACKSPACE = 127
|
||||
};
|
||||
|
||||
enum e_line_flags
|
||||
enum e_line_flags
|
||||
{
|
||||
REFRESH_CLEAN = 1 << 0, // Clean the old prompt from the screen
|
||||
REFRESH_WRITE = 1 << 1, // Rewrite the prompt on the screen.
|
||||
REFRESH_ALL = REFRESH_CLEAN | REFRESH_WRITE, // Do both.
|
||||
REFRESH_CLEAN = 1 << 0,
|
||||
REFRESH_WRITE = 1 << 1,
|
||||
REFRESH_ALL = REFRESH_CLEAN | REFRESH_WRITE,
|
||||
};
|
||||
|
||||
enum e_history_direction
|
||||
enum e_history_direction
|
||||
{
|
||||
HIST_PREV,
|
||||
HIST_NEXT,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
/// https://github.com/antirez/linenoise
|
||||
|
||||
#ifndef LINE_H
|
||||
#define LINE_H
|
||||
# define LINE_H
|
||||
|
||||
#include "line/_line_functions.h"
|
||||
#include "line/_line_structs.h"
|
||||
# include "line/_line_functions.h"
|
||||
# include "line/_line_structs.h"
|
||||
|
||||
#endif /* LINE_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue