diff options
Diffstat (limited to '')
-rw-r--r-- | boxes.c | 49 |
1 files changed, 29 insertions, 20 deletions
@@ -494,7 +494,6 @@ typedef struct _view view; | |||
494 | 494 | ||
495 | typedef void (*boxFunction) (box *box); | 495 | typedef void (*boxFunction) (box *box); |
496 | typedef void (*eventHandler) (view *view); | 496 | typedef void (*eventHandler) (view *view); |
497 | typedef void (*CSIhandler) (long extra, int *code, int count); | ||
498 | 497 | ||
499 | struct function | 498 | struct function |
500 | { | 499 | { |
@@ -1785,6 +1784,14 @@ void nop(view *view) | |||
1785 | } | 1784 | } |
1786 | 1785 | ||
1787 | 1786 | ||
1787 | typedef void (*CSIhandler) (long extra, int *code, int count); | ||
1788 | |||
1789 | struct CSI | ||
1790 | { | ||
1791 | char *code; | ||
1792 | CSIhandler func; | ||
1793 | }; | ||
1794 | |||
1788 | static void termSize(long extra, int *params, int count) | 1795 | static 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 | ||
1814 | struct CSI | 1821 | struct 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 | ||
1820 | struct CSI CSI_terminators[] = | 1826 | static 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 | ||
1826 | static int handleKeySequence(long extra, char *sequence) | 1841 | static 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 | ||
1873 | void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence)) | 1888 | void 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 | ||