mirror of
https://github.com/troglobit/editline.git
synced 2025-05-05 20:11:12 +08:00
Merge branch 'dev'
This commit is contained in:
commit
3cf0e89a68
58
README.md
58
README.md
@ -1,6 +1,6 @@
|
||||
Editline
|
||||
========
|
||||
[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
||||
[![License Badge][]][License] [![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
||||
|
||||
|
||||
Table of Contents
|
||||
@ -20,7 +20,7 @@ This is a small [line editing][] library. It can be linked into almost
|
||||
any program to provide command line editing and history functions. It
|
||||
is call compatible with the [FSF readline][] library, but at a fraction
|
||||
of the size, and as a result fewer features. It is also distributed
|
||||
under a much more liberal [LICENSE][].
|
||||
under a much more liberal [License][].
|
||||
|
||||
The small size (<30k), lack of dependencies (ncurses not needed!), and
|
||||
the free license should make this library interesting to many embedded
|
||||
@ -57,7 +57,7 @@ availble in the source tree.
|
||||
#include <stdlib.h>
|
||||
#include <editline.h>
|
||||
|
||||
int main (void)
|
||||
int main(void)
|
||||
{
|
||||
char *p;
|
||||
|
||||
@ -130,17 +130,17 @@ to [FSF readline][], which may not be entirely up-to-date.
|
||||
int el_hist_size; /* Size of history scrollback buffer, default: 15 */
|
||||
|
||||
/* Editline specific functions. */
|
||||
char * el_find_word(void);
|
||||
void el_print_columns(int ac, char **av);
|
||||
el_status_t el_ring_bell(void);
|
||||
el_status_t el_del_char(void);
|
||||
char * el_find_word (void);
|
||||
void el_print_columns (int ac, char **av);
|
||||
el_status_t el_ring_bell (void);
|
||||
el_status_t el_del_char (void);
|
||||
|
||||
/* Callback function for key binding */
|
||||
typedef el_status_t el_keymap_func_t(void);
|
||||
|
||||
/* Bind key to a callback, use CTL('f') to change Ctrl-F, for example */
|
||||
el_status_t el_bind_key(int key, el_keymap_func_t function);
|
||||
el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);
|
||||
el_status_t el_bind_key (int key, el_keymap_func_t function);
|
||||
el_status_t el_bind_key_in_metamap (int key, el_keymap_func_t function);
|
||||
|
||||
/* For compatibility with FSF readline. */
|
||||
int rl_point;
|
||||
@ -151,32 +151,32 @@ to [FSF readline][], which may not be entirely up-to-date.
|
||||
const char *rl_readline_name;
|
||||
|
||||
void (*rl_deprep_term_function)(void);
|
||||
void rl_deprep_terminal(void);
|
||||
void rl_reset_terminal(const char *terminal_name);
|
||||
void rl_deprep_terminal (void);
|
||||
void rl_reset_terminal (const char *terminal_name);
|
||||
|
||||
void rl_initialize(void);
|
||||
void rl_uninitialize(void); /* Free all internal memory */
|
||||
void rl_initialize (void);
|
||||
void rl_uninitialize (void); /* Free all internal memory */
|
||||
|
||||
void rl_save_prompt(void);
|
||||
void rl_restore_prompt(void);
|
||||
void rl_set_prompt(const char *prompt);
|
||||
void rl_save_prompt (void);
|
||||
void rl_restore_prompt (void);
|
||||
void rl_set_prompt (const char *prompt);
|
||||
|
||||
void rl_clear_message(void);
|
||||
void rl_forced_update_display(void);
|
||||
void rl_clear_message (void);
|
||||
void rl_forced_update_display (void);
|
||||
|
||||
/* Main function to use, saves history by default */
|
||||
char *readline(const char *prompt);
|
||||
char *readline (const char *prompt);
|
||||
|
||||
/* Use to save a read line to history, when el_no_hist is set */
|
||||
void add_history(const char *line);
|
||||
void add_history (const char *line);
|
||||
|
||||
/* Load and save editline history from/to a file. */
|
||||
int read_history(const char *filename);
|
||||
int write_history(const char *filename);
|
||||
int read_history (const char *filename);
|
||||
int write_history (const char *filename);
|
||||
|
||||
/* Magic completion API, see examples/cli.c for more info */
|
||||
rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func);
|
||||
rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func);
|
||||
rl_complete_func_t *rl_set_complete_func (rl_complete_func_t *func);
|
||||
rl_list_possib_func_t *rl_set_list_possib_func (rl_list_possib_func_t *func);
|
||||
|
||||
/* Alternate interface to plain readline(), for event loops */
|
||||
void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);
|
||||
@ -216,10 +216,10 @@ Origin & References
|
||||
--------------------
|
||||
|
||||
This [line editing][] library was created by [Rich Salz][] and Simmule
|
||||
Turner and in 1992. It is distributed under a “C News-like” license,
|
||||
similar to the [BSD license][]. Rich's latest version is however under
|
||||
Turner and in 1992. It is distributed with a “[C News][]-like” license,
|
||||
similar to the [BSD license][]. Rich's current version is however under
|
||||
the Apache license. For details on the licensing terms of this version
|
||||
of the software, see [LICENSE][].
|
||||
of the software, see [License][].
|
||||
|
||||
This version of the editline library was forked from the [Minix 3][]
|
||||
source tree and is *not* related to the similarily named NetBSD version
|
||||
@ -249,7 +249,7 @@ Outstanding issues are listed in the [TODO.md][] file.
|
||||
[line editing]: https://github.com/troglobit/editline/blob/master/doc/README
|
||||
[release tarball]: https://github.com/troglobit/editline/releases
|
||||
[maintainer]: http://troglobit.com
|
||||
[LICENSE]: https://github.com/troglobit/editline/blob/master/LICENSE
|
||||
[C News]: https://en.wikipedia.org/wiki/C_News
|
||||
[TODO.md]: https://github.com/troglobit/editline/blob/master/TODO.md
|
||||
[ChangeLog.md]: https://github.com/troglobit/editline/blob/master/ChangeLog.md
|
||||
[FSF readline]: http://www.gnu.org/software/readline/
|
||||
@ -262,6 +262,8 @@ Outstanding issues are listed in the [TODO.md][] file.
|
||||
[Heimdal]: http://www.h5l.org
|
||||
[Festival]: http://festvox.org/festival/
|
||||
[Steve Tell]: http://www.cs.unc.edu/~tell/dist.html
|
||||
[License]: https://github.com/troglobit/editline/blob/master/LICENSE
|
||||
[License Badge]: https://img.shields.io/badge/License-C%20News-orange.svg
|
||||
[Travis]: https://travis-ci.org/troglobit/editline
|
||||
[Travis Status]: https://travis-ci.org/troglobit/editline.png?branch=master
|
||||
[Coverity Scan]: https://scan.coverity.com/projects/2982
|
||||
|
1
examples/.gitignore
vendored
1
examples/.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.o
|
||||
cli
|
||||
testit
|
||||
excallback
|
@ -134,6 +134,8 @@ main()
|
||||
rl_callback_read_char();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -168,7 +170,8 @@ change_prompt(void)
|
||||
prompt = !prompt;
|
||||
|
||||
/* save away the current contents of the line */
|
||||
strcpy(line_buf, rl_line_buffer);
|
||||
strncpy(line_buf, rl_line_buffer, sizeof(line_buf));
|
||||
line_buf[sizeof(line_buf) - 1] = 0;
|
||||
|
||||
/* install a new handler which will change the prompt and erase the current line */
|
||||
rl_callback_handler_install(get_prompt(), process_line);
|
||||
@ -179,7 +182,7 @@ change_prompt(void)
|
||||
/* redraw the current line - this is an undocumented function. It invokes the
|
||||
* redraw-current-line command.
|
||||
*/
|
||||
rl_refresh_line(0, 0);
|
||||
return rl_refresh_line(0, 0);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -892,6 +892,31 @@ el_status_t el_del_char(void)
|
||||
return del_char();
|
||||
}
|
||||
|
||||
static el_status_t fd_word(void)
|
||||
{
|
||||
return do_forward(CSmove);
|
||||
}
|
||||
|
||||
static el_status_t bk_word(void)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
for (p = &rl_line_buffer[rl_point]; p > rl_line_buffer && !is_alpha_num(p[-1]); p--)
|
||||
left(CSmove);
|
||||
|
||||
for (; p > rl_line_buffer && !isblank(p[-1]) && is_alpha_num(p[-1]); p--)
|
||||
left(CSmove);
|
||||
|
||||
if (rl_point == 0)
|
||||
break;
|
||||
} while (++i < Repeat);
|
||||
|
||||
return CSstay;
|
||||
}
|
||||
|
||||
static el_status_t meta(void)
|
||||
{
|
||||
int c;
|
||||
@ -905,6 +930,20 @@ static el_status_t meta(void)
|
||||
if (c == '[' || c == 'O') {
|
||||
switch (tty_get()) {
|
||||
case EOF: return CSeof;
|
||||
case '1':
|
||||
{
|
||||
char seq[4] = { 0 };
|
||||
|
||||
for (c = 0; c < 3; c++)
|
||||
seq[c] = tty_get();
|
||||
|
||||
if (!strncmp(seq, ";5C", 3))
|
||||
return fd_word(); /* Ctrl+Right */
|
||||
if (!strncmp(seq, ";5D", 3))
|
||||
return bk_word(); /* Ctrl+Left */
|
||||
|
||||
break;
|
||||
}
|
||||
case '2': tty_get(); return CSstay; /* Insert */
|
||||
case '3': tty_get(); return del_char(); /* Delete */
|
||||
case '5': tty_get(); return CSstay; /* PgUp */
|
||||
@ -1689,11 +1728,6 @@ static el_status_t move_to_char(void)
|
||||
return CSstay;
|
||||
}
|
||||
|
||||
static el_status_t fd_word(void)
|
||||
{
|
||||
return do_forward(CSmove);
|
||||
}
|
||||
|
||||
static el_status_t fd_kill_word(void)
|
||||
{
|
||||
int i;
|
||||
@ -1708,26 +1742,6 @@ static el_status_t fd_kill_word(void)
|
||||
return CSstay;
|
||||
}
|
||||
|
||||
static el_status_t bk_word(void)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
for (p = &rl_line_buffer[rl_point]; p > rl_line_buffer && !is_alpha_num(p[-1]); p--)
|
||||
left(CSmove);
|
||||
|
||||
for (; p > rl_line_buffer && !isblank(p[-1]) && is_alpha_num(p[-1]); p--)
|
||||
left(CSmove);
|
||||
|
||||
if (rl_point == 0)
|
||||
break;
|
||||
} while (++i < Repeat);
|
||||
|
||||
return CSstay;
|
||||
}
|
||||
|
||||
static el_status_t bk_kill_word(void)
|
||||
{
|
||||
bk_word();
|
||||
|
Loading…
Reference in New Issue
Block a user