aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--boxes.c57
1 files 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)
1783} 1783}
1784 1784
1785 1785
1786static struct keyCommand *lineLoop(long extra)
1787{
1788 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away.
1789 int y, len;
1790
1791 // Coz things might change out from under us, find the current view.
1792 if (commandMode) view = commandLine;
1793 else view = currentBox->view;
1794 // Draw the prompt and the current line.
1795 y = view->Y + (view->cY - view->offsetY);
1796 len = strlen(view->prompt);
1797 drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0);
1798 drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1);
1799 // Move the cursor.
1800 printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1);
1801 fflush(stdout);
1802
1803 // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate.
1804 // More importantly, the currentBox may change due to a command.
1805 return currentBox->view->content->context->modes[currentBox->view->mode].keys;
1806}
1807
1808static void lineChar(long extra, char *buffer) 1786static void lineChar(long extra, char *buffer)
1809{ 1787{
1810 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. 1788 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)
1812 // Coz things might change out from under us, find the current view. 1790 // Coz things might change out from under us, find the current view.
1813 if (commandMode) view = commandLine; 1791 if (commandMode) view = commandLine;
1814 else view = currentBox->view; 1792 else view = currentBox->view;
1793
1815 // TODO - Should check for tabs to, and insert them. 1794 // TODO - Should check for tabs to, and insert them.
1816 // Though better off having a function for that? 1795 // Though better off having a function for that?
1817 // TODO - see if I can get these out of here. Some sort of pushCharacter(buffer, blob) that is passed in.
1818 mooshStrings(view->line, buffer, view->iX, 0, !TT.overWriteMode); 1796 mooshStrings(view->line, buffer, view->iX, 0, !TT.overWriteMode);
1819 view->oW = formatLine(view, view->line->line, &(view->output)); 1797 view->oW = formatLine(view, view->line->line, &(view->output));
1820 moveCursorRelative(view, strlen(buffer), 0, 0, 0); 1798 moveCursorRelative(view, strlen(buffer), 0, 0, 0);
1821} 1799}
1822 1800
1823static void lineCommand(long extra, char *command, event *event) 1801// 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.
1802static struct keyCommand * lineCommand(long extra, char *command, event *event)
1824{ 1803{
1825 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. 1804 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away.
1805 int y, len;
1826 1806
1827 // Coz things might change out from under us, find the current view. 1807 // Coz things might change out from under us, find the current view.
1828 if (commandMode) view = commandLine; 1808 if (commandMode) view = commandLine;
1829 else view = currentBox->view; 1809 else view = currentBox->view;
1810
1830 doCommand(view->content->context->commands, command, view, event); 1811 doCommand(view->content->context->commands, command, view, event);
1812
1813 // Coz things might change out from under us, find the current view. Again
1814 if (commandMode) view = commandLine;
1815 else view = currentBox->view;
1816
1817 // Draw the prompt and the current line.
1818 y = view->Y + (view->cY - view->offsetY);
1819 len = strlen(view->prompt);
1820 drawLine(y, view->X, view->X + view->W, "", " ", view->prompt, "", 0);
1821 drawContentLine(view, y, view->X + len, view->X + view->W, "", " ", view->line->line, "", 1);
1822 // Move the cursor.
1823 printf("\x1B[%d;%dH", y + 1, view->X + len + (view->cX - view->offsetX) + 1);
1824 fflush(stdout);
1825
1826 // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate.
1827 return currentBox->view->content->context->modes[currentBox->view->mode].keys;
1831} 1828}
1832 1829
1833// Basically this is the main loop. 1830// Basically this is the main loop.
@@ -1846,9 +1843,11 @@ The response from a terminal size check command includes a prefix, a suffix, wit
1846 1843
1847 Mouse events are likely similar. 1844 Mouse events are likely similar.
1848*/ 1845*/
1849void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lineChar)(long extra, char *buffer), void (*lineCommand)(long extra, char *command, event *event)) 1846void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command, event *event))
1850{ 1847{
1851 struct pollfd pollfds[1]; 1848 struct pollfd pollfds[1];
1849 // Get the initial command set, and trigger the first cursor move.
1850 struct keyCommand *ourKeys = lineCommand(extra, "", NULL);
1852 char buffer[20]; 1851 char buffer[20];
1853 char command[20]; 1852 char command[20];
1854 int pollcount = 1; 1853 int pollcount = 1;
@@ -1866,9 +1865,6 @@ void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lin
1866 { 1865 {
1867 int j, p; 1866 int j, p;
1868 char *found = NULL; 1867 char *found = NULL;
1869 // We do this coz the command set might change out from under us in response to commands.
1870 // So lineLoop should return the current command set if nothing else.
1871 struct keyCommand *ourKeys = lineLoop(extra);
1872 1868
1873 // Apparently it's more portable to reset this each time. 1869 // Apparently it's more portable to reset this each time.
1874 memset(pollfds, 0, pollcount * sizeof(struct pollfd)); 1870 memset(pollfds, 0, pollcount * sizeof(struct pollfd));
@@ -1876,6 +1872,7 @@ void editLine(long extra, struct keyCommand *(*lineLoop)(long extra), void (*lin
1876 pollfds[0].fd = 0; 1872 pollfds[0].fd = 0;
1877 1873
1878// 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). 1874// 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).
1875// This might be fixed now.
1879 1876
1880 // TODO - Should only ask for a time out after we get an Escape. 1877 // TODO - Should only ask for a time out after we get an Escape.
1881 p = poll(pollfds, pollcount, 100); // Timeout of one tenth of a second (100). 1878 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
1988 if (found) 1985 if (found)
1989 { 1986 {
1990 // That last argument, an event pointer, should be the original raw keystrokes, though by this time that's been cleared. 1987 // That last argument, an event pointer, should be the original raw keystrokes, though by this time that's been cleared.
1991 lineCommand(extra, found, NULL); 1988 ourKeys = lineCommand(extra, found, NULL);
1992 command[0] = 0; 1989 command[0] = 0;
1993 } 1990 }
1994 } 1991 }
@@ -2733,7 +2730,7 @@ void boxes_main(void)
2733 drawBoxes(currentBox); 2730 drawBoxes(currentBox);
2734 2731
2735 // Run the main loop. 2732 // Run the main loop.
2736 editLine((long) currentBox->view, lineLoop, lineChar, lineCommand); 2733 editLine((long) currentBox->view, lineChar, lineCommand);
2737 2734
2738 // TODO - Should remember to turn off mouse reporting when we leave. 2735 // TODO - Should remember to turn off mouse reporting when we leave.
2739 2736