@@ -1,6 +1,6 @@ | |||
CC=gcc | |||
CFLAGS:=-ggdb | |||
LDLIBS=-I ${CHDRD} $$(pkg-config --libs ncurses) | |||
LDLIBS=-I ${CHDRD} $$(pkg-config --libs ncurses readline) | |||
LEX:=flex | |||
LEXD:=src/ | |||
@@ -136,7 +136,7 @@ command(int commandc) | |||
return(NO); | |||
} | |||
/* if this is a line selection */ | |||
if (p->y1 < FLDLINE) { | |||
if (p->y1 > FLDLINE) { | |||
/* find the selected line */ | |||
/* note: the selection is forced into range */ | |||
@@ -173,6 +173,7 @@ command(int commandc) | |||
case '\n': /* go to reference */ | |||
if (current_window == &wresult) { | |||
editref(curdispline); | |||
window_change = CH_ALL; | |||
return(YES); | |||
} | |||
/* FALLTHROUGH */ | |||
@@ -304,9 +305,10 @@ command(int commandc) | |||
clearprompt(); | |||
shellpath(filename, sizeof(filename), newpat); | |||
if (readrefs(filename) == NO) { | |||
postmsg2("Ignoring an empty file"); | |||
return(NO); | |||
postmsg2("Ignoring an empty file"); | |||
return(NO); | |||
} | |||
window_change |= CH_INPUT; | |||
return(YES); | |||
} | |||
clearprompt(); | |||
@@ -499,6 +501,7 @@ cscope: cannot open pipe to shell command: %s\n", newpat); | |||
return(NO); | |||
} | |||
} /* switch(commandc) */ | |||
window_change |= CH_INPUT; | |||
return(YES); | |||
} | |||
@@ -85,7 +85,6 @@ | |||
#define FLDLINE (LINES - FIELDS - 1 - 1) /* first input field line */ | |||
#define MSGLINE 0 /* message line */ | |||
#define PRLINE (LINES - 1) /* input prompt line */ | |||
#define REFLINE 3 /* first displayed reference line */ | |||
/* input fields (value matches field order on screen) */ | |||
#define SYMBOL 0 | |||
@@ -85,12 +85,7 @@ static int mode_window_height; | |||
#define WRESULT_TABLE_BODY_START 4 | |||
static enum { | |||
CH_RESULT = 0x0001, | |||
CH_INPUT = CH_RESULT << 1, | |||
CH_MODE = CH_RESULT << 2, | |||
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE | |||
}; | |||
int window_change = CH_ALL; | |||
const char dispchars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |||
@@ -143,7 +138,7 @@ dispinit(void) | |||
mode_window_height = LINES - input_window_height - 2 - 1; | |||
first_col_width = 48; // (((COLS - 2)%2 == 0) ? ((COLS-2)/2) : (((COLS-2)/2)+1)); | |||
second_col_width = COLS - 2 - 1 - first_col_width; //((COLS - 2) / 2) - 1; | |||
mdisprefs = result_window_height - 1; | |||
mdisprefs = result_window_height - WRESULT_TABLE_BODY_START - 1 - 1; | |||
if (mdisprefs <= 0) { | |||
postfatal("%s: screen too small\n", argv0); | |||
@@ -156,6 +151,9 @@ dispinit(void) | |||
/* allocate the displayed line array */ | |||
displine = malloc(mdisprefs * sizeof(*displine)); | |||
/* readline */ | |||
rlinit(); | |||
/* initialize windows */ | |||
winput = newwin(input_window_height, first_col_width, 1, 1); | |||
wmode = newwin(mode_window_height, first_col_width, input_window_height+1 + 1, 1); | |||
@@ -197,7 +195,7 @@ static inline void display_frame(){ | |||
waddstr(stdscr, helpstring); | |||
} | |||
static inline void display_input_fields(){ | |||
static inline void display_mode(){ | |||
for(int i = 0; i < FIELDS; ++i){ | |||
mvwprintw(wmode, i, 0, "%s %s", fields[i].text1, fields[i].text2); | |||
} | |||
@@ -271,7 +269,7 @@ static inline void display_results(){ | |||
/* until the max references have been displayed or | |||
there is no more room */ | |||
topline = nextline; | |||
for (disprefs = 0, screenline = REFLINE; | |||
for (disprefs = 0, screenline = WRESULT_TABLE_BODY_START; | |||
disprefs < mdisprefs && screenline <= result_window_height; | |||
++disprefs, ++screenline) | |||
{ | |||
@@ -392,9 +390,10 @@ static inline void display_results(){ | |||
wmove(wresult, screenline, second_col_width - srctxtw); | |||
} /* for(ever) */ | |||
} /* for(reference output lines) */ | |||
endrefs: | |||
endrefs: | |||
/* position the cursor for the message */ | |||
i = FLDLINE - 1; | |||
i = result_window_height - 1; | |||
if (screenline < i) { | |||
waddch(wresult, '\n'); | |||
} | |||
@@ -408,7 +407,7 @@ static inline void display_results(){ | |||
wprintw(wresult, "* Lines %d-%d of %d, %d more - press the space bar to display more *", topline, bottomline, totallines, i); | |||
} | |||
/* if this is the last page of references */ | |||
else if (topline > 1 && nextline > totallines) { | |||
else{ //if (topline > 1 && nextline > totallines) { //XXX: i dont see how this condition is ever userful, but i might be wrong | |||
waddstr(wresult, "* Press the space bar to display the first lines again *"); | |||
} | |||
} | |||
@@ -422,7 +421,7 @@ void display_cursor(void){ | |||
}else if(current_window == &wmode){ | |||
yoffset = field; | |||
}else if(current_window == &wresult){ | |||
yoffset = WRESULT_TABLE_BODY_START + curdispline; | |||
yoffset = displine[curdispline]; | |||
}else{ | |||
assert(("No window selected.", true)); | |||
} | |||
@@ -439,17 +438,29 @@ display(void) | |||
{ | |||
//drawscrollbar(topline, nextline); /* display the scrollbar */ | |||
display_frame(); | |||
display_command_field(); | |||
display_input_fields(); | |||
display_results(); | |||
if(window_change){ | |||
if(window_change & CH_ALL){ | |||
display_frame(); | |||
} | |||
if(window_change & CH_INPUT){ | |||
display_command_field(); | |||
} | |||
if(window_change & CH_RESULT){ | |||
display_results(); | |||
} | |||
if(window_change & CH_MODE){ | |||
display_mode(); | |||
} | |||
display_cursor(); | |||
display_cursor(); | |||
refresh(); | |||
wrefresh(winput); | |||
wrefresh(wmode); | |||
wrefresh(wresult); | |||
} | |||
refresh(); | |||
wrefresh(winput); | |||
wrefresh(wmode); | |||
wrefresh(wresult); | |||
window_change = CH_NONE; | |||
} | |||
void | |||
@@ -709,7 +720,7 @@ postmsg2(char *msg) | |||
else { | |||
clearmsg2(); | |||
waddstr(wresult, msg); | |||
refresh(); | |||
wrefresh(wresult); | |||
} | |||
} | |||
@@ -84,6 +84,15 @@ struct cmd { /* command history struct */ | |||
char *text; /* input field text */ | |||
}; | |||
enum { | |||
CH_NONE = 0x0000, | |||
CH_RESULT = 0x0001 << 0, | |||
CH_INPUT = 0x0001 << 1, | |||
CH_MODE = 0x0001 << 2, | |||
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE | |||
}; | |||
#ifndef DFLT_INCDIR | |||
# define DFLT_INCDIR "/usr/include" | |||
@@ -181,6 +190,7 @@ extern unsigned int topline; /* top line of page */ | |||
extern long searchcount; /* count of files searched */ | |||
extern unsigned int totallines; /* total reference lines */ | |||
extern const char dispchars[]; /* display chars for jumping to lines */ | |||
extern int window_change; | |||
/* find.c global data */ | |||
extern char block[]; /* cross-reference file block */ | |||
@@ -199,6 +209,10 @@ extern struct keystruct { | |||
/* mouse.c global data */ | |||
extern BOOL mouse; /* mouse interface */ | |||
/* display.c global data */ | |||
extern int input_available; | |||
extern char input_char; | |||
#if UNIXPC | |||
extern BOOL unixpcmouse; /* UNIX PC mouse interface */ | |||
#endif | |||
@@ -232,6 +246,8 @@ extern char *reflines; /* symbol reference lines file */ | |||
void verswp_field(void); | |||
void horswp_field(void); | |||
void rlinit(void); | |||
void addcmd(int f, char *s); | |||
void addsrcfile(char *path); | |||
void askforchar(void); | |||
@@ -56,12 +56,9 @@ static void catchint(int sig); | |||
/* catch the interrupt signal */ | |||
/*ARGSUSED*/ | |||
static void | |||
catchint(int sig) | |||
{ | |||
(void) sig; /* 'use' it, to avoid a warning */ | |||
signal(SIGINT, catchint); | |||
longjmp(env, 1); | |||
} | |||
@@ -681,6 +681,8 @@ static inline void screenmode_event_loop(void){ | |||
display(); | |||
c = mygetch(); | |||
input_available = 1; | |||
rl_callback_read_char(); | |||
/* exit if the quit command is entered */ | |||
if (c == EOF || c == ctrl('D')) { | |||
@@ -691,6 +693,5 @@ static inline void screenmode_event_loop(void){ | |||
continue; | |||
} | |||
command(c); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
#include <readline/readline.h> | |||
#include "global.h" | |||
int input_available = 0; | |||
char input_char; | |||
static void getc_function(FILE* ignore){ | |||
input_available = 0; | |||
return (int)input_char; | |||
} | |||
static input_available_hook(){ | |||
return input_available; | |||
} | |||
static void redisplay_function(){ | |||
window_change |= CH_INPUT; | |||
//display(); | |||
} | |||
static void callback_handler(char* line){ | |||
// ?! | |||
} | |||
int proxy(int i, int h){ | |||
horswp_field(); | |||
} | |||
void rlinit(){ | |||
rl_catch_signals = 0; | |||
rl_catch_sigwinch = 0; | |||
rl_prep_term_function = NULL; | |||
rl_deprep_term_function = NULL; | |||
rl_change_environment = 0; | |||
rl_getc_function = getc_function; | |||
rl_input_available_hook = input_available_hook; | |||
rl_redisplay_function = redisplay_function; | |||
rl_callback_handler_install("", callback_handler); | |||
rl_bind_key('\t', proxy); | |||
} |