forked from test34/can_wizard
adding new functions and a new struct
This commit is contained in:
parent
57f4569fcd
commit
e3fe13d3ea
2 changed files with 50 additions and 26 deletions
|
@ -137,21 +137,6 @@ static int history_len = 0;
|
|||
static char **history = NULL;
|
||||
static bool allow_empty = true;
|
||||
|
||||
/* The linenoiseState structure represents the state during line editing.
|
||||
* We pass this state to functions implementing specific editing
|
||||
* functionalities. */
|
||||
struct linenoiseState {
|
||||
char *buf; /* Edited line buffer. */
|
||||
size_t buflen; /* Edited line buffer size. */
|
||||
const char *prompt; /* Prompt to display. */
|
||||
size_t plen; /* Prompt length. */
|
||||
size_t pos; /* Current cursor position. */
|
||||
size_t oldpos; /* Previous refresh cursor position. */
|
||||
size_t len; /* Current edited line length. */
|
||||
size_t cols; /* Number of columns in terminal. */
|
||||
size_t maxrows; /* Maximum num of rows used so far (multiline mode) */
|
||||
int history_index; /* The history index we are currently editing. */
|
||||
};
|
||||
|
||||
enum KEY_ACTION{
|
||||
KEY_NULL = 0, /* NULL */
|
||||
|
@ -188,7 +173,7 @@ FILE *lndebug_fp = NULL;
|
|||
fprintf(lndebug_fp, \
|
||||
"[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \
|
||||
(int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \
|
||||
(int)l->maxrows,old_rows); \
|
||||
(int)l->oldrows,old_rows); \
|
||||
} \
|
||||
fprintf(lndebug_fp, ", " __VA_ARGS__); \
|
||||
fflush(lndebug_fp); \
|
||||
|
@ -568,13 +553,13 @@ static void refreshMultiLine(struct linenoiseState *l) {
|
|||
int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
|
||||
int rpos2; /* rpos after refresh. */
|
||||
int col; /* colum position, zero-based. */
|
||||
int old_rows = l->maxrows;
|
||||
int old_rows = l->oldrows;
|
||||
int j;
|
||||
int fd = fileno(stdout);
|
||||
struct abuf ab;
|
||||
|
||||
/* Update maxrows if needed. */
|
||||
if (rows > (int)l->maxrows) l->maxrows = rows;
|
||||
/* Update oldrows if needed. */
|
||||
if (rows > (int)l->oldrows) l->oldrows = rows;
|
||||
|
||||
/* First step: clear all the lines used before. To do so start by
|
||||
* going to the last row. */
|
||||
|
@ -615,7 +600,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
|
|||
snprintf(seq,64,"\r");
|
||||
abAppend(&ab,seq,strlen(seq));
|
||||
rows++;
|
||||
if (rows > (int)l->maxrows) l->maxrows = rows;
|
||||
if (rows > (int)l->oldrows) l->oldrows = rows;
|
||||
}
|
||||
|
||||
/* Move cursor to right position. */
|
||||
|
@ -829,7 +814,7 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
|||
l.oldpos = l.pos = 0;
|
||||
l.len = 0;
|
||||
l.cols = getColumns();
|
||||
l.maxrows = 0;
|
||||
l.oldrows = 0;
|
||||
l.history_index = 0;
|
||||
|
||||
/* Buffer starts empty. */
|
||||
|
|
|
@ -46,11 +46,46 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern char *linenoiseEditMore;
|
||||
|
||||
/* The linenoiseState structure represents the state during line editing.
|
||||
* We pass this state to functions implementing specific editing
|
||||
* functionalities. */
|
||||
struct linenoiseState {
|
||||
int in_completion; /* The user pressed TAB and we are now in completion
|
||||
* mode, so input is handled by completeLine(). */
|
||||
size_t completion_idx; /* Index of next completion to propose. */
|
||||
int ifd; /* Terminal stdin file descriptor. */
|
||||
int ofd; /* Terminal stdout file descriptor. */
|
||||
char *buf; /* Edited line buffer. */
|
||||
size_t buflen; /* Edited line buffer size. */
|
||||
const char *prompt; /* Prompt to display. */
|
||||
size_t plen; /* Prompt length. */
|
||||
size_t pos; /* Current cursor position. */
|
||||
size_t oldpos; /* Previous refresh cursor position. */
|
||||
size_t len; /* Current edited line length. */
|
||||
size_t cols; /* Number of columns in terminal. */
|
||||
size_t oldrows; /* Rows used by last refrehsed line (multiline mode) */
|
||||
int history_index; /* The history index we are currently editing. */
|
||||
};
|
||||
|
||||
typedef struct linenoiseCompletions {
|
||||
size_t len;
|
||||
char **cvec;
|
||||
} linenoiseCompletions;
|
||||
|
||||
/* Non blocking API. */
|
||||
int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt);
|
||||
char *linenoiseEditFeed(struct linenoiseState *l);
|
||||
void linenoiseEditStop(struct linenoiseState *l);
|
||||
void linenoiseHide(struct linenoiseState *l);
|
||||
void linenoiseShow(struct linenoiseState *l);
|
||||
|
||||
/* Blocking API. */
|
||||
char *linenoise(const char *prompt);
|
||||
void linenoiseFree(void *ptr);
|
||||
|
||||
/* Completion API. */
|
||||
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||
typedef char*(linenoiseHintsCallback)(const char *, int *color, int *bold);
|
||||
typedef void(linenoiseFreeHintsCallback)(void *);
|
||||
|
@ -59,21 +94,25 @@ void linenoiseSetHintsCallback(linenoiseHintsCallback *);
|
|||
void linenoiseSetFreeHintsCallback(linenoiseFreeHintsCallback *);
|
||||
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||
|
||||
int linenoiseProbe(void);
|
||||
char *linenoise(const char *prompt);
|
||||
void linenoiseFree(void *ptr);
|
||||
/* History API. */
|
||||
int linenoiseHistoryAdd(const char *line);
|
||||
int linenoiseHistorySetMaxLen(int len);
|
||||
int linenoiseHistorySave(const char *filename);
|
||||
int linenoiseHistoryLoad(const char *filename);
|
||||
void linenoiseHistoryFree(void);
|
||||
|
||||
/* Other utilities. */
|
||||
void linenoiseClearScreen(void);
|
||||
void linenoiseSetMultiLine(int ml);
|
||||
void linenoiseSetDumbMode(int set);
|
||||
bool linenoiseIsDumbMode(void);
|
||||
void linenoisePrintKeyCodes(void);
|
||||
// Allow empty input from console (Enter key)
|
||||
void linenoiseAllowEmpty(bool);
|
||||
int linenoiseSetMaxLineLen(size_t len);
|
||||
// Testing console for escape codes support
|
||||
int linenoiseProbe(void);
|
||||
// Dump mode for consoles withoud escape codes support
|
||||
void linenoiseSetDumbMode(int set);
|
||||
bool linenoiseIsDumbMode(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue