mirror of https://gitee.com/bigwinds/arangodb
number of visible charaters of the prompt is saved in current structure
This commit is contained in:
parent
92c43d1f89
commit
0a4e416ebc
|
@ -170,7 +170,8 @@ struct current {
|
||||||
size_t pos; /* Cursor position, measured in chars */
|
size_t pos; /* Cursor position, measured in chars */
|
||||||
int cols; /* Size of the window, in chars */
|
int cols; /* Size of the window, in chars */
|
||||||
int rows; /* Screen rows */
|
int rows; /* Screen rows */
|
||||||
const char *prompt;
|
const char *prompt; /*string with control charaters for displaying the prompt */
|
||||||
|
size_t pchars; /*number of visible charaters in the prompt */
|
||||||
char *capture; /* Allocated capture buffer, or NULL for none. Always null terminated */
|
char *capture; /* Allocated capture buffer, or NULL for none. Always null terminated */
|
||||||
#if defined(USE_TERMIOS)
|
#if defined(USE_TERMIOS)
|
||||||
int fd; /* Terminal fd */
|
int fd; /* Terminal fd */
|
||||||
|
@ -314,12 +315,11 @@ static void clearScreen(struct current *current)
|
||||||
|
|
||||||
static void cursorToLeft(struct current *current)
|
static void cursorToLeft(struct current *current)
|
||||||
{
|
{
|
||||||
size_t pchars = 20;
|
|
||||||
/**
|
/**
|
||||||
* how many lines are need to display the current->pos characters of the
|
* how many lines are need to display the current->pos characters of the
|
||||||
* current buffer
|
* current buffer
|
||||||
*/
|
*/
|
||||||
size_t number_lines = new_line_numbers(current->pos, current->cols, pchars);
|
size_t number_lines = new_line_numbers(current->pos, current->cols, current->pchars);
|
||||||
/**
|
/**
|
||||||
* move cursor number_lines above
|
* move cursor number_lines above
|
||||||
*/
|
*/
|
||||||
|
@ -349,11 +349,10 @@ static void outputControlChar(struct current *current, char ch)
|
||||||
|
|
||||||
static void eraseEol(struct current *current)
|
static void eraseEol(struct current *current)
|
||||||
{
|
{
|
||||||
size_t pchars = 20;
|
|
||||||
/**
|
/**
|
||||||
* number of additional lines to display chars characters (the quite buffer)
|
* number of additional lines to display chars characters (the quite buffer)
|
||||||
*/
|
*/
|
||||||
size_t number_lines = new_line_numbers(current->chars, current->cols, pchars);
|
size_t number_lines = new_line_numbers(current->chars, current->cols, current->pchars);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
/**
|
/**
|
||||||
|
@ -1043,12 +1042,7 @@ static void refreshMultiLine(const char *prompt, struct current *current)
|
||||||
getWindowSize(current);
|
getWindowSize(current);
|
||||||
|
|
||||||
plen = strlen(prompt);
|
plen = strlen(prompt);
|
||||||
pchars = utf8_strlen(prompt, plen);
|
pchars = current->pchars;
|
||||||
/* Scan the prompt for embedded ansi color control sequences and
|
|
||||||
* discount them as characters/columns.
|
|
||||||
*/
|
|
||||||
pchars -= countColorControlChars(prompt);
|
|
||||||
|
|
||||||
|
|
||||||
/* Cursor to left edge, then the prompt */
|
/* Cursor to left edge, then the prompt */
|
||||||
// cursorToLeft(current);
|
// cursorToLeft(current);
|
||||||
|
@ -1468,8 +1462,7 @@ static void moveCursorToRight(struct current * current) {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void moveCursorToLeft(struct current * current) {
|
static void moveCursorToLeft(struct current * current) {
|
||||||
size_t pchars = 20;
|
int x = next_allowed_x(current->pos + 1, current->cols, current->pchars);
|
||||||
int x = next_allowed_x(current->pos + 1, current->cols, pchars);
|
|
||||||
if(x==0) {
|
if(x==0) {
|
||||||
fd_printf(current->fd, "\x1b[1A\x1b[%dG", current->cols);
|
fd_printf(current->fd, "\x1b[1A\x1b[%dG", current->cols);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1477,8 +1470,7 @@ static void moveCursorToLeft(struct current * current) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void moveCursorToRight(struct current * current) {
|
static void moveCursorToRight(struct current * current) {
|
||||||
size_t pchars = 20;
|
int x = next_allowed_x(current->pos-1, current->cols, current->pchars);
|
||||||
int x = next_allowed_x(current->pos-1, current->cols, pchars);
|
|
||||||
if(current->pos>current->chars) {
|
if(current->pos>current->chars) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1836,12 +1828,18 @@ char *linenoise(const char *prompt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
size_t pchars = utf8_strlen(prompt, strlen(prompt));
|
||||||
|
/* Scan the prompt for embedded ansi color control sequences and
|
||||||
|
* discount them as characters/columns.
|
||||||
|
*/
|
||||||
|
pchars -= countColorControlChars(prompt);
|
||||||
current.buf = buf;
|
current.buf = buf;
|
||||||
current.bufmax = sizeof(buf);
|
current.bufmax = sizeof(buf);
|
||||||
current.len = 0;
|
current.len = 0;
|
||||||
current.chars = 0;
|
current.chars = 0;
|
||||||
current.pos = 0;
|
current.pos = 0;
|
||||||
current.prompt = prompt;
|
current.prompt = prompt;
|
||||||
|
current.pchars = pchars;
|
||||||
current.capture = NULL;
|
current.capture = NULL;
|
||||||
|
|
||||||
initLinenoiseLine(¤t);
|
initLinenoiseLine(¤t);
|
||||||
|
|
Loading…
Reference in New Issue