X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=selector.c;h=aafaf9d63369a8bc7d12f058ed0af3df620614f4;hb=edb1db90ca786eb30c83464380df373a85b339a0;hp=0cb82ea6aa21f861ec23b34c14b9182facfe9d08;hpb=40783cf11bb49618d80fa3f588632a1c61c0ce2d;p=selector.git
diff --git a/selector.c b/selector.c
index 0cb82ea..aafaf9d 100644
--- a/selector.c
+++ b/selector.c
@@ -191,7 +191,7 @@ void usage(FILE *out) {
fprintf(out, " -a, --case-sensitive\n");
fprintf(out, " start in case sensitive mode\n");
fprintf(out, " -j, --show-long-lines\n");
- fprintf(out, " print three dots at the end of truncated lines\n");
+ fprintf(out, " print a long-line indicator at the end of truncated lines\n");
fprintf(out, " -y, --show-hits\n");
fprintf(out, " highlight the matching substrings\n");
fprintf(out, " -u, --upper-case-makes-case-sensitive\n");
@@ -206,6 +206,8 @@ void usage(FILE *out) {
fprintf(out, " -- all following arguments are filenames\n");
fprintf(out, " -t
, --title \n");
fprintf(out, " add a title in the modeline\n");
+ fprintf(out, " -r , --pattern \n");
+ fprintf(out, " set an initial pattern\n");
fprintf(out, " -c , --colors \n");
fprintf(out, " set the display colors with an argument of the form\n");
fprintf(out, " ,,,\n");
@@ -335,8 +337,8 @@ int add_interval(int n, int *switches, int start, int end) {
while(g < n && switches[g] <= end) { g++; }
if(f == n) {
- /* switches[n] start end */
- /* XXXXXXXXXX| */
+ /* switches[n-1] start end */
+ /* XXXXXXXXXXXX| */
switches[f] = start;
switches[f+1] = end;
return n + 2;
@@ -571,7 +573,6 @@ int next_visible(int current_line, int nb_lines, char **lines,
/*********************************************************************/
void print_string_with_switches(char *buffer, int line_width,
- int console_width,
int nb_patterns, int *switches) {
int w, current = 0, next;
if(switches) {
@@ -590,10 +591,10 @@ void print_string_with_switches(char *buffer, int line_width,
}
}
if(current < line_width) {
- addnstr(buffer + current, console_width - current);
+ addnstr(buffer + current, line_width - current);
}
} else {
- addnstr(buffer, console_width);
+ addnstr(buffer, line_width);
}
}
@@ -741,36 +742,37 @@ void update_screen(int *current_focus_line, int *displayed_focus_line,
if(l == new_focus_line) {
if(show_long_lines && k >= console_width) {
- if(console_width >= 4) {
- buffer[console_width - 4] = ' ';
- buffer[console_width - 3] = '.';
- buffer[console_width - 2] = '.';
- buffer[console_width - 1] = '.';
- }
+ attron(attr_focus_line);
+ print_string_with_switches(buffer, console_width-1,
+ nb_switches / 2, switches);
+ /* attron(attr_error); */
+ addnstr("\\", 1);
+ /* attroff(attr_error); */
+ attroff(attr_focus_line);
} else {
while(k < console_width) {
buffer[k++] = ' ';
}
+ attron(attr_focus_line);
+ print_string_with_switches(buffer, k,
+ nb_switches / 2, switches);
+ attroff(attr_focus_line);
}
- attron(attr_focus_line);
- print_string_with_switches(buffer, k, console_width,
- nb_switches / 2, switches);
- attroff(attr_focus_line);
} else {
if(show_long_lines && k >= console_width) {
- if(console_width >= 4) {
- buffer[console_width - 4] = ' ';
- buffer[console_width - 3] = '.';
- buffer[console_width - 2] = '.';
- buffer[console_width - 1] = '.';
- }
+ print_string_with_switches(buffer, console_width-1,
+ nb_switches / 2, switches);
+ attron(attr_focus_line);
+ addnstr("\\", 1);
+ attroff(attr_focus_line);
} else {
- buffer[k++] = '\n';
- buffer[k++] = '\0';
+ if(k < console_width) {
+ buffer[k++] = '\n';
+ buffer[k++] = '\0';
+ }
+ print_string_with_switches(buffer, k,
+ nb_switches / 2, switches);
}
-
- print_string_with_switches(buffer, k, console_width,
- nb_switches / 2, switches);
}
nb_printed_lines++;
@@ -966,6 +968,7 @@ static struct option long_options[] = {
{ "show-hits", no_argument, 0, 'j'},
{ "upper-case-makes-case-sensitive", no_argument, 0, 'u' },
{ "title", 1, 0, 't' },
+ { "pattern", 1, 0, 'r' },
{ "number-of-lines", 1, 0, 'l' },
{ "colors", 1, 0, 'c' },
{ "bash", no_argument, 0, OPT_BASH_MODE },
@@ -997,6 +1000,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ pattern[0] = '\0';
+
color_fg_modeline = COLOR_WHITE;
color_bg_modeline = COLOR_BLACK;
color_fg_highlight = COLOR_BLACK;
@@ -1006,7 +1011,7 @@ int main(int argc, char **argv) {
strcpy(output_filename, "");
- while ((c = getopt_long(argc, argv, "o:s:x:vwmqf:ibzdeajyunt:l:c:-h",
+ while ((c = getopt_long(argc, argv, "o:s:x:vwmqf:ibzdeajyunt:r:l:c:-h",
long_options, NULL)) != -1) {
switch(c) {
@@ -1081,6 +1086,10 @@ int main(int argc, char **argv) {
strcpy(title, optarg);
break;
+ case 'r':
+ strcpy(pattern, optarg);
+ break;
+
case 'l':
str_to_positive_integers(optarg, &nb_lines_max, 1);
break;
@@ -1199,8 +1208,6 @@ int main(int argc, char **argv) {
*s = '\0';
}
- pattern[0] = '\0';
-
cursor_position = 0;
/* Here we start to display with curse */
@@ -1246,6 +1253,7 @@ int main(int argc, char **argv) {
current_focus_line = 0;
displayed_focus_line = 0;
+ cursor_position = strlen(pattern);
update_screen(¤t_focus_line, &displayed_focus_line,
0,