Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
256deeca
Commit
256deeca
authored
Sep 22, 2014
by
antirez
Browse files
Linenoise lib updated.
parent
beafebb4
Changes
2
Show whitespace changes
Inline
Side-by-side
deps/linenoise/linenoise.c
View file @
256deeca
...
...
@@ -56,10 +56,6 @@
* flickering effect with some slow terminal, but the lesser sequences
* the more compatible.
*
* CHA (Cursor Horizontal Absolute)
* Sequence: ESC [ n G
* Effect: moves cursor to column n
*
* EL (Erase Line)
* Sequence: ESC [ n K
* Effect: if n is 0 or missing, clear from cursor to end of line
...
...
@@ -68,7 +64,19 @@
*
* CUF (CUrsor Forward)
* Sequence: ESC [ n C
* Effect: moves cursor forward of n chars
* Effect: moves cursor forward n chars
*
* CUB (CUrsor Backward)
* Sequence: ESC [ n D
* Effect: moves cursor backward n chars
*
* The following is used to get the terminal width if getting
* the width with the TIOCGWINSZ ioctl fails
*
* DSR (Device Status Report)
* Sequence: ESC [ 6 n
* Effect: reports the current cusor position as ESC [ n ; m R
* where n is the row and m is the column
*
* When multi line mode is enabled, we also use an additional escape
* sequence. However multi line editing is disabled by default.
...
...
@@ -81,14 +89,15 @@
* Sequence: ESC [ n B
* Effect: moves cursor down of n chars.
*
* The following are used to clear the screen: ESC [ H ESC [ 2 J
* This is actually composed of two sequences:
* When linenoiseClearScreen() is called, two additional escape sequences
* are used in order to clear the screen and position the cursor at home
* position.
*
*
cursorhome
*
CUP (Cursor position)
* Sequence: ESC [ H
* Effect: moves the cursor to upper left corner
*
* ED
2
(
Clear entire screen
)
* ED (
Erase display
)
* Sequence: ESC [ 2 J
* Effect: clear the whole screen
*
...
...
@@ -471,7 +480,7 @@ static void refreshSingleLine(struct linenoiseState *l) {
abInit
(
&
ab
);
/* Cursor to left edge */
snprintf
(
seq
,
64
,
"
\
x1b
[0G
"
);
snprintf
(
seq
,
64
,
"
\
r
"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
/* Write the prompt and the current buffer content */
abAppend
(
&
ab
,
l
->
prompt
,
strlen
(
l
->
prompt
));
...
...
@@ -480,7 +489,7 @@ static void refreshSingleLine(struct linenoiseState *l) {
snprintf
(
seq
,
64
,
"
\x1b
[0K"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
/* Move cursor to original position. */
snprintf
(
seq
,
64
,
"
\
x1b
[0G
\x1b
[%dC"
,
(
int
)(
pos
+
plen
));
snprintf
(
seq
,
64
,
"
\
r
\x1b
[%dC"
,
(
int
)(
pos
+
plen
));
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
if
(
write
(
fd
,
ab
.
b
,
ab
.
len
)
==
-
1
)
{}
/* Can't recover from write error. */
abFree
(
&
ab
);
...
...
@@ -496,6 +505,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
int
rows
=
(
plen
+
l
->
len
+
l
->
cols
-
1
)
/
l
->
cols
;
/* rows used by current buf. */
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
fd
=
l
->
ofd
,
j
;
struct
abuf
ab
;
...
...
@@ -515,13 +525,13 @@ static void refreshMultiLine(struct linenoiseState *l) {
/* Now for every row clear it, go up. */
for
(
j
=
0
;
j
<
old_rows
-
1
;
j
++
)
{
lndebug
(
"clear+up"
);
snprintf
(
seq
,
64
,
"
\
x1b
[0G
\x1b
[0K
\x1b
[1A"
);
snprintf
(
seq
,
64
,
"
\
r
\x1b
[0K
\x1b
[1A"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
}
/* Clean the top line. */
lndebug
(
"clear"
);
snprintf
(
seq
,
64
,
"
\
x1b
[0G
\x1b
[0K"
);
snprintf
(
seq
,
64
,
"
\
r
\x1b
[0K"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
/* Write the prompt and the current buffer content */
...
...
@@ -536,7 +546,7 @@ static void refreshMultiLine(struct linenoiseState *l) {
{
lndebug
(
"<newline>"
);
abAppend
(
&
ab
,
"
\n
"
,
1
);
snprintf
(
seq
,
64
,
"
\
x1b
[0G
"
);
snprintf
(
seq
,
64
,
"
\
r
"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
rows
++
;
if
(
rows
>
(
int
)
l
->
maxrows
)
l
->
maxrows
=
rows
;
...
...
@@ -554,8 +564,12 @@ static void refreshMultiLine(struct linenoiseState *l) {
}
/* Set column. */
lndebug
(
"set col %d"
,
1
+
((
plen
+
(
int
)
l
->
pos
)
%
(
int
)
l
->
cols
));
snprintf
(
seq
,
64
,
"
\x1b
[%dG"
,
1
+
((
plen
+
(
int
)
l
->
pos
)
%
(
int
)
l
->
cols
));
col
=
(
plen
+
(
int
)
l
->
pos
)
%
(
int
)
l
->
cols
;
lndebug
(
"set col %d"
,
1
+
col
);
if
(
col
)
snprintf
(
seq
,
64
,
"
\r\x1b
[%dC"
,
col
);
else
snprintf
(
seq
,
64
,
"
\r
"
);
abAppend
(
&
ab
,
seq
,
strlen
(
seq
));
lndebug
(
"
\n
"
);
...
...
@@ -757,6 +771,7 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen,
case
ENTER
:
/* enter */
history_len
--
;
free
(
history
[
history_len
]);
if
(
mlmode
)
linenoiseEditMoveEnd
(
&
l
);
return
(
int
)
l
.
len
;
case
CTRL_C
:
/* ctrl-c */
errno
=
EAGAIN
;
...
...
@@ -765,7 +780,7 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen,
case
8
:
/* ctrl-h */
linenoiseEditBackspace
(
&
l
);
break
;
case
CTRL_D
:
/* ctrl-d, remove char at right of cursor, or
o
f the
case
CTRL_D
:
/* ctrl-d, remove char at right of cursor, or
i
f the
line is empty, act as end-of-file. */
if
(
l
.
len
>
0
)
{
linenoiseEditDelete
(
&
l
);
...
...
@@ -904,7 +919,7 @@ void linenoisePrintKeyCodes(void) {
printf
(
"'%c' %02x (%d) (type quit to exit)
\n
"
,
isprint
(
c
)
?
c
:
'?'
,
(
int
)
c
,
(
int
)
c
);
printf
(
"
\
x1b
[0G
"
);
/* Go left edge manually, we are in raw mode. */
printf
(
"
\
r
"
);
/* Go left edge manually, we are in raw mode. */
fflush
(
stdout
);
}
disableRawMode
(
STDIN_FILENO
);
...
...
deps/linenoise/linenoise.h
View file @
256deeca
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment