Commit Graph

109 Commits

Author SHA1 Message Date
antirez
c1c5a026d0 Move to end before return when in multi-line mode.
This makes sure that if we are editing in multi-line mode a line that
actually spawns across multiple lines, the next output performed by the
application using linenoise will not overwrite the edited line.
2014-09-03 11:49:43 +02:00
antirez
01e723a095 Replace ESC 999D with CR.
OSX default Terminal app does not handle 999D well, the cursor will wrap
back to the previous row in the last colum, instead of ignoring the
sequence if the cursor is already at the left edge.

In order to avoid reintroducing the nG sequence that is not compatible
with base VT100 emulation and ANSI.SYS, we use CR that should be
hopefully widely supported.
2014-09-03 11:38:19 +02:00
antirez
c84d0a02ce Don't emit ESC [ n C with n=0.
This fixes a bug introduced with ANSI.SYS compatibility.
When we want to move at a specific column, we need to emit the sequence
to move the cursor to the right (after we moved 999 positions to the left)
only if we want to actually move right at least 1 position, since a
count of zero will still move the cursor one position to the right.
2014-09-03 10:11:31 +02:00
antirez
471e754601 Better specify the set of escapes used. 2014-09-03 09:51:29 +02:00
antirez
0a745fca68 Avoid CHA sequence for ANSI.SYS compatibility.
Github user @welash proposed a change in issue #73 in order to improve
the linenoise compatibility with older terminal emulators only able to
deal with a subset of ANSI sequences, notably ANSI.SYS and VT100
terminals strictly able to handle the original set of VT100 escape
sequences.

In order to improve the compatibility, the CHA sequence was removed and
translated to move 999 positions to the left, then move on the right
for the desired number of positions. The CHA sequence was apparently
added only with VT220, that's why it is not available everywhere.

This commit features almost exactly the change proposed in issue #73
with a small fix for a bug in multi-line editing mode introduced by the
patch.
2014-09-03 09:30:32 +02:00
antirez
828b9dacc5 Remove trailing spaces from source code. 2014-09-03 00:02:15 +02:00
antirez
e0f15a65d6 Multi line editing is no longer experimental.
It is now the default in the Redis command line interface so it is
used by many users every day.
2014-04-18 17:47:49 +02:00
antirez
0ca0326a74 Fixed yet another 1000 lines claim. 2014-04-18 17:46:47 +02:00
antirez
542ad7e346 Linenoise is now ~ 1100 lines of code ;-)
Fixes issue #63.
2014-04-18 17:45:46 +02:00
antirez
c86280ed0c linenoiseHistoryAdd() reworked + duplicated lines prevented. 2014-03-13 12:40:02 +01:00
antirez
2a92a4d19b Check read() return value in getCursorPosition(). 2014-03-13 12:27:53 +01:00
antirez
ca20f8c4bc Support for Home / End keys.
Some terminal reports ESC [H and ESC [F, while some other reports
ESC OH and ESC OF. We support both but there is at least another
variant documented, hopefully no longer.
2014-03-13 12:25:14 +01:00
antirez
8447b2b0f0 Fix right arrow handling.
Bug introduced in recent refactoring.
2014-03-13 12:20:11 +01:00
antirez
9e1c23185b If ioctl() fails get num of columns querying the terminal.
This change makes linenoise both more robust if the ioctl() fails, and
far more portable to non POSIX systems, since the ioclt() to query the
terminal was probably one of the non trivial parts to replace.

The code is inspired to Andreas Kupries commit 24186e99 on the win32
Linenoise port from Steve Bennett, but is a complete reimplementation.
2014-03-13 12:04:36 +01:00
antirez
fb015dabbd linenoiseEdit() escapes processing refactor. 2014-03-13 11:08:37 +01:00
antirez
4115b61663 Compare human readable key codes with chars literals.
Many sequences are actually human readable and fall into the printable
ASCII subset, they are a lot more recognizable when written as chars
compared to numbers.

For example up arrow is sent back from the terimal as ESC [A, and so
forth.

This commit makes the code speak the same "language" that you find in
any terminal escape sequences documentation.
2014-03-13 10:30:31 +01:00
antirez
3e521d47df linenoisePrintKeyCodes(): show character if printable. 2014-03-13 10:19:07 +01:00
antirez
f698ec47d1 Rename Scan codes -> Key codes.
What we print in debug mode using the option (now) called --keycodes
are not the scan codes, but the key codes returned by the terminal (a
more higher level representation of the keys pressed).

This commit fixes the word used.
2014-03-13 10:10:30 +01:00
antirez
cb0d040010 Fix Del key processing + minor cleanup. 2014-03-12 23:49:54 +01:00
antirez
bbcf9bf246 Scan codes debugging functionality.
./linenoise_example --scancodes
2014-03-12 23:38:48 +01:00
antirez
a05ab23df6 Use the two-reads fix for the additional escapes as well.
See commit e153bd8 for more information.
The gist is that slow terminals may return a short read of 1 byte.
2014-03-12 23:25:27 +01:00
antirez
d5ec9cbbaa Arrow scancodes replaced with enums in linenoiseEdit(). 2014-03-12 23:10:48 +01:00
Nick Gasson
e153bd83ab Fix escape sequence processing when only one byte available
The read call in the escape sequence processing does not
handle the case where only the first byte is available. This can
happen for example on a slow serial terminal.

Comment by @antirez:

I reworked the code for brevity, for historical reasons here is the
proposed patch. I believe my fix should be functionally equivalent.

Original fix:

             case 27:    /* escape sequence */
                 /* Read the next two bytes representing the
                    escape sequence. */
    -            if (read(fd,seq,2) == -1) break;
    +            {
    +                ssize_t b = read(fd, seq, 2);
    +
    +                if (b < 0) break;
    +
    +                if (b == 1) {
    +                    b = read(fd,&seq[1], 1);
    +                    if (b != 1) {
    +                        break;
    +                    }
    +                }
    +            }

See PR #47.
2014-03-12 16:32:42 +01:00
antirez
8d4566825c Merge branch 'master' of github.com:/antirez/linenoise 2014-03-12 16:28:32 +01:00
Nick Gasson
fb2385900d Add extern "C" around linenoise.h when compiled as C++ 2014-03-12 16:26:15 +01:00
Salvatore Sanfilippo
3cc30b1b2a Merge pull request #48 from nickg/emacs
Add "emacs" to unsupported_term
2014-03-12 16:23:24 +01:00
Salvatore Sanfilippo
94cbdd6540 Merge pull request #49 from polch/master_fixes
fix linenoiseEdit buflen decreasing.
2014-03-12 16:22:13 +01:00
Salvatore Sanfilippo
ff91a64c78 Merge pull request #51 from MartinNowak/const
use const char * when modification isn't necessary
2014-03-12 16:19:51 +01:00
antirez
01cd117f47 Don't assume STDIN_FD and STDOUT_FD are interchangeable. 2014-03-12 16:18:20 +01:00
Shengwen1997
49635f1cca Add the key enumeration 2014-03-12 16:07:14 +01:00
antirez
8ea25f8da3 Debugging code cleanup. 2014-03-12 15:38:37 +01:00
antirez
f3a4e0629c Merge branch 'master' of git://github.com/antirez/linenoise 2014-03-12 13:12:29 +01:00
antirez
cbf172f79d Handle malloc error in linenoiseAddCompletion().
We just don't add the entry on out of memory to avoid to
break the API with previous versions of Linenoise.
2014-03-12 13:10:44 +01:00
antirez
aed9d1af9f Refresh line with single write to avoid flickering.
Escape sequences and actual content to write to the terminal is now
accumulated into an heap allocated buffer that is flushed with a single
write at the end. This avoids a flickering effect making linenoise more
professional looking ;-)
2014-03-12 13:04:26 +01:00
Salvatore Sanfilippo
2022fb1fc8 Merge pull request #53 from insop/master
fix incorrect type caused issue on 64bit powerpc
2014-02-21 10:48:29 +01:00
Insop Song
5f5cc2eaae fix incorrect type caused issue on 64bit powerpc
Signed-off-by: Insop Song <insop.song@gainspeed.com>
2014-02-21 01:21:13 -08:00
Martin Nowak
9031c808f0 use const char * when modification isn't necessary 2014-01-28 00:53:26 +01:00
Paul Chavent
3258af5ac9 fix linenoiseEdit buflen decreasing. 2014-01-15 22:52:18 +01:00
Nick Gasson
4642c1ae25 Add "emacs" to unsupported_term
The Emacs terminal emulator has its own line editing and does not
behave correctly in raw mode. Without this programs using linenoise
will hang when run inside an Emacs shell.
2014-01-06 11:19:36 +00:00
Salvatore Sanfilippo
27a3b4d520 Merge pull request #31 from fperrad/buildroot
fix getColumns() for Buildroot
2013-02-08 03:33:05 -08:00
antirez
59a4fc96d8 Example app improved. 2013-02-08 12:24:07 +01:00
antirez
64e109e26c linenoiseHistorySetMaxLen() was broken and never tested. Fixed. 2013-02-08 12:18:42 +01:00
antirez
5654f543aa Merge branch 'master' of git://github.com/antirez/linenoise 2013-02-08 00:12:39 +01:00
antirez
892ec0fe4c Completion fixed (broken during refactoring). 2013-02-08 00:12:01 +01:00
Salvatore Sanfilippo
dac4299905 Merge pull request #30 from shvechikov/patch-1
Typo: readl -> real
2013-02-07 15:05:56 -08:00
antirez
4cc1ac4984 Merge branch 'master' of git://github.com/antirez/linenoise 2013-02-07 17:31:25 +01:00
antirez
09ddc70963 Fix to multi-line mode when deleting cross-line with cursor at EOL. 2013-02-07 17:30:49 +01:00
Salvatore Sanfilippo
d6373b3139 Merge pull request #37 from spullara/patch-1
Reducing the lines of code from 1 million to 1 thousand
2013-02-07 08:18:29 -08:00
Sam Pullara
d7f2c5c567 Reducing the lines of code from 1 million to 1 thousand 2013-02-07 08:17:39 -08:00
antirez
752175d66b Linenoise is now ~1000 lines of code, not 400. 2013-02-07 17:02:48 +01:00