From 6249b7076f9145772cd7f4b5d16fc2d0fd06564b Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 28 Jan 2014 19:56:34 +1000 Subject: Move the per loop stuff into the do command stuff. Much saner. --- boxes.c | 57 +++++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/boxes.c b/boxes.c index 8a25798..c0a3131 100644 --- a/boxes.c +++ b/boxes.c @@ -1783,28 +1783,6 @@ void nop(box *box, event *event) } -static struct keyCommand *lineLoop(long extra) -{ - struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. - int y, len; - - // Coz things might change out from under us, find the current view. - if (commandMode) view = commandLine; - else view = currentBox->view; - // Draw the prompt and the current line. - y = view->Y + (view->cY - view->offsetY); - len = strlen(view->prompt); - drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0); - drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1); - // Move the cursor. - printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1); - fflush(stdout); - - // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate. - // More importantly, the currentBox may change due to a command. - return currentBox->view->content->context->modes[currentBox->view->mode].keys; -} - static void lineChar(long extra, char *buffer) { struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. @@ -1812,22 +1790,41 @@ static void lineChar(long extra, char *buffer) // Coz things might change out from under us, find the current view. if (commandMode) view = commandLine; else view = currentBox->view; + // TODO - Should check for tabs to, and insert them. // Though better off having a function for that? - // TODO - see if I can get these out of here. Some sort of pushCharacter(buffer, blob) that is passed in. mooshStrings(view->line, buffer, view->iX, 0, !TT.overWriteMode); view->oW = formatLine(view, view->line->line, &(view->output)); moveCursorRelative(view, strlen(buffer), 0, 0, 0); } -static void lineCommand(long extra, char *command, event *event) +// TODO - should merge this and the real one. Note that when doing scripts and such, might want to turn off the line update until finished. +static struct keyCommand * lineCommand(long extra, char *command, event *event) { struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. + int y, len; // Coz things might change out from under us, find the current view. if (commandMode) view = commandLine; else view = currentBox->view; + doCommand(view->content->context->commands, command, view, event); + + // Coz things might change out from under us, find the current view. Again + if (commandMode) view = commandLine; + else view = currentBox->view; + + // Draw the prompt and the current line. + y = view->Y + (view->cY - view->offsetY); + len = strlen(view->prompt); + drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0); + drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1); + // Move the cursor. + printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1); + fflush(stdout); + + // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate. + return currentBox->view->content->context->modes[currentBox->view->mode].keys; } // Basically this is the main loop. @@ -1846,9 +1843,11 @@ The response from a terminal size check command includes a prefix, a suffix, wit Mouse events are likely similar. */ -void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lineChar)(long extra, char *buffer), void (*lineCommand)(long extra, char *command, event *event)) +void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command, event *event)) { struct pollfd pollfds[1]; + // Get the initial command set, and trigger the first cursor move. + struct keyCommand *ourKeys = lineCommand(extra, "", NULL); char buffer[20]; char command[20]; int pollcount = 1; @@ -1866,9 +1865,6 @@ void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lin { int j, p; char *found = NULL; - // We do this coz the command set might change out from under us in response to commands. - // So lineLoop should return the current command set if nothing else. - struct keyCommand *ourKeys = lineLoop(extra); // Apparently it's more portable to reset this each time. memset(pollfds, 0, pollcount * sizeof(struct pollfd)); @@ -1876,6 +1872,7 @@ void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lin pollfds[0].fd = 0; // TODO - A bit unstable at the moment, something makes it go into a horrid CPU eating edit line flicker mode sometimes. And / or vi mode can crash on exit (stack smash). +// This might be fixed now. // TODO - Should only ask for a time out after we get an Escape. p = poll(pollfds, pollcount, 100); // Timeout of one tenth of a second (100). @@ -1988,7 +1985,7 @@ void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lin if (found) { // That last argument, an event pointer, should be the original raw keystrokes, though by this time that's been cleared. - lineCommand(extra, found, NULL); + ourKeys = lineCommand(extra, found, NULL); command[0] = 0; } } @@ -2733,7 +2730,7 @@ void boxes_main(void) drawBoxes(currentBox); // Run the main loop. - editLine((long) currentBox->view, lineLoop, lineChar, lineCommand); + editLine((long) currentBox->view, lineChar, lineCommand); // TODO - Should remember to turn off mouse reporting when we leave. -- cgit v1.1