aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-01-30 16:45:04 +1000
committerDavid Walter Seikel2014-01-30 16:45:04 +1000
commit0deaf20da18fc442417e55e4865ee0293a7bc379 (patch)
tree4ed5326bdb3d92b42cab21400d88701841773fe5
parentMove all the SIGWINCH stuff inte handle_keys(). (diff)
downloadboxes-0deaf20da18fc442417e55e4865ee0293a7bc379.zip
boxes-0deaf20da18fc442417e55e4865ee0293a7bc379.tar.gz
boxes-0deaf20da18fc442417e55e4865ee0293a7bc379.tar.bz2
boxes-0deaf20da18fc442417e55e4865ee0293a7bc379.tar.xz
Move the actual CSI command scanner out of handle_keys().
-rw-r--r--boxes.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/boxes.c b/boxes.c
index 8f9f19a..fba9fe0 100644
--- a/boxes.c
+++ b/boxes.c
@@ -494,7 +494,6 @@ typedef struct _view view;
494 494
495typedef void (*boxFunction) (box *box); 495typedef void (*boxFunction) (box *box);
496typedef void (*eventHandler) (view *view); 496typedef void (*eventHandler) (view *view);
497typedef void (*CSIhandler) (long extra, int *code, int count);
498 497
499struct function 498struct function
500{ 499{
@@ -1785,6 +1784,14 @@ void nop(view *view)
1785} 1784}
1786 1785
1787 1786
1787typedef void (*CSIhandler) (long extra, int *code, int count);
1788
1789struct CSI
1790{
1791 char *code;
1792 CSIhandler func;
1793};
1794
1788static void termSize(long extra, int *params, int count) 1795static void termSize(long extra, int *params, int count)
1789{ 1796{
1790 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. 1797 struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away.
@@ -1811,17 +1818,25 @@ static void termSize(long extra, int *params, int count)
1811 } 1818 }
1812} 1819}
1813 1820
1814struct CSI 1821struct CSI CSIcommands[] =
1815{ 1822{
1816 char *code; 1823 {"R", termSize} // Parameters are cursor line and column. Note this may be sent at other times, not just during terminal resize.
1817 CSIhandler func;
1818}; 1824};
1819 1825
1820struct CSI CSI_terminators[] = 1826static void handleCSI(long extra, char *command, int *params, int count)
1821{ 1827{
1822 {"R", termSize}, // Parameters are cursor line and column. Note this may be sent at other times, not just during terminal resize. 1828 int j;
1823 {NULL, NULL} 1829
1824}; 1830 for (j = 0; j < (sizeof(CSIcommands) / sizeof(*CSIcommands)); j++)
1831 {
1832 if (strcmp(CSIcommands[j].code, command) == 0)
1833 {
1834 CSIcommands[j].func(extra, params, count);
1835 break;
1836 }
1837 }
1838}
1839
1825 1840
1826static int handleKeySequence(long extra, char *sequence) 1841static int handleKeySequence(long extra, char *sequence)
1827{ 1842{
@@ -1870,7 +1885,7 @@ static void handleSignals(int signo)
1870// TODO - Unhandled complications - 1885// TODO - Unhandled complications -
1871// Less and more have the "ZZ" command, but nothing else seems to have multi ordinary character commands. 1886// Less and more have the "ZZ" command, but nothing else seems to have multi ordinary character commands.
1872 1887
1873void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence)) 1888void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence), void (*handle_CSI)(long extra, char *command, int *params, int count))
1874{ 1889{
1875 fd_set selectFds; 1890 fd_set selectFds;
1876 struct timespec timeout; 1891 struct timespec timeout;
@@ -2063,16 +2078,10 @@ TODO So abort the current CSI and start from scratch.
2063 } 2078 }
2064 while (t); 2079 while (t);
2065 2080
2066 // Get the final command sequence, and search for it. 2081 // Get the final command sequence, and pass it to the callback.
2067 strcat(csFinal, &buffer[csIndex]); 2082 strcat(csFinal, &buffer[csIndex]);
2068 for (j = 0; CSI_terminators[j].code; j++) 2083 if (handle_CSI)
2069 { 2084 handle_CSI(extra, csFinal, csParams, p);
2070 if (strcmp(CSI_terminators[j].code, csFinal) == 0)
2071 {
2072 CSI_terminators[j].func(extra, csParams, p);
2073 break;
2074 }
2075 }
2076 } 2085 }
2077 2086
2078 csi = 0; 2087 csi = 0;
@@ -2081,7 +2090,7 @@ TODO So abort the current CSI and start from scratch.
2081 } 2090 }
2082 2091
2083 // Pass the result to the callback. 2092 // Pass the result to the callback.
2084 if (sequence[0] || buffer[0]) 2093 if ((handle_sequence) && (sequence[0] || buffer[0]))
2085 { 2094 {
2086 char b[strlen(sequence) + strlen(buffer) + 1]; 2095 char b[strlen(sequence) + strlen(buffer) + 1];
2087 2096
@@ -2860,7 +2869,7 @@ void boxes_main(void)
2860 updateLine(currentBox->view); 2869 updateLine(currentBox->view);
2861 2870
2862 // Run the main loop. 2871 // Run the main loop.
2863 handle_keys((long) currentBox->view, handleKeySequence); 2872 handle_keys((long) currentBox->view, handleKeySequence, handleCSI);
2864 2873
2865 // TODO - Should remember to turn off mouse reporting when we leave. 2874 // TODO - Should remember to turn off mouse reporting when we leave.
2866 2875