summaryrefslogtreecommitdiffstats
path: root/linenoise
Commit message (Collapse)AuthorAgeFilesLines
...
* linenoise: parenthesis-matching backward jump.Kaz Kylheku2015-09-151-0/+94
| | | | | | | | | | | * linenoise/linenoise.c (LINENOISE_PAREN_DELAY): New preprocessor symbol. (scan_match_rev, scan_rev, usec_delay, paren_jump): New static functions. (edit): Handle closing parenthesis, bracket and brace by inserting and calling paren_jump. * txr.1: Documented.
* linenoise: handle SIGWINCH resize signal.Kaz Kylheku2015-09-141-2/+64
| | | | | | | | | | | | | | | | | | | | * linenoise/linenoise.c (struct lino_state): New member, need_resize. (lino_list_busy): New static variable. (handle_resize): New function. (complete_line, history_search, edit): Check for the tty read being interrupted, and in that case call handle_resize to put the resize into effect, and continue the loop to fetch another character. (sigwich_handler): New function. (linenoise): If we have SIGWINCH, install a handler for it temporarily. (link_into_list, unlink_from_list): Set global busy flag around list manipulations. The signal handler stays away if these are set. This means that if the user performs some action that requires a lino_t to be constructed (e.g. types Ctrl-R to search), while resizing the window at almost exactly the same time, we will lose the resize signal. Oh well!
* linenoise: recognize additional commands in search.Kaz Kylheku2015-09-131-0/+10
| | | | | | | | | * linenoise/linenoise.c (history_search): Editing keys should leave search mode and be processed in command mode. Also, let's have Ctrl-L and Ctrl-Z work, but stay in search mode. * txr.1: Documented.
* linenoise: suppress duplicates in Ctrl-R search.Kaz Kylheku2015-09-131-2/+8
| | | | | | * linenoise/linenoise.c (history_search): Don't step through identical lines, which looks as if Ctrl-R is being ignored.
* linenoise: support completion in the middle of line.Kaz Kylheku2015-09-121-12/+20
| | | | | | | | | * linenoise/linenoise.c (compare_completions): Restructure with help of new lino_copy function to collect completions just for the prefix of the line up to the cursor position, and recombine those with the suffix. * txr.1: Doc updated.
* linenoise: incorrect ESC treatment in completion.Kaz Kylheku2015-09-121-3/+1
| | | | | | | | | | * linenoise/linenoise.c (complete_line): ESC must not be treated specially when leaving completion mode; it must accept the completed line. The original code did this wrong in my opinion and I propagated the error. * txr.1: Remove all mention of special ESC treatment in completion mode.
* linenoise: Suppress unknown control characters.Kaz Kylheku2015-09-121-0/+2
| | | | | | | * linenoise/linenoise.c (edit): Don't let characters less than 32 be inserted. * txr.1: Documented that control characters are rejected.
* linenoise: Ctrl-R searchKaz Kylheku2015-09-121-3/+135
| | | | | | | | | | | * linenoise/linenoise.c (next_hist_match, history_search): New static function. (edit): New Ctrl-R case added to early switch that also handles Tab completion, and calls history_search. (lino_free): Adding null check, so we can safely call lino_free(0). history_search relies on this. * txr.1: Documented search.
* linenoise: Ctrl-C cleanly cancels completion.Kaz Kylheku2015-09-111-0/+3
| | | | | | | | | | * linenoise/linenoise.c (complete_line): If Ctrl-C is pressed in completion mode, we cancel completion and return 0 so the command loop reads a new character. * txr.1: Documented Ctrl-C in completion mode, and removed the falsehood that ESC is a cancel command, adding instead an explanation about the ESC handling is really for.
* linenoise: replace 9 with TAB; anticipate extension.Kaz Kylheku2015-09-111-8/+14
| | | | | | | * linenoise/linenoise.c (edit): Code block which handles tab completion before main command dispatch uses the TAB symbol instead of 9, and is refactored into a switch statement which will also handle a history search command.
* linenoise: lino_copy function.Kaz Kylheku2015-09-112-7/+35
| | | | | | | | | | | | * linenoise/linenoise.c (link_into_list, unlink_from_list): New static functions. (lino_make): Use link_into_list instead of open-coded list manipulation. (lino_copy): New function. (lino_free): Use unlink_from list instead of open-coded list manipulation. * linenoise/linenoise.h (lino_copy): Declared.
* linenoise: sort completions by length.Kaz Kylheku2015-09-101-0/+19
| | | | | | | | | | Give the shorter completions first, and lexicographically within each length equivalence class. This effectively gives the user a breadth-first search through the trie of possible suffixes. * linenoise/linenoise.c (compare_completions): New static function. (complete_line): Apply qsort to the collected vector of strings. Easy does it.
* linenoise: fix g++ signed/unsigned warning.Kaz Kylheku2015-09-091-1/+2
| | | | | | * linenoise/linenoise.c (sync_data_to_buf): Cast l->dpos to the signed type ptrdiff_t when comparing to difference between two pointers.
* Reveal struct winsize on Solaris.Kaz Kylheku2015-09-091-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | On Solaris 10, we need __EXTENSIONS__ defined to make struct winsize appear out of <termios.h>. This commit adds detection for what preprocessor symbol needs to be defined for struct winsize to appear, if it appears at all. Then this symbol is defined on the compiler command line when compiling linenoise. * Makefile (CFLAGS): Add -D$(termios_define) for linenoise.o target. * configure (have_winsize, termios_define): New variables. Detect whether struct winsize is available, and what preprocessor symbol, if any, is required to reveal the feature. * linenoise/linenoise.c: Need to include TXR's "config.h" for HAVE_WINSIZE. (get_columns): Reorganized so that use of struct winsize is guarded by HAVE_WINSIZE and fallback code is used if either obtaining the size fails or the feature is completely unavailable.
* linenoise: remove input-viewing debug function.Kaz Kylheku2015-09-093-32/+0
| | | | | | | | | | | | This is unused code which just addds to the executable size. Also it passes a char to isprint, which is undefined behavior if that char happens to be negative. * linenoise/example.c (main): Remove --keycodes option and reference to lino_print_keycodes function. * linenoise/linenoise.c, linenoise/linenoise.h (lino_print_keycodes): Function removed.
* linenoise: don't touch OPOST termios output flag.Kaz Kylheku2015-09-081-2/+1
| | | | | | * linenoise/linenoise.c (enable_raw_mode): Do not clear the OPOST output flag. It is implementation-defined, and if it is set, it is probably set for a good reason.
* linenoise: stray printf on stdout.Kaz Kylheku2015-09-081-2/+5
| | | | | * linenoise/linenoise.c (linenoise): Replace printf("\n") with one-character write on ls->ofd.
* linenoise: don't flush tty input when changing mode.Kaz Kylheku2015-09-081-2/+2
| | | | | | | * linenoise/linenoise.c (enable_raw_mode, disable_raw_mode): Use TCSANOW instead of TCSAFLUSH to change tty settings without flushing input. TCSAFLUSH could discard type-ahead-buffered keystrokes.
* linenoise: stdin fd closed bug in !isatty case.Kaz Kylheku2015-09-081-1/+4
| | | | | | * linenoise/linenoise.c (linenoise): Of course, we must up ls->ifd and fdopen the dup, because fdopen closes the descriptor.
* linenoise: eliminate silly CTRL_<letter> constants.Kaz Kylheku2015-09-081-32/+18
| | | | | | | * linenoise/linenoise.c (CTL): New macro. (enum key_action): Removed CTRL_ members. (edit): Replace CTRL_A with CTL('A') and similarly for all others.
* linenoise: Ctrl-U deletes only to the left.Kaz Kylheku2015-09-081-4/+11
| | | | | | | | | | | Ctrl-U does not traditionally delete the entire line in line editors or text editors. Rather, it is a "super backspace" to the beginning of the line. * linenoise/linenoise.c (edit_delete_prev_all): New static function. (edit): Replace CTRL_U action with call to edit_delete_prev_all.
* linenoise: expand tabs to spaces instead of ^I.Kaz Kylheku2015-09-081-4/+10
| | | | | | | | | | * linenoise/linenoise.c (LINENOISE_MAX_LINE): Reduced to 1024. (LINENOISE_MAX_DISP): Now 8 times LINENOISE_MAX_LINE because the worst case is that the line contains only tabs, which expand to eight spaces. (sync_data_to_buf): Use character constants instead of hard coded values. Check for tab, and expand to spaces up to the next modulo 8 tab position.
* linenoise: delete word recognizes tabs as space.Kaz Kylheku2015-09-081-2/+3
| | | | | | * linenoise/linenoise.c (SPACE): New preprocessor symbol. (edit_delete_prev_word): Use strchr to check for spaces and tabs.
* linenoise: remove history and TODO list from comment.Kaz Kylheku2015-09-081-64/+0
|
* linenoise: Ctrl-Z suspend.Kaz Kylheku2015-09-071-0/+8
| | | | | * linenoise.c (key_action): New enum constant, CTRL_Z. (edit): Implement Ctrl-Z suspend.
* linenoise: STDIN_FILENO used as pointer.Kaz Kylheku2015-09-061-2/+2
| | | | | | | | * linenoise/linenoise.c (lino_print_codes): Pass l into enable_raw_mode rather than STDIN_FILENO. Read from l->ifd rather than STDIN_FILENO. since this is a debugging function, I'm leaving the printfs to stdio alone.
* linenoise: use checked allocator for strdup.Kaz Kylheku2015-09-061-4/+5
| | | | | | | | | | * lib.c (chk_strdup_utf8): New function. * lib.h (chk_strdup_utf8): Declared. * linenoise/linenoise.c (chk_strdup_utf8): Declared. (edit_history_next, linenoise, lino_hist_add): Use chk_strdup_utf8 instead of strdup.
* linenoise: remove bogus suport for crap terminals.Kaz Kylheku2015-09-061-55/+30
| | | | | | | | | | | | | If some program really needs this, it can be implemented in that program. * linenoise/linenoise.c (supported_term): Static array removed. (unsupported_term): Function removed. (linenoise): Function removed. (go_raw): Converted to linenoise function. For handling non-tty's, opens and closes a stdio stream over ls->ifd instead of using stdin and STDIN_FILENO.
* linenoise: error code distinguishes interrupt from eof.Kaz Kylheku2015-09-062-9/+55
| | | | | | | | | | | | | | | | | | In this commit, we introduce a persistent error variable stored in the lino_t structure, and functions to access it. * linenoise/linenoise.c (struct lino_state): New member, error. (enable_raw_mode): Don't set errno to ENOTTY; set linenoise error to lino_notty. (complete_line, edit, go_raw, linenoise, lino_hist_save, lino_hist_load): Set linenoise error before returning -1. (lino_get_error, lino_set_error): New functions. * linenoise/linenoise.h (enum lino_error, lino_error_t): New enum. (lino_get_error, lino_set_error): Declared.
* linenoise: use lino_t typedef everywhere.Kaz Kylheku2015-09-061-17/+17
| | | | | | | | | * linenoise.c (complete_line, sync_data_to_buf, refresh_singleline, refresh_multiline, refresh_line, edit_insert, edit_move_left, edit_move_right, edit_move_home, edit_move_end, edit_history_next, edit_delete, edit_backspace, edit_delete_prev_word): struct lino_state replaced with lino_t.
* linenoise: 27 and 9 to ESC and TAB.Kaz Kylheku2015-09-051-2/+2
| | | | | * linenoise/linenoise.c (complete_line): Use TAB and ESC instead of 9 and 27.
* linenoise: Ctrl-V verbatim insert.Kaz Kylheku2015-09-051-0/+12
| | | | | | * linenoise/linenoise.c (enum key_action): New enum constant, CTRL_V. (edit): Implement Ctrl-V.
* linenoise: remove useless comments, 8 -> CTRL_H.Kaz Kylheku2015-09-051-35/+34
| | | | | | | | | * linenoise/linenoise.c (enum key_action): Unused KEY_NULL removed. Removed uninformative comments next to self-explanatory enum constants. (edit): Removed uninformative comments next to cases based on enum key_action enum constants. Replaced 8 with CTRL_H.
* linenoise: separate display semantics from bufferKaz Kylheku2015-09-051-82/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The linenoise edit buffer now shows a printed representation of underlying data. In this printed representation, multiple characters can denote a single physical character, so that a control code like 15 can be displayed as ^M. In the future, this will help with a Unicode-ization of linenoise. The actual edit routines now operate on the data array rather than buf, and the new function sync_data_to_buf is used to synchronize buf with data for the sake of refreshing the display. * linenoise/linenoise.c (LINENOISE_MAX_DISP): New variable. (struct lino_state): buf member becomes an array, so the display buffer is now in the structure, and not stack allocated in the linenoise function. New members data, dlen and dpos for tracking the underlying data. Also, the buflen member variable is gone. Uses of buflen are replaced with sizeof. (sync_data_to_buf): New static function. (complete_line): Pass ls->data to callback, rather than ls->buf. In the saving and restoring trick used when displaying completions, we must copy in the completion to the data array; we cannot swizzle a buffer pointer like before. The restoration of the state is simplified; just copy back the entire original. Lastly, when a completion is selected, it must go into the data array, and not buf. Here, there is a bugfix; it appears that refresh_line was not called; I had to add that call. (Did that work before this change?) (refresh_line): Call sync_data_to_buf before calling either refresh function. (edit_insert, edit_move_left, edit_move_right, edit_move_home, edit_move_end, edit_history_next, edit_backspace, edit_delete_prev_word): Operate on data array, dlen and dpos rather than buf, len and pos. (edit): Doesn't take buffer and length parameters any more. No need to initialize context structure members buf, or removed member buflen. New members dlen and dpos have to be initialized. Inlined edit operations now work with data array, rather than buf. (go_raw): Buffer and buflen arguments are gone. Non-tty code still allocates buffer on stack, but only in its local block. (linenoise): Do not instantiate local buffer for passing to go_raw, which doesn't take one any more. When finished, duplicate the string in the data array.
* linenoise: hard-coded stream in generate_beep.Kaz Kylheku2015-09-051-5/+4
| | | | | | | * linenoise/linenoise.c (generate_beep): Take line noise context argument and send BEL character to output file descriptor, rather than hardcoding to stderr. (complete_line): Pass context to generate_beep.
* linenoise: get rid of globals; everything in struct.Kaz Kylheku2015-09-043-182/+234
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * linenoise/linenoise.c (completion_callback, orig_termios, rawmode, mlmode, history_max_len, history_len, history): Global variables removed; moved into struct lino_state. (struct lino_state): New members next, prev. New members completion_callback, orig_termios, rawmode, mlmode, history_max_len, history_len, history. (lino_list): New static variable: dummy node for circular list of struct lino_state structures. (lino_set_multiline): Operate on structure rather than global variable. (enable_raw_mode, disable_raw_mode): Operate on structure. Use file descriptors from structures rather than inconsistent hard-coded use of STDIN_FILENO and the argument fd, which is gone. (lino_clear_screen): Obtain file descriptor from structure, rather than global. (complete_line): Operate on structure rather than globals. Pass context to completion callback. (lino_set_completion_cb): Store callback in structure rather than global. Store new context argument also. (reresh_line): Take mode from structure rather than global. (edit_insert, edit_move_end): Operate on struture rather than globals. (edit): Do not accept file descriptor arguments. Do not update ifd and ofd members of structure; just rely on these values to already be there, since the lino_make constructor puts them there. (lino_print_keycodes, go_raw): Operate on structure. (lino_make, lino_free): New functions. (lino_cleanup): New static function. (linenoise, free_hist): Operate on structure. (atexit_handler): Loop over all structures in global list, and clean up each one. (lino_hist_add, lino_list_set_max_len, lino_hist_save, lino_hist_load): Operate on structure. * linenoise/linenoise.h (lino_t): New typedef. (lino_compl_cb_t): Function type takes new context argument. (lino_set_completion_cb, linenoise, lino_hist_add, lino_hist_set_max, lino_his_save, lino_hist_load, lino_clear_screen, lino_set_multiline, lino_print_keycodes): Declarations updated. * linenoise/example.c (completion): Take new context argument, and ignore it. (main): Create linenoise context with lino_make, giving it the input and output file descriptor, and pass it to all functions.
* Bringing in Linenoise example.Kaz Kylheku2015-09-041-0/+75
| | | | * linenoise/example.c: New file.
* linenoise: tty read fix.Kaz Kylheku2015-09-041-1/+2
| | | | | | * linenoise/linenoise.c (edit): If 0 bytes is read from the tty for any reason, return -1 so that the linenoise function will return a null pointer rather than a blank line.
* Null out freed history elements.Kaz Kylheku2015-09-041-7/+15
| | | | | | | | | | * linenoise/linenoise.c (edit): Set freed element of history array to null. (free_hist): Null out all elements, and then the array pointer. (lino_hist_set_max_len): Calculate value of history_len variable in obviously correct way, based on amount of history preserved.
* linenoise: change naming to conform to project.Kaz Kylheku2015-09-042-146/+145
| | | | | | | | linenoise/linenoise.c, linenoise/linenoise.h: Renaming all camel-case identifiers to underscores. The verbose linenoise prefix becomes lino_. All caps enum tag gets lower cased. Static functions with linenoise prefix lose the prefix.
* Eliminate tabs from linenoise source.Kaz Kylheku2015-09-041-19/+19
| | | | | | * linenoise/linenoise.c (enum KEY_ACTION): Remove tabs from declaration. This is the only place in the file which has tabs.
* linenoise: compile as C++ and use checked allocator.Kaz Kylheku2015-09-042-27/+19
| | | | | | | | | | | | | | | | | * linenoise/linenoise.c (mem_t): New typedef, compatible with the one in lib.h, which we don't want to include. (chk_malloc, chk_realloc): External declarations added. (unsupported_term): Make element type const char *. (linenoiseAddCompletion): Use checked allocator, add casts, use the superior "sizeof *dest_pointer_var" expression in size calculations rather than "sizeof (maybe_wrong_type)". (abAppend, linenoiseHistoryAdd, linenoiseHistorySetMaxLen): Likewise. * linenoise/linenoise.h: Remove unnecessary include guards; we don't use them in this project. Remove 'extern "C"'; we don't require C linkage when compiling everything as C++.
* Compile and link linkenoise into txr; fix errors.Kaz Kylheku2015-09-041-9/+9
| | | | | | | | | | | * Makefile (OBJS): Add linenoise/linenoise.o. * linenoise/linenoise.c (linenoiseEditInsert, linenoiseEditMoveLeft, linenoiseEditMoveRight, linenoiseEditMoveEnd, linenoiseEditHistoryNext, linenoiseEditDelete, linenoiseEditBackspace, linenoiseEditDeletePrevWord): These de facto internal functions are switched from external to static.
* Add linenoise library.Kaz Kylheku2015-09-033-0/+1200
* LICENSE: Add Linenoise authors to the list of copyright holders. * linenoise/LICENSE: New file. * linenoise/linenoise.c: New file. * linenoise/linenoise.h: New file.