This commit is contained in:
anon 2023-08-16 12:14:09 +02:00
parent ea6f464ad6
commit 125826ac1a
5 changed files with 48 additions and 45 deletions

View File

@ -106,6 +106,7 @@ All can be configured sucklessly under "config/colors.h". Hopefully the comments
| int window_change | Bit mask type of the CH_\* macros. Keeps track of the windows to be refresed on the next run of display(). Could be better utalized. | int window_change | Bit mask type of the CH_\* macros. Keeps track of the windows to be refresed on the next run of display(). Could be better utalized.
# TODO /*move soon*/ # TODO /*move soon*/
1. create a step in the mean loop where the cursor us forced into the right window based on mode
+ sort out constants.h + sort out constants.h
+ scrollbar() uses magic int literals? + scrollbar() uses magic int literals?
+ lineflagafterfile is stupid + lineflagafterfile is stupid
@ -125,6 +126,7 @@ All can be configured sucklessly under "config/colors.h". Hopefully the comments
Aborted Aborted
+ Changing text can crash without replacing text and leaving the console ncursed + Changing text can crash without replacing text and leaving the console ncursed
+ After an attempted change malloc *can* cry and crash + After an attempted change malloc *can* cry and crash
+ Changing text fucks up redisplaying
# Future features / contributor wishlist # Future features / contributor wishlist
+ providing support for other languages by integrating new lexers (e.g. ctag's) + providing support for other languages by integrating new lexers (e.g. ctag's)

View File

@ -77,7 +77,7 @@ const char *prompts[] = {[INPUT_NORMAL] = "$ ",
[INPUT_PIPE] = "Pipe to shell command: ", [INPUT_PIPE] = "Pipe to shell command: ",
[INPUT_READ] = "Read from file: ", [INPUT_READ] = "Read from file: ",
[INPUT_CHANGE_TO] = "To: ", [INPUT_CHANGE_TO] = "To: ",
[INPUT_CHANGE] = "To: "}; [INPUT_CHANGE] = "###"};
unsigned int topline = 1; /* top line of page */ unsigned int topline = 1; /* top line of page */
@ -614,7 +614,7 @@ static inline void display_cursor(void) {
waddch(*current_window, i); waddch(*current_window, i);
} }
void horswp_field(void) { void horswp_window(void) {
if(input_mode != INPUT_NORMAL){ return; } if(input_mode != INPUT_NORMAL){ return; }
if(current_window != &wresult) { if(current_window != &wresult) {
@ -634,7 +634,7 @@ void horswp_field(void) {
window_change |= CH_RESULT; window_change |= CH_RESULT;
} }
void verswp_field(void) { void verswp_window(void) {
if(current_window == &wresult) { return; } if(current_window == &wresult) { return; }
current_window = (current_window == &winput) ? &wmode : &winput; current_window = (current_window == &winput) ? &wmode : &winput;
window_change |= CH_INPUT | CH_MODE; window_change |= CH_INPUT | CH_MODE;

View File

@ -75,6 +75,8 @@ struct cmd { /* command history struct */
char *text; /* input field text */ char *text; /* input field text */
}; };
/* bitmask type to mark which windows have to be rerendered by
display() */
enum { enum {
CH_NONE = 0x0000, CH_NONE = 0x0000,
CH_RESULT = 0x0001 << 0, CH_RESULT = 0x0001 << 0,
@ -84,6 +86,7 @@ enum {
CH_HELP = 0x0001 << 4, /* do NOT add to CH_ALL */ CH_HELP = 0x0001 << 4, /* do NOT add to CH_ALL */
CH_ALL = CH_RESULT | CH_INPUT | CH_MODE | CH_CASE CH_ALL = CH_RESULT | CH_INPUT | CH_MODE | CH_CASE
}; };
extern int window_change;
enum { enum {
INPUT_NORMAL, INPUT_NORMAL,
@ -93,6 +96,7 @@ enum {
INPUT_CHANGE_TO, INPUT_CHANGE_TO,
INPUT_CHANGE INPUT_CHANGE
}; };
extern int input_mode;
#ifndef DFLT_INCDIR #ifndef DFLT_INCDIR
# define DFLT_INCDIR "/usr/include" # define DFLT_INCDIR "/usr/include"
@ -181,8 +185,6 @@ extern unsigned int mdisprefs; /* maximum displayed references */
extern unsigned int nextline; /* next line to be shown */ extern unsigned int nextline; /* next line to be shown */
extern long searchcount; /* count of files searched */ extern long searchcount; /* count of files searched */
extern unsigned int totallines; /* total reference lines */ extern unsigned int totallines; /* total reference lines */
extern int window_change; /* bitmask type to mark which windows have to be rerendered by
display() */
/* find.c global data */ /* find.c global data */
extern char block[]; /* cross-reference file block */ extern char block[]; /* cross-reference file block */
@ -237,13 +239,12 @@ extern char *reflines; /* symbol reference lines file */
extern bool do_press_any_key; /* wait for any key to continue */ extern bool do_press_any_key; /* wait for any key to continue */
extern int current_page; extern int current_page;
#define topref (current_page * mdisprefs) #define topref (current_page * mdisprefs)
void verswp_field(void); void horswp_window(void);
void horswp_field(void); void verswp_window(void);
bool interpret(int c); // XXX: probably rename bool interpret(int c); // XXX: probably rename
int handle_input(const int c); int handle_input(const int c);
int dispchar2int(const char c); int dispchar2int(const char c);
int process_mouse(); int process_mouse();
extern int input_mode;
int changestring(const char *from, const char *to, const bool *const change, int changestring(const char *from, const char *to, const bool *const change,
const int change_len); const int change_len);

View File

@ -46,6 +46,11 @@
#include "keys.h" #include "keys.h"
extern const void *const winput;
extern const void *const wmode;
extern const void *const wresult;
extern const void *const *const current_window;
bool do_press_any_key = false; bool do_press_any_key = false;
static jmp_buf env; /* setjmp/longjmp buffer */ static jmp_buf env; /* setjmp/longjmp buffer */
@ -219,10 +224,10 @@ noredisp:
static int global_input(const int c) { static int global_input(const int c) {
switch(c) { switch(c) {
case '\t': case '\t':
horswp_field(); horswp_window();
break; break;
case '%': case '%':
verswp_field(); verswp_window();
break; break;
case ctrl('K'): case ctrl('K'):
field = (field + (FIELDS - 1)) % FIELDS; field = (field + (FIELDS - 1)) % FIELDS;
@ -251,32 +256,14 @@ static int global_input(const int c) {
window_change |= CH_RESULT; window_change |= CH_RESULT;
break; break;
case '>': /* write or append the lines to a file */ case '>': /* write or append the lines to a file */
break; // XXX if (totallines == 0) {
// char filename[PATHLEN + 1]; postmsg("There are no lines to write to a file");
// char* s; break;
// char ch; }
// FILE* file; if(*current_window == wresult){ horswp_window(); }
// if (totallines == 0) { if(*current_window == wmode){ verswp_window(); }
// postmsg("There are no lines to write to a file"); input_mode = INPUT_APPEND;
// return(NO); window_change |= CH_INPUT;
// }
// move(PRLINE, 0);
////addstr("Write to file: "); // XXX
// s = "w";
// if ((ch = getch()) == '>') {
// move(PRLINE, 0);
////addstr(appendprompt); // XXX fix
////ch = '\0';
////s = "a";
////}
////if (ch != '\r' && mygetline("", newpat, COLS - sizeof(appendprompt), c,
///NO) > 0) { / shellpath(filename, sizeof(filename), newpat); / if
///((file = myfopen(filename, s)) == NULL) { / cannotopen(filename); /
///} else { / seekline(1); / while ((ch = getc(refsfound)) !=
///EOF) { / putc(ch, file); / } / seekline(topline); /
///fclose(file); / }
////}
////clearprompt();
break; break;
case '<': /* read lines from a file */ case '<': /* read lines from a file */
break; // XXX break; // XXX
@ -369,11 +356,6 @@ static int global_input(const int c) {
return 1; return 1;
} }
extern const void *const winput;
extern const void *const wmode;
extern const void *const wresult;
extern const void *const *const current_window;
int change_input(const int c) { int change_input(const int c) {
MOUSE *p; /* mouse data */ MOUSE *p; /* mouse data */
@ -412,7 +394,7 @@ int change_input(const int c) {
case ctrl('D'): case ctrl('D'):
changestring(input_line, newpat, change, totallines); changestring(input_line, newpat, change, totallines);
input_mode = INPUT_NORMAL; input_mode = INPUT_NORMAL;
horswp_field(); horswp_window();
search(newpat); search(newpat);
break; break;
default: default:
@ -426,6 +408,8 @@ int change_input(const int c) {
} }
} }
input_mode = INPUT_NORMAL;
return 0; return 0;
} }
@ -538,6 +522,7 @@ int handle_input(const int c) {
assert("'current_window' dangling."); assert("'current_window' dangling.");
break; /* NOTREACHED */ break; /* NOTREACHED */
case INPUT_CHANGE_TO: case INPUT_CHANGE_TO:
case INPUT_APPEND:
return interpret(c); return interpret(c);
case INPUT_CHANGE: case INPUT_CHANGE:
return change_input(c); return change_input(c);

View File

@ -80,7 +80,7 @@ static void redisplay_function() {
} }
static void callback_handler(char *line) { static void callback_handler(char *line) {
if(!line) { return; } if(!line) { return; } // XXX; should behave differently with different modes
add_history(line); add_history(line);
@ -88,7 +88,7 @@ static void callback_handler(char *line) {
case INPUT_NORMAL: case INPUT_NORMAL:
strncpy(input_line, line, PATLEN); strncpy(input_line, line, PATLEN);
search(input_line); search(input_line);
horswp_field(); horswp_window();
curdispline = 0; curdispline = 0;
current_page = 0; current_page = 0;
PCS_reset(); PCS_reset();
@ -97,12 +97,27 @@ static void callback_handler(char *line) {
strncpy(newpat, line, PATLEN); strncpy(newpat, line, PATLEN);
change = calloc(totallines, sizeof(*change)); change = calloc(totallines, sizeof(*change));
input_mode = INPUT_CHANGE; input_mode = INPUT_CHANGE;
horswp_field(); horswp_window();
return; return;
case INPUT_APPEND: {
char filename[PATHLEN + 1];
FILE* file;
char ch;
shellpath(filename, sizeof(filename), line);
file = fopen(filename, "a+");
seekpage(0);
while ((ch = getc(refsfound)) != EOF) {
putc(ch, file);
}
fclose(file);
input_mode = INPUT_NORMAL;
return;
}
} }
switch(field) { switch(field) {
case CHANGE: case CHANGE:
if(totallines == 0){ return; }
input_mode = INPUT_CHANGE_TO; input_mode = INPUT_CHANGE_TO;
break; break;
case DEFINITION: case DEFINITION: