diff options
-rw-r--r-- | boxes.c | 83 |
1 files changed, 42 insertions, 41 deletions
@@ -1799,7 +1799,7 @@ static void lineChar(long extra, char *buffer) | |||
1799 | updateLine(view); | 1799 | updateLine(view); |
1800 | } | 1800 | } |
1801 | 1801 | ||
1802 | static struct keyCommand * lineCommand(long extra, char *command) | 1802 | static struct keyCommand * lineCommand(long extra, char *sequence) |
1803 | { | 1803 | { |
1804 | 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 | 1805 | ||
@@ -1807,7 +1807,7 @@ static struct keyCommand * lineCommand(long extra, char *command) | |||
1807 | if (commandMode) view = commandLine; | 1807 | if (commandMode) view = commandLine; |
1808 | else view = currentBox->view; | 1808 | else view = currentBox->view; |
1809 | 1809 | ||
1810 | doCommand(view, command); | 1810 | doCommand(view, sequence); |
1811 | 1811 | ||
1812 | // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate. | 1812 | // This is using the currentBox instead of view, coz the command line keys are part of the box context now, not separate. |
1813 | return currentBox->view->content->context->modes[currentBox->view->mode].keys; | 1813 | return currentBox->view->content->context->modes[currentBox->view->mode].keys; |
@@ -1862,22 +1862,22 @@ Some editors have a shortcut command concept. The smallest unique first part of | |||
1862 | A further complication is if we are not implementing some commands that might change what is "shortest unique prefix". | 1862 | A further complication is if we are not implementing some commands that might change what is "shortest unique prefix". |
1863 | */ | 1863 | */ |
1864 | 1864 | ||
1865 | void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *command)) | 1865 | void handle_keys(long extra, void (*lineChar)(long extra, char *buffer), struct keyCommand * (*lineCommand)(long extra, char *sequence)) |
1866 | { | 1866 | { |
1867 | fd_set selectFds; | 1867 | fd_set selectFds; |
1868 | struct timespec timeout; | 1868 | struct timespec timeout; |
1869 | sigset_t signalMask; | 1869 | sigset_t signalMask; |
1870 | 1870 | ||
1871 | // Get the initial command set. | 1871 | // Get the initial command set. |
1872 | struct keyCommand *ourKeys = lineCommand(extra, ""); | 1872 | struct keyCommand *commands = lineCommand(extra, ""); |
1873 | char buffer[20], command[20], csFinal[8]; | 1873 | char buffer[20], sequence[20], csFinal[8]; |
1874 | int csi = 0, csCount = 0, csIndex = 0, csParams[8], index = 0, pollcount = 1; | 1874 | int csi = 0, csCount = 0, csIndex = 0, csParams[8], buffIndex = 0; |
1875 | // TODO - multiline editLine is an advanced feature. Editing boxes just moves the editLine up and down. | 1875 | // TODO - multiline editLine is an advanced feature. Editing boxes just moves the editLine up and down. |
1876 | // uint16_t h = 1; | 1876 | // uint16_t h = 1; |
1877 | // TODO - should check if it's at the top of the box, then grow it down instead of up if so. | 1877 | // TODO - should check if it's at the top of the box, then grow it down instead of up if so. |
1878 | 1878 | ||
1879 | buffer[0] = 0; | 1879 | buffer[0] = 0; |
1880 | command[0] = 0; | 1880 | sequence[0] = 0; |
1881 | 1881 | ||
1882 | sigemptyset(&signalMask); | 1882 | sigemptyset(&signalMask); |
1883 | sigaddset(&signalMask, SIGWINCH); | 1883 | sigaddset(&signalMask, SIGWINCH); |
@@ -1887,9 +1887,9 @@ void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct key | |||
1887 | while (TT.stillRunning) | 1887 | while (TT.stillRunning) |
1888 | { | 1888 | { |
1889 | int j, p; | 1889 | int j, p; |
1890 | char *found = NULL; | 1890 | char *command = NULL; |
1891 | 1891 | ||
1892 | if (0 == index) | 1892 | if (0 == buffIndex) |
1893 | { | 1893 | { |
1894 | buffer[0] = 0; | 1894 | buffer[0] = 0; |
1895 | csi = 0; | 1895 | csi = 0; |
@@ -1925,11 +1925,11 @@ void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct key | |||
1925 | } | 1925 | } |
1926 | if (0 == p) // A timeout, trigger a time event. | 1926 | if (0 == p) // A timeout, trigger a time event. |
1927 | { | 1927 | { |
1928 | if ((1 == index) && ('\x1B' == buffer[0])) | 1928 | if ((1 == buffIndex) && ('\x1B' == buffer[0])) |
1929 | { | 1929 | { |
1930 | // After a short delay to check, this is a real Escape key, not part of an escape sequence, so deal with it. | 1930 | // After a short delay to check, this is a real Escape key, not part of an escape sequence, so deal with it. |
1931 | strcpy(command, "^["); | 1931 | strcpy(sequence, "^["); |
1932 | index = 0; | 1932 | buffIndex = 0; |
1933 | } | 1933 | } |
1934 | // TODO - Send a timer event to lineCommand(). This wont be a precise timed event, but don't think we need one. | 1934 | // TODO - Send a timer event to lineCommand(). This wont be a precise timed event, but don't think we need one. |
1935 | } | 1935 | } |
@@ -1980,7 +1980,7 @@ void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct key | |||
1980 | buffer[0] = '\x9B'; | 1980 | buffer[0] = '\x9B'; |
1981 | for (j = 1; buffer[j]; j++) | 1981 | for (j = 1; buffer[j]; j++) |
1982 | buffer[j] = buffer[j + 1]; | 1982 | buffer[j] = buffer[j + 1]; |
1983 | index--; | 1983 | buffIndex--; |
1984 | csi = 1; | 1984 | csi = 1; |
1985 | } | 1985 | } |
1986 | 1986 | ||
@@ -1991,8 +1991,8 @@ void editLine(long extra, void (*lineChar)(long extra, char *buffer), struct key | |||
1991 | { | 1991 | { |
1992 | if (strcmp(keys[j].code, buffer) == 0) | 1992 | if (strcmp(keys[j].code, buffer) == 0) |
1993 | { | 1993 | { |
1994 | strcat(command, keys[j].name); | 1994 | strcat(sequence, keys[j].name); |
1995 | index = 0; | 1995 | buffIndex = 0; |
1996 | csi = 0; | 1996 | csi = 0; |
1997 | break; | 1997 | break; |
1998 | } | 1998 | } |
@@ -2030,9 +2030,8 @@ TODO So abort the current CSI and start from scratch. | |||
2030 | } | 2030 | } |
2031 | else | 2031 | else |
2032 | { | 2032 | { |
2033 | // TODO - Using rindex here, coz index is a variable in this scope. Should rename index. | ||
2034 | // Check for the private bit. | 2033 | // Check for the private bit. |
2035 | if (rindex("<=>?", buffer[1])) | 2034 | if (index("<=>?", buffer[1])) |
2036 | { | 2035 | { |
2037 | csFinal[0] = buffer[1]; | 2036 | csFinal[0] = buffer[1]; |
2038 | csFinal[1] = 0; | 2037 | csFinal[1] = 0; |
@@ -2044,7 +2043,7 @@ TODO So abort the current CSI and start from scratch. | |||
2044 | do | 2043 | do |
2045 | { | 2044 | { |
2046 | // So we know when we get to the end of parameter space. | 2045 | // So we know when we get to the end of parameter space. |
2047 | t = rindex("01234567890:;<=>?", buffer[j + 1]); | 2046 | t = index("01234567890:;<=>?", buffer[j + 1]); |
2048 | // See if we passed a paremeter. | 2047 | // See if we passed a paremeter. |
2049 | if ((';' == buffer[j]) || (!t)) | 2048 | if ((';' == buffer[j]) || (!t)) |
2050 | { | 2049 | { |
@@ -2072,7 +2071,7 @@ TODO So abort the current CSI and start from scratch. | |||
2072 | { | 2071 | { |
2073 | t = CSI_terminators[j].func(extra, csParams, csCount); | 2072 | t = CSI_terminators[j].func(extra, csParams, csCount); |
2074 | if (t) | 2073 | if (t) |
2075 | strcpy(command, t); | 2074 | strcpy(sequence, t); |
2076 | break; | 2075 | break; |
2077 | } | 2076 | } |
2078 | } | 2077 | } |
@@ -2080,55 +2079,57 @@ TODO So abort the current CSI and start from scratch. | |||
2080 | 2079 | ||
2081 | csi = 0; | 2080 | csi = 0; |
2082 | // Wether or not it's a CSI we understand, it's been handled either here or in the key sequence scanning above. | 2081 | // Wether or not it's a CSI we understand, it's been handled either here or in the key sequence scanning above. |
2083 | index = 0; | 2082 | buffIndex = 0; |
2084 | } | 2083 | } |
2085 | 2084 | ||
2086 | // See if it's an ordinary key, | 2085 | // See if it's an ordinary key, |
2087 | if ((1 == index) && isprint(buffer[0])) | 2086 | if ((1 == buffIndex) && isprint(buffer[0])) |
2088 | { | 2087 | { |
2089 | // Here we want to run it through the command finder first, and only "insert" it if it's not a command. | 2088 | // Here we want to run it through the command finder first, and only "insert" it if it's not a command. |
2090 | for (j = 0; ourKeys[j].key; j++) | 2089 | // Yes, this is duplicated below. |
2090 | for (j = 0; commands[j].key; j++) | ||
2091 | { | 2091 | { |
2092 | if (strcmp(ourKeys[j].key, buffer) == 0) | 2092 | if (strcmp(commands[j].key, buffer) == 0) |
2093 | { | 2093 | { |
2094 | strcpy(command, buffer); | 2094 | strcpy(sequence, buffer); |
2095 | found = command; | 2095 | command = sequence; |
2096 | break; | 2096 | break; |
2097 | } | 2097 | } |
2098 | } | 2098 | } |
2099 | if (NULL == found) | 2099 | if (NULL == command) |
2100 | { | 2100 | { |
2101 | // If there's an outstanding command, add this to the end of it. | 2101 | // If there's an outstanding sequence, add this to the end of it. |
2102 | if (command[0]) strcat(command, buffer); | 2102 | if (sequence[0]) strcat(sequence, buffer); |
2103 | else lineChar(extra, buffer); | 2103 | else lineChar(extra, buffer); |
2104 | } | 2104 | } |
2105 | index = 0; | 2105 | buffIndex = 0; |
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | if (command[0]) // Search for a bound key. | 2108 | // Search for a key sequence bound to a command. |
2109 | if (sequence[0]) | ||
2109 | { | 2110 | { |
2110 | if (sizeof(command) < (strlen(command) + 1)) | 2111 | if (sizeof(sequence) < (strlen(sequence) + 1)) |
2111 | { | 2112 | { |
2112 | fprintf(stderr, "Full command buffer - %s \n", command); | 2113 | fprintf(stderr, "Full key sequence buffer - %s \n", sequence); |
2113 | fflush(stderr); | 2114 | fflush(stderr); |
2114 | command[0] = 0; | 2115 | sequence[0] = 0; |
2115 | } | 2116 | } |
2116 | 2117 | ||
2117 | if (NULL == found) | 2118 | if (NULL == command) |
2118 | { | 2119 | { |
2119 | for (j = 0; ourKeys[j].key; j++) | 2120 | for (j = 0; commands[j].key; j++) |
2120 | { | 2121 | { |
2121 | if (strcmp(ourKeys[j].key, command) == 0) | 2122 | if (strcmp(commands[j].key, sequence) == 0) |
2122 | { | 2123 | { |
2123 | found = ourKeys[j].command; | 2124 | command = commands[j].command; |
2124 | break; | 2125 | break; |
2125 | } | 2126 | } |
2126 | } | 2127 | } |
2127 | } | 2128 | } |
2128 | if (found) | 2129 | if (command) |
2129 | { | 2130 | { |
2130 | ourKeys = lineCommand(extra, found); | 2131 | commands = lineCommand(extra, command); |
2131 | command[0] = 0; | 2132 | sequence[0] = 0; |
2132 | } | 2133 | } |
2133 | } | 2134 | } |
2134 | } | 2135 | } |
@@ -2909,7 +2910,7 @@ void boxes_main(void) | |||
2909 | updateLine(currentBox->view); | 2910 | updateLine(currentBox->view); |
2910 | 2911 | ||
2911 | // Run the main loop. | 2912 | // Run the main loop. |
2912 | editLine((long) currentBox->view, lineChar, lineCommand); | 2913 | handle_keys((long) currentBox->view, lineChar, lineCommand); |
2913 | 2914 | ||
2914 | // TODO - Should remember to turn off mouse reporting when we leave. | 2915 | // TODO - Should remember to turn off mouse reporting when we leave. |
2915 | 2916 | ||