projects
/
selector.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Automatic commit
[selector.git]
/
selector.cc
diff --git
a/selector.cc
b/selector.cc
index
7a79979
..
0878f82
100644
(file)
--- a/
selector.cc
+++ b/
selector.cc
@@
-31,13
+31,15
@@
using namespace std;
const int buffer_size = 1024;
const int nb_lines_max = 100000;
const int buffer_size = 1024;
const int nb_lines_max = 100000;
-
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char *regexp
) {
+
int refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, char *regexp, int noblink
) {
char buffer[buffer_size];
int maxx = getmaxx(stdscr);
int maxy = min(buffer_size-2, getmaxy(stdscr));
char buffer[buffer_size];
int maxx = getmaxx(stdscr);
int maxy = min(buffer_size-2, getmaxy(stdscr));
- // clear(); // Cleaning the window
+ if(!noblink) {
+ clear();
+ }
use_default_colors();
use_default_colors();
@@
-45,6
+47,7
@@
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char
int nb_printed_lines = 1, last_printer_line = -1;
int y = 0;
int nb_printed_lines = 1, last_printer_line = -1;
int y = 0;
+ int current_line = -1;
while(nb_printed_lines < maxy && y < nb_lines) {
if(strstr(lines[y], regexp) &&
while(nb_printed_lines < maxy && y < nb_lines) {
if(strstr(lines[y], regexp) &&
@@
-56,8
+59,10
@@
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char
k++;
}
k++;
}
- while(k < maxx - 1) {
- buffer[k++] = ' ';
+ if(noblink) {
+ while(k < maxx - 1) {
+ buffer[k++] = ' ';
+ }
}
buffer[k++] = '\n';
buffer[k++] = '\0';
}
buffer[k++] = '\n';
buffer[k++] = '\0';
@@
-66,6
+71,7
@@
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char
attron(COLOR_PAIR(2));
printw(buffer);
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(2));
printw(buffer);
attroff(COLOR_PAIR(2));
+ current_line = y;
} else {
printw(buffer);
}
} else {
printw(buffer);
}
@@
-76,7
+82,7
@@
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char
y++;
}
y++;
}
- { // Erase the rest of the window. That's slightly ugly.
+
if(noblink)
{ // Erase the rest of the window. That's slightly ugly.
int k = 0;
while(k < maxx - 1) {
buffer[k++] = ' ';
int k = 0;
while(k < maxx - 1) {
buffer[k++] = ' ';
@@
-99,11
+105,14
@@
void build_display(int *screen_line, int *line, int nb_lines, char **lines, char
attroff(COLOR_PAIR(1));
refresh(); // After doing something on the display, we refresh it
attroff(COLOR_PAIR(1));
refresh(); // After doing something on the display, we refresh it
+
+ return current_line;
}
int main(int argc, char **argv) {
char buffer[buffer_size];
char *lines[nb_lines_max];
}
int main(int argc, char **argv) {
char buffer[buffer_size];
char *lines[nb_lines_max];
+ int noblink = 1;
char *file_name;
char stdin_name[] = "/dev/stdin";
char *file_name;
char stdin_name[] = "/dev/stdin";
@@
-152,7
+161,9
@@
int main(int argc, char **argv) {
int line = 0, screen_line = 0;
int line = 0, screen_line = 0;
- build_display(&screen_line, &line, nb_lines, lines, regexp);
+ refresh_screen(&screen_line, &line, nb_lines, lines, regexp, noblink);
+
+ int current_line = -1;
do {
do {
@@
-180,13
+191,17
@@
int main(int argc, char **argv) {
line++;
}
line++;
}
-
build_display(&screen_line, &line, nb_lines, lines, regexp
);
+
current_line = refresh_screen(&screen_line, &line, nb_lines, lines, regexp, noblink
);
} while(key != '\n' && key != KEY_ENTER && key != '
\a
');
echo();
curs_set(1);
endwin();
} while(key != '\n' && key != KEY_ENTER && key != '
\a
');
echo();
curs_set(1);
endwin();
+ ofstream out("/tmp/selector.out");
+ out << lines[current_line] << endl;
+ out.flush();
+
for(int l = 0; l < nb_lines; l++) {
delete[] lines[l];
}
for(int l = 0; l < nb_lines; l++) {
delete[] lines[l];
}