X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.cc;h=96e1b3dbff2a5f01998c480e85e069cd5086055f;hb=51a365af19cc63be6c61820f65423d58670cbee1;hp=fbd2d3dd59ed0c11632479b134e5023a3c2ce066;hpb=414ff39c648ddaca4e7fde98bbc2c033f1e23d2d;p=selector.git diff --git a/selector.cc b/selector.cc index fbd2d3d..96e1b3d 100644 --- a/selector.cc +++ b/selector.cc @@ -23,7 +23,7 @@ */ // To use it as a super-history-search for bash: -// alias h='selector -d -i -b -v -f <(history)' +// selector -q -b -i -d -v -w -l 10000 <(history) #include #include @@ -70,10 +70,11 @@ void inject_into_tty_buffer(char *string) { memset(&newtio, 0, sizeof(newtio)); // Set input mode (non-canonical, *no echo*,...) tcsetattr(STDIN_FILENO, TCSANOW, &newtio); + const char control_q = '\021'; // Put the selected string in the tty input buffer - char control_q = '\021'; - for(char *k = string; *k; k++) { - if(add_control_qs) { + for(const char *k = string; *k; k++) { + if(add_control_qs && !(*k >= ' ' && *k <= '~')) { + // Add ^Q to quote control characters ioctl(STDIN_FILENO, TIOCSTI, &control_q); } ioctl(STDIN_FILENO, TIOCSTI, k); @@ -348,7 +349,6 @@ void update_screen(int *current_line, int *temporary_line, int motion, int nb_printed_lines = 0; - clear(); use_default_colors(); addstr("\n"); @@ -444,6 +444,8 @@ void update_screen(int *current_line, int *temporary_line, int motion, buffer[k++] = '\n'; buffer[k++] = '\0'; + clrtoeol(); + // Highlight the highlighted line ... if(l == new_line) { @@ -478,6 +480,8 @@ void update_screen(int *current_line, int *temporary_line, int motion, addnstr("[empty choice]\n", console_width); } + clrtobot(); + // Draw the modeline move(0, 0); @@ -868,6 +872,7 @@ int main(int argc, char **argv) { char pattern[buffer_size]; pattern[0] = '\0'; + int cursor_position; cursor_position = 0; @@ -908,7 +913,8 @@ int main(int argc, char **argv) { int key; int current_line = 0, temporary_line = 0; - update_screen(¤t_line, &temporary_line, 0, nb_lines, labels, cursor_position, pattern); + update_screen(¤t_line, &temporary_line, 0, + nb_lines, labels, cursor_position, pattern); do { @@ -993,6 +999,11 @@ int main(int argc, char **argv) { kill_after_cursor(pattern, &cursor_position); } + else if(key == '\014') { // ^L + // I suspect that we may sometime mess up the display + clear(); + } + update_screen(¤t_line, &temporary_line, motion, nb_lines, labels, cursor_position, pattern);