diff options
Diffstat (limited to '')
-rw-r--r-- | boxes.c | 94 |
1 files changed, 52 insertions, 42 deletions
@@ -1651,59 +1651,69 @@ struct CSI CSIcommands[] = | |||
1651 | {"R", termSize} // Parameters are cursor line and column. Note this may be sent at other times, not just during terminal resize. | 1651 | {"R", termSize} // Parameters are cursor line and column. Note this may be sent at other times, not just during terminal resize. |
1652 | }; | 1652 | }; |
1653 | 1653 | ||
1654 | // Callback for incoming CSI commands from the terminal. | ||
1655 | static void handleCSI(long extra, char *command, int *params, int count) | ||
1656 | { | ||
1657 | int j; | ||
1658 | 1654 | ||
1659 | for (j = 0; j < (sizeof(CSIcommands) / sizeof(*CSIcommands)); j++) | 1655 | // Callback for incoming sequences from the terminal. |
1656 | static int handleEvent(long extra, struct keyevent *event) | ||
1657 | { | ||
1658 | switch (event->type) | ||
1660 | { | 1659 | { |
1661 | if (strcmp(CSIcommands[j].code, command) == 0) | 1660 | case HK_CSI : |
1662 | { | 1661 | { |
1663 | CSIcommands[j].func(extra, params, count); | 1662 | int j; |
1663 | |||
1664 | for (j = 0; j < ARRAY_LEN(CSIcommands); j++) | ||
1665 | { | ||
1666 | if (strcmp(CSIcommands[j].code, event->sequence) == 0) | ||
1667 | { | ||
1668 | CSIcommands[j].func(extra, event->params, event->count); | ||
1669 | break; | ||
1670 | } | ||
1671 | } | ||
1664 | break; | 1672 | break; |
1665 | } | 1673 | } |
1666 | } | ||
1667 | } | ||
1668 | 1674 | ||
1669 | // Callback for incoming key sequences from the user. | 1675 | case HK_KEYS : |
1670 | static int handleKeySequence(long extra, char *sequence, int isTranslated) | 1676 | { |
1671 | { | 1677 | struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. |
1672 | struct _view *view = (struct _view *) extra; // Though we pretty much stomp on this straight away. | 1678 | struct keyCommand *commands = currentBox->view->content->context->modes[currentBox->view->mode].keys; |
1673 | struct keyCommand *commands = currentBox->view->content->context->modes[currentBox->view->mode].keys; | 1679 | int j, l = strlen(event->sequence); |
1674 | int j, l = strlen(sequence); | ||
1675 | 1680 | ||
1676 | // Coz things might change out from under us, find the current view. | 1681 | // Coz things might change out from under us, find the current view. |
1677 | if (commandMode) view = commandLine; | 1682 | if (commandMode) view = commandLine; |
1678 | else view = currentBox->view; | 1683 | else view = currentBox->view; |
1679 | 1684 | ||
1680 | // Search for a key sequence bound to a command. | 1685 | // Search for a key sequence bound to a command. |
1681 | for (j = 0; commands[j].key; j++) | 1686 | for (j = 0; commands[j].key; j++) |
1682 | { | ||
1683 | if (strncmp(commands[j].key, sequence, l) == 0) | ||
1684 | { | ||
1685 | // If it's a partial match, keep accumulating them. | ||
1686 | if (strlen(commands[j].key) != l) | ||
1687 | return 0; | ||
1688 | else | ||
1689 | { | 1687 | { |
1690 | doCommand(view, commands[j].command); | 1688 | if (strncmp(commands[j].key, event->sequence, l) == 0) |
1691 | return 1; | 1689 | { |
1690 | // If it's a partial match, keep accumulating them. | ||
1691 | if (strlen(commands[j].key) != l) | ||
1692 | return 0; | ||
1693 | else | ||
1694 | { | ||
1695 | doCommand(view, commands[j].command); | ||
1696 | return 1; | ||
1697 | } | ||
1698 | } | ||
1692 | } | 1699 | } |
1700 | |||
1701 | // See if it's ordinary keys. | ||
1702 | // NOTE - with vi style ordinary keys can be commands, | ||
1703 | // but they would be found by the command check above first. | ||
1704 | if (!event->isTranslated) | ||
1705 | { | ||
1706 | // TODO - Should check for tabs to, and insert them. | ||
1707 | // Though better off having a function for that? | ||
1708 | mooshStrings(view->line, event->sequence, view->iX, 0, !overWriteMode); | ||
1709 | view->oW = formatLine(view, view->line->line, &(view->output)); | ||
1710 | moveCursorRelative(view, strlen(event->sequence), 0, 0, 0); | ||
1711 | updateLine(view); | ||
1712 | } | ||
1713 | break; | ||
1693 | } | 1714 | } |
1694 | } | ||
1695 | 1715 | ||
1696 | // See if it's ordinary keys. | 1716 | default : break; |
1697 | // NOTE - with vi style ordinary keys can be commands, | ||
1698 | // but they would be found by the command check above first. | ||
1699 | if (!isTranslated) | ||
1700 | { | ||
1701 | // TODO - Should check for tabs to, and insert them. | ||
1702 | // Though better off having a function for that? | ||
1703 | mooshStrings(view->line, sequence, view->iX, 0, !overWriteMode); | ||
1704 | view->oW = formatLine(view, view->line->line, &(view->output)); | ||
1705 | moveCursorRelative(view, strlen(sequence), 0, 0, 0); | ||
1706 | updateLine(view); | ||
1707 | } | 1717 | } |
1708 | 1718 | ||
1709 | // Tell handle_keys to drop it, coz we dealt with it, or it's not one of ours. | 1719 | // Tell handle_keys to drop it, coz we dealt with it, or it's not one of ours. |
@@ -2481,7 +2491,7 @@ void boxes_main(void) | |||
2481 | updateLine(currentBox->view); | 2491 | updateLine(currentBox->view); |
2482 | 2492 | ||
2483 | // Run the main loop. | 2493 | // Run the main loop. |
2484 | handle_keys((long) currentBox->view, handleKeySequence, handleCSI); | 2494 | handle_keys((long) currentBox->view, handleEvent); |
2485 | 2495 | ||
2486 | // TODO - Should remember to turn off mouse reporting when we leave. | 2496 | // TODO - Should remember to turn off mouse reporting when we leave. |
2487 | 2497 | ||