Mercurial > hg
comparison mcabber/src/screen.c @ 173:09e24917059d
[/trunk] Changeset 185 by mikael
* Command (input) line history
author | mikael |
---|---|
date | Wed, 04 May 2005 21:06:05 +0000 |
parents | 6ad156673b19 |
children | 6354625e8fb2 |
comparison
equal
deleted
inserted
replaced
172:dabf8c3b475c | 173:09e24917059d |
---|---|
45 | 45 |
46 static char inputLine[INPUTLINE_LENGTH+1]; | 46 static char inputLine[INPUTLINE_LENGTH+1]; |
47 static char *ptr_inputline; | 47 static char *ptr_inputline; |
48 static short int inputline_offset; | 48 static short int inputline_offset; |
49 static int completion_started; | 49 static int completion_started; |
50 static GList *cmdhisto; | |
51 static GList *cmdhisto_cur; | |
50 | 52 |
51 | 53 |
52 /* Functions */ | 54 /* Functions */ |
53 | 55 |
54 int scr_WindowWidth(WINDOW * win) | 56 int scr_WindowWidth(WINDOW * win) |
950 inline void scr_set_chatmode(int enable) | 952 inline void scr_set_chatmode(int enable) |
951 { | 953 { |
952 chatmode = enable; | 954 chatmode = enable; |
953 } | 955 } |
954 | 956 |
957 // scr_cmdhisto_addline() | |
958 // Add a line to the inputLine history | |
959 inline void scr_cmdhisto_addline(char *line) | |
960 { | |
961 if (!line || !*line) return; | |
962 | |
963 cmdhisto = g_list_append(cmdhisto, g_strdup(line)); | |
964 } | |
965 | |
966 // scr_cmdhisto_prev() | |
967 // Look for previous line beginning w/ the given mask in the inputLine history | |
968 const char *scr_cmdhisto_prev(char *mask, guint len) | |
969 { | |
970 GList *hl; | |
971 if (!cmdhisto_cur) { | |
972 hl = g_list_last(cmdhisto); | |
973 } else { | |
974 hl = g_list_previous(cmdhisto_cur); | |
975 } | |
976 while (hl) { | |
977 if (!strncmp((char*)hl->data, mask, len)) { | |
978 // Found a match | |
979 cmdhisto_cur = hl; | |
980 return (const char*)hl->data; | |
981 } | |
982 hl = g_list_previous(hl); | |
983 } | |
984 return NULL; | |
985 } | |
986 | |
987 // scr_cmdhisto_next() | |
988 // Look for next line beginning w/ the given mask in the inputLine history | |
989 const char *scr_cmdhisto_next(char *mask, guint len) | |
990 { | |
991 GList *hl; | |
992 if (!cmdhisto_cur) return NULL; | |
993 hl = cmdhisto_cur; | |
994 while ((hl = g_list_next(hl)) != NULL) | |
995 if (!strncmp((char*)hl->data, mask, len)) { | |
996 // Found a match | |
997 cmdhisto_cur = hl; | |
998 return (const char*)hl->data; | |
999 } | |
1000 return NULL; | |
1001 } | |
1002 | |
955 // which_row() | 1003 // which_row() |
956 // Tells which row our cursor is in, in the command line. | 1004 // Tells which row our cursor is in, in the command line. |
957 // -1 -> normal text | 1005 // -1 -> normal text |
958 // 0 -> command | 1006 // 0 -> command |
959 // 1 -> parameter 1 (etc.) | 1007 // 1 -> parameter 1 (etc.) |
1152 check_offset(0); | 1200 check_offset(0); |
1153 break; | 1201 break; |
1154 case '\n': // Enter | 1202 case '\n': // Enter |
1155 if (process_line(inputLine)) | 1203 if (process_line(inputLine)) |
1156 return 255; | 1204 return 255; |
1205 // Add line to history | |
1206 scr_cmdhisto_addline(inputLine); | |
1207 cmdhisto_cur = NULL; | |
1208 // Reset the line | |
1157 ptr_inputline = inputLine; | 1209 ptr_inputline = inputLine; |
1158 *ptr_inputline = 0; | 1210 *ptr_inputline = 0; |
1159 inputline_offset = 0; | 1211 inputline_offset = 0; |
1160 break; | 1212 break; |
1161 case KEY_UP: | 1213 case KEY_UP: |
1188 case KEY_EOL: | 1240 case KEY_EOL: |
1189 case 11: // Ctrl-k | 1241 case 11: // Ctrl-k |
1190 *ptr_inputline = 0; | 1242 *ptr_inputline = 0; |
1191 break; | 1243 break; |
1192 case 16: // Ctrl-p | 1244 case 16: // Ctrl-p |
1193 scr_LogPrint("Ctrl-p not yet implemented"); | 1245 { |
1246 const char *l = scr_cmdhisto_prev(inputLine, | |
1247 ptr_inputline-inputLine); | |
1248 if (l) { | |
1249 strcpy(inputLine, l); | |
1250 } | |
1251 } | |
1194 break; | 1252 break; |
1195 case 14: // Ctrl-n | 1253 case 14: // Ctrl-n |
1196 scr_LogPrint("Ctrl-n not yet implemented"); | 1254 { |
1255 const char *l = scr_cmdhisto_next(inputLine, | |
1256 ptr_inputline-inputLine); | |
1257 if (l) { | |
1258 strcpy(inputLine, l); | |
1259 } | |
1260 } | |
1197 break; | 1261 break; |
1198 case 27: // ESC | 1262 case 27: // ESC |
1199 currentWindow = NULL; | 1263 currentWindow = NULL; |
1200 chatmode = FALSE; | 1264 chatmode = FALSE; |
1201 if (current_buddy) | 1265 if (current_buddy) |