Mercurial > hg > nnchat
comparison main.c @ 449:7d9fa9f7caf1
Rename tab completion functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 04:09:03 +0300 |
parents | 73ff0a592b2f |
children | a8373a1ce1eb |
comparison
equal
deleted
inserted
replaced
448:73ff0a592b2f | 449:7d9fa9f7caf1 |
---|---|
1338 if (statusWin) redrawwin(statusWin); | 1338 if (statusWin) redrawwin(statusWin); |
1339 if (editWin) redrawwin(editWin); | 1339 if (editWin) redrawwin(editWin); |
1340 } | 1340 } |
1341 | 1341 |
1342 | 1342 |
1343 void tabCompletionProd(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) | 1343 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) |
1344 { | 1344 { |
1345 size_t i; | 1345 size_t i; |
1346 | 1346 |
1347 for (i = startPos; i <= endPos; i++) | 1347 for (i = startPos; i <= endPos; i++) |
1348 nn_editbuf_delete(buf, startPos); | 1348 nn_editbuf_delete(buf, startPos); |
1352 | 1352 |
1353 *pi = i; | 1353 *pi = i; |
1354 } | 1354 } |
1355 | 1355 |
1356 | 1356 |
1357 void tabCompletionFinish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) | 1357 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) |
1358 { | 1358 { |
1359 nn_editbuf_setpos(buf, startPos + 1 + strlen(name)); | 1359 nn_editbuf_setpos(buf, startPos + 1 + strlen(name)); |
1360 th_free(*previous); | 1360 th_free(*previous); |
1361 *previous = th_strdup(name); | 1361 *previous = th_strdup(name); |
1362 } | 1362 } |
1363 | 1363 |
1364 | 1364 |
1365 BOOL performTabCompletion(nn_editbuf_t *buf) | 1365 BOOL nn_tabcomplete_buffer(nn_editbuf_t *buf) |
1366 { | 1366 { |
1367 static char *previous = NULL, *pattern = NULL; | 1367 static char *previous = NULL, *pattern = NULL; |
1368 BOOL again = FALSE, hasSeparator = FALSE, | 1368 BOOL again = FALSE, hasSeparator = FALSE, |
1369 hasSpace, newPattern = FALSE, isCommand; | 1369 hasSpace, newPattern = FALSE, isCommand; |
1370 char *str = buf->data; | 1370 char *str = buf->data; |
1447 nn_user_t *user = nn_userhash_match(nnUsers, pattern, previous, again); | 1447 nn_user_t *user = nn_userhash_match(nnUsers, pattern, previous, again); |
1448 | 1448 |
1449 if (user) | 1449 if (user) |
1450 { | 1450 { |
1451 size_t i; | 1451 size_t i; |
1452 tabCompletionProd(buf, &i, startPos, endPos, user->name); | 1452 nn_tabcomplete_replace(buf, &i, startPos, endPos, user->name); |
1453 | 1453 |
1454 if (!hasSeparator && startPos == 0) | 1454 if (!hasSeparator && startPos == 0) |
1455 { | 1455 { |
1456 nn_editbuf_insert(buf, i++, optNickSep); | 1456 nn_editbuf_insert(buf, i++, optNickSep); |
1457 startPos++; | 1457 startPos++; |
1461 startPos++; | 1461 startPos++; |
1462 | 1462 |
1463 if (!hasSpace) | 1463 if (!hasSpace) |
1464 nn_editbuf_insert(buf, i++, ' '); | 1464 nn_editbuf_insert(buf, i++, ' '); |
1465 | 1465 |
1466 tabCompletionFinish(buf, &previous, startPos, user->name); | 1466 nn_tabcomplete_finish(buf, &previous, startPos, user->name); |
1467 return TRUE; | 1467 return TRUE; |
1468 } | 1468 } |
1469 } | 1469 } |
1470 | 1470 |
1471 return FALSE; | 1471 return FALSE; |
2203 case KEY_F(9): // F9 = Quit | 2203 case KEY_F(9): // F9 = Quit |
2204 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); | 2204 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); |
2205 exitProg = TRUE; | 2205 exitProg = TRUE; |
2206 break; | 2206 break; |
2207 | 2207 |
2208 case 0x09: // Tab = complete username | 2208 case 0x09: // Tab = complete username or command |
2209 performTabCompletion(editBuf); | 2209 nn_tabcomplete_buffer(editBuf); |
2210 update = TRUE; | 2210 update = TRUE; |
2211 break; | 2211 break; |
2212 | 2212 |
2213 case 0x0c: // Ctrl + L | 2213 case 0x0c: // Ctrl + L |
2214 nnwin_update_all(); | 2214 nnwin_update_all(); |