diff options
| author | David Walter Seikel | 2014-01-28 22:57:53 +1000 |
|---|---|---|
| committer | David Walter Seikel | 2014-01-28 22:57:53 +1000 |
| commit | 34595e01e980bbd353e885b172142f0f2b8f642d (patch) | |
| tree | 5f7a453feb1c0ba5ba8ffbef07d358bce9f49c7b | |
| parent | Reorganise doCommand() and friends a bit. (diff) | |
| download | boxes-34595e01e980bbd353e885b172142f0f2b8f642d.zip boxes-34595e01e980bbd353e885b172142f0f2b8f642d.tar.gz boxes-34595e01e980bbd353e885b172142f0f2b8f642d.tar.bz2 boxes-34595e01e980bbd353e885b172142f0f2b8f642d.tar.xz | |
Split out the line updating to it's own function.
Diffstat (limited to '')
| -rw-r--r-- | boxes.c | 43 |
1 files changed, 25 insertions, 18 deletions
| @@ -1068,6 +1068,25 @@ void drawContentLine(view *view, int y, int start, int end, char *left, char *in | |||
| 1068 | drawLine(y, start, end, left, internal, &(temp[offset]), right, current); | 1068 | drawLine(y, start, end, left, internal, &(temp[offset]), right, current); |
| 1069 | } | 1069 | } |
| 1070 | 1070 | ||
| 1071 | void updateLine(view *view) | ||
| 1072 | { | ||
| 1073 | int y, len; | ||
| 1074 | |||
| 1075 | // Coz things might change out from under us, find the current view. Again. | ||
| 1076 | if (commandMode) view = commandLine; | ||
| 1077 | else view = currentBox->view; | ||
| 1078 | |||
| 1079 | // TODO - When doing scripts and such, might want to turn off the line update until finished. | ||
| 1080 | // Draw the prompt and the current line. | ||
| 1081 | y = view->Y + (view->cY - view->offsetY); | ||
| 1082 | len = strlen(view->prompt); | ||
| 1083 | drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0); | ||
| 1084 | drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1); | ||
| 1085 | // Move the cursor. | ||
| 1086 | printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1); | ||
| 1087 | fflush(stdout); | ||
| 1088 | } | ||
| 1089 | |||
| 1071 | void doCommand(view *view, char *command) | 1090 | void doCommand(view *view, char *command) |
| 1072 | { | 1091 | { |
| 1073 | if (command) | 1092 | if (command) |
| @@ -1081,23 +1100,8 @@ void doCommand(view *view, char *command) | |||
| 1081 | { | 1100 | { |
| 1082 | if (functions[i].handler); | 1101 | if (functions[i].handler); |
| 1083 | { | 1102 | { |
| 1084 | int y, len; | ||
| 1085 | |||
| 1086 | functions[i].handler(view); | 1103 | functions[i].handler(view); |
| 1087 | 1104 | updateLine(view); | |
| 1088 | // Coz things might change out from under us, find the current view. Again. | ||
| 1089 | if (commandMode) view = commandLine; | ||
| 1090 | else view = currentBox->view; | ||
| 1091 | |||
| 1092 | // TODO - When doing scripts and such, might want to turn off the line update until finished. | ||
| 1093 | // Draw the prompt and the current line. | ||
| 1094 | y = view->Y + (view->cY - view->offsetY); | ||
| 1095 | len = strlen(view->prompt); | ||
| 1096 | drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0); | ||
| 1097 | drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1); | ||
| 1098 | // Move the cursor. | ||
| 1099 | printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1); | ||
| 1100 | fflush(stdout); | ||
| 1101 | } | 1105 | } |
| 1102 | break; | 1106 | break; |
| 1103 | } | 1107 | } |
| @@ -1795,6 +1799,7 @@ static void lineChar(long extra, char *buffer) | |||
| 1795 | mooshStrings(view->line, buffer, view->iX, 0, !TT.overWriteMode); | 1799 | mooshStrings(view->line, buffer, view->iX, 0, !TT.overWriteMode); |
| 1796 | view->oW = formatLine(view, view->line->line, &(view->output)); | 1800 | view->oW = formatLine(view, view->line->line, &(view->output)); |
| 1797 | moveCursorRelative(view, strlen(buffer), 0, 0, 0); | 1801 | moveCursorRelative(view, strlen(buffer), 0, 0, 0); |
| 1802 | updateLine(view); | ||
| 1798 | } | 1803 | } |
| 1799 | 1804 | ||
| 1800 | static struct keyCommand * lineCommand(long extra, char *command) | 1805 | static struct keyCommand * lineCommand(long extra, char *command) |
| @@ -1830,8 +1835,8 @@ The response from a terminal size check command includes a prefix, a suffix, wit | |||
| 1830 | void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command)) | 1835 | void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command)) |
| 1831 | { | 1836 | { |
| 1832 | struct pollfd pollfds[1]; | 1837 | struct pollfd pollfds[1]; |
| 1833 | // Get the initial command set, and trigger the first cursor move. Assumes the command set has a nop that otherwise does nothing. | 1838 | // Get the initial command set. |
| 1834 | struct keyCommand *ourKeys = lineCommand(extra, "nop"); | 1839 | struct keyCommand *ourKeys = lineCommand(extra, ""); |
| 1835 | char buffer[20]; | 1840 | char buffer[20]; |
| 1836 | char command[20]; | 1841 | char command[20]; |
| 1837 | int pollcount = 1; | 1842 | int pollcount = 1; |
| @@ -2717,6 +2722,8 @@ void boxes_main(void) | |||
| 2717 | 2722 | ||
| 2718 | calcBoxes(currentBox); | 2723 | calcBoxes(currentBox); |
| 2719 | drawBoxes(currentBox); | 2724 | drawBoxes(currentBox); |
| 2725 | // Do the first cursor update. | ||
| 2726 | updateLine(currentBox->view); | ||
| 2720 | 2727 | ||
| 2721 | // Run the main loop. | 2728 | // Run the main loop. |
| 2722 | editLine((long) currentBox->view, lineChar, lineCommand); | 2729 | editLine((long) currentBox->view, lineChar, lineCommand); |
