Mercurial > hg
comparison mcabber/src/screen.c @ 499:baa812f04f24
Reorganise process_key()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 13 Oct 2005 19:58:58 +0200 |
parents | 882e1acae422 |
children | ddec224c2318 |
comparison
equal
deleted
inserted
replaced
498:879ffddc13b0 | 499:baa812f04f24 |
---|---|
1551 | 1551 |
1552 // process_key(key) | 1552 // process_key(key) |
1553 // Handle the pressed key, in the command line (bottom). | 1553 // Handle the pressed key, in the command line (bottom). |
1554 int process_key(int key) | 1554 int process_key(int key) |
1555 { | 1555 { |
1556 if (isprint(key)) { | 1556 switch(key) { |
1557 char tmpLine[INPUTLINE_LENGTH+1]; | 1557 case 8: // Ctrl-h |
1558 | 1558 case 127: // Backspace too |
1559 // Check the line isn't too long | 1559 case KEY_BACKSPACE: |
1560 if (strlen(inputLine) >= INPUTLINE_LENGTH) | 1560 if (ptr_inputline != (char*)&inputLine) { |
1561 return 0; | 1561 char *c = --ptr_inputline; |
1562 | 1562 for ( ; *c ; c++) |
1563 // Insert char | 1563 *c = *(c+1); |
1564 strcpy(tmpLine, ptr_inputline); | 1564 check_offset(-1); |
1565 *ptr_inputline++ = key; | 1565 } |
1566 strcpy(ptr_inputline, tmpLine); | 1566 break; |
1567 check_offset(1); | 1567 case KEY_DC:// Del |
1568 } else { | 1568 if (*ptr_inputline) |
1569 switch(key) { | 1569 strcpy(ptr_inputline, ptr_inputline+1); |
1570 case 8: // Ctrl-h | 1570 break; |
1571 case 127: // Backspace too | 1571 case KEY_LEFT: |
1572 case KEY_BACKSPACE: | 1572 if (ptr_inputline != (char*)&inputLine) { |
1573 if (ptr_inputline != (char*)&inputLine) { | 1573 ptr_inputline--; |
1574 char *c = --ptr_inputline; | 1574 check_offset(-1); |
1575 for ( ; *c ; c++) | 1575 } |
1576 *c = *(c+1); | 1576 break; |
1577 check_offset(-1); | 1577 case KEY_RIGHT: |
1578 if (*ptr_inputline) | |
1579 ptr_inputline++; | |
1580 check_offset(1); | |
1581 break; | |
1582 case 7: // Ctrl-g | |
1583 scr_cancel_current_completion(); | |
1584 scr_end_current_completion(); | |
1585 check_offset(-1); | |
1586 break; | |
1587 case 9: // Tab | |
1588 scr_handle_tab(); | |
1589 check_offset(0); | |
1590 break; | |
1591 case 13: // Enter | |
1592 case 15: // Ctrl-o ("accept-line-and-down-history") | |
1593 scr_CheckAutoAway(TRUE); | |
1594 if (process_line(inputLine)) | |
1595 return 255; | |
1596 // Add line to history | |
1597 scr_cmdhisto_addline(inputLine); | |
1598 // Reset the line | |
1599 ptr_inputline = inputLine; | |
1600 *ptr_inputline = 0; | |
1601 inputline_offset = 0; | |
1602 | |
1603 if (key == 13) // Enter | |
1604 { | |
1605 // Reset history line pointer | |
1606 cmdhisto_cur = NULL; | |
1607 } else { // down-history | |
1608 // Use next history line instead of a blank line | |
1609 const char *l = scr_cmdhisto_next("", 0); | |
1610 if (l) strcpy(inputLine, l); | |
1611 // Reset backup history line | |
1612 cmdhisto_backup[0] = 0; | |
1613 } | |
1614 break; | |
1615 case KEY_UP: | |
1616 { | |
1617 const char *l = scr_cmdhisto_prev(inputLine, | |
1618 ptr_inputline-inputLine); | |
1619 if (l) strcpy(inputLine, l); | |
1620 } | |
1621 break; | |
1622 case KEY_DOWN: | |
1623 { | |
1624 const char *l = scr_cmdhisto_next(inputLine, | |
1625 ptr_inputline-inputLine); | |
1626 if (l) strcpy(inputLine, l); | |
1627 } | |
1628 break; | |
1629 case KEY_PPAGE: | |
1630 scr_CheckAutoAway(TRUE); | |
1631 scr_RosterUp(); | |
1632 break; | |
1633 case KEY_NPAGE: | |
1634 scr_CheckAutoAway(TRUE); | |
1635 scr_RosterDown(); | |
1636 break; | |
1637 case KEY_HOME: | |
1638 case 1: | |
1639 ptr_inputline = inputLine; | |
1640 inputline_offset = 0; | |
1641 break; | |
1642 case 3: // Ctrl-C | |
1643 scr_handle_CtrlC(); | |
1644 break; | |
1645 case KEY_END: | |
1646 case 5: | |
1647 for (; *ptr_inputline; ptr_inputline++) ; | |
1648 check_offset(1); | |
1649 break; | |
1650 case 21: // Ctrl-u | |
1651 strcpy(inputLine, ptr_inputline); | |
1652 ptr_inputline = inputLine; | |
1653 inputline_offset = 0; | |
1654 break; | |
1655 case KEY_EOL: | |
1656 case 11: // Ctrl-k | |
1657 *ptr_inputline = 0; | |
1658 break; | |
1659 case 16: // Ctrl-p | |
1660 scr_BufferScrollUpDown(-1); | |
1661 break; | |
1662 case 14: // Ctrl-n | |
1663 scr_BufferScrollUpDown(1); | |
1664 break; | |
1665 case 17: // Ctrl-q | |
1666 scr_CheckAutoAway(TRUE); | |
1667 scr_RosterUnreadMessage(1); // next unread message | |
1668 break; | |
1669 case 20: // Ctrl-t | |
1670 readline_transpose_chars(); | |
1671 break; | |
1672 case 23: // Ctrl-w | |
1673 readline_backward_kill_word(); | |
1674 break; | |
1675 case 27: // ESC | |
1676 scr_CheckAutoAway(TRUE); | |
1677 currentWindow = NULL; | |
1678 chatmode = FALSE; | |
1679 if (current_buddy) | |
1680 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | |
1681 top_panel(chatPanel); | |
1682 top_panel(inputPanel); | |
1683 update_panels(); | |
1684 break; | |
1685 case 12: // Ctrl-l | |
1686 scr_CheckAutoAway(TRUE); | |
1687 redrawwin(stdscr); | |
1688 case KEY_RESIZE: | |
1689 scr_Resize(); | |
1690 break; | |
1691 default: | |
1692 if (isprint(key)) { | |
1693 char tmpLine[INPUTLINE_LENGTH+1]; | |
1694 | |
1695 // Check the line isn't too long | |
1696 if (strlen(inputLine) >= INPUTLINE_LENGTH) | |
1697 return 0; | |
1698 | |
1699 // Insert char | |
1700 strcpy(tmpLine, ptr_inputline); | |
1701 *ptr_inputline++ = key; | |
1702 strcpy(ptr_inputline, tmpLine); | |
1703 check_offset(1); | |
1704 } else { | |
1705 const gchar *boundcmd = isbound(key); | |
1706 if (boundcmd) { | |
1707 gchar *cmd = g_strdup_printf("/%s", boundcmd); | |
1708 scr_CheckAutoAway(TRUE); | |
1709 if (process_command(cmd)) | |
1710 return 255; | |
1711 g_free(cmd); | |
1712 } else { | |
1713 scr_LogPrint(LPRINT_NORMAL, "Unknown key=%d", key); | |
1714 if (utf8_mode) | |
1715 scr_LogPrint(LPRINT_NORMAL, | |
1716 "WARNING: UTF-8 not yet supported!"); | |
1578 } | 1717 } |
1579 break; | 1718 } |
1580 case KEY_DC:// Del | 1719 } |
1581 if (*ptr_inputline) | 1720 |
1582 strcpy(ptr_inputline, ptr_inputline+1); | |
1583 break; | |
1584 case KEY_LEFT: | |
1585 if (ptr_inputline != (char*)&inputLine) { | |
1586 ptr_inputline--; | |
1587 check_offset(-1); | |
1588 } | |
1589 break; | |
1590 case KEY_RIGHT: | |
1591 if (*ptr_inputline) | |
1592 ptr_inputline++; | |
1593 check_offset(1); | |
1594 break; | |
1595 case 7: // Ctrl-g | |
1596 scr_cancel_current_completion(); | |
1597 scr_end_current_completion(); | |
1598 check_offset(-1); | |
1599 break; | |
1600 case 9: // Tab | |
1601 scr_handle_tab(); | |
1602 check_offset(0); | |
1603 break; | |
1604 case 13: // Enter | |
1605 case 15: // Ctrl-o ("accept-line-and-down-history") | |
1606 scr_CheckAutoAway(TRUE); | |
1607 if (process_line(inputLine)) | |
1608 return 255; | |
1609 // Add line to history | |
1610 scr_cmdhisto_addline(inputLine); | |
1611 // Reset the line | |
1612 ptr_inputline = inputLine; | |
1613 *ptr_inputline = 0; | |
1614 inputline_offset = 0; | |
1615 | |
1616 if (key == 13) // Enter | |
1617 { | |
1618 // Reset history line pointer | |
1619 cmdhisto_cur = NULL; | |
1620 } else { // down-history | |
1621 // Use next history line instead of a blank line | |
1622 const char *l = scr_cmdhisto_next("", 0); | |
1623 if (l) strcpy(inputLine, l); | |
1624 // Reset backup history line | |
1625 cmdhisto_backup[0] = 0; | |
1626 } | |
1627 break; | |
1628 case KEY_UP: | |
1629 { | |
1630 const char *l = scr_cmdhisto_prev(inputLine, | |
1631 ptr_inputline-inputLine); | |
1632 if (l) strcpy(inputLine, l); | |
1633 } | |
1634 break; | |
1635 case KEY_DOWN: | |
1636 { | |
1637 const char *l = scr_cmdhisto_next(inputLine, | |
1638 ptr_inputline-inputLine); | |
1639 if (l) strcpy(inputLine, l); | |
1640 } | |
1641 break; | |
1642 case KEY_PPAGE: | |
1643 scr_CheckAutoAway(TRUE); | |
1644 scr_RosterUp(); | |
1645 break; | |
1646 case KEY_NPAGE: | |
1647 scr_CheckAutoAway(TRUE); | |
1648 scr_RosterDown(); | |
1649 break; | |
1650 case KEY_HOME: | |
1651 case 1: | |
1652 ptr_inputline = inputLine; | |
1653 inputline_offset = 0; | |
1654 break; | |
1655 case 3: // Ctrl-C | |
1656 scr_handle_CtrlC(); | |
1657 break; | |
1658 case KEY_END: | |
1659 case 5: | |
1660 for (; *ptr_inputline; ptr_inputline++) ; | |
1661 check_offset(1); | |
1662 break; | |
1663 case 21: // Ctrl-u | |
1664 strcpy(inputLine, ptr_inputline); | |
1665 ptr_inputline = inputLine; | |
1666 inputline_offset = 0; | |
1667 break; | |
1668 case KEY_EOL: | |
1669 case 11: // Ctrl-k | |
1670 *ptr_inputline = 0; | |
1671 break; | |
1672 case 16: // Ctrl-p | |
1673 scr_BufferScrollUpDown(-1); | |
1674 break; | |
1675 case 14: // Ctrl-n | |
1676 scr_BufferScrollUpDown(1); | |
1677 break; | |
1678 case 17: // Ctrl-q | |
1679 scr_CheckAutoAway(TRUE); | |
1680 scr_RosterUnreadMessage(1); // next unread message | |
1681 break; | |
1682 case 20: // Ctrl-t | |
1683 readline_transpose_chars(); | |
1684 break; | |
1685 case 23: // Ctrl-w | |
1686 readline_backward_kill_word(); | |
1687 break; | |
1688 case 27: // ESC | |
1689 scr_CheckAutoAway(TRUE); | |
1690 currentWindow = NULL; | |
1691 chatmode = FALSE; | |
1692 if (current_buddy) | |
1693 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); | |
1694 top_panel(chatPanel); | |
1695 top_panel(inputPanel); | |
1696 update_panels(); | |
1697 break; | |
1698 case 12: // Ctrl-l | |
1699 scr_CheckAutoAway(TRUE); | |
1700 redrawwin(stdscr); | |
1701 case KEY_RESIZE: | |
1702 scr_Resize(); | |
1703 break; | |
1704 default: | |
1705 { | |
1706 const gchar *boundcmd = isbound(key); | |
1707 if (boundcmd) { | |
1708 gchar *cmd = g_strdup_printf("/%s", boundcmd); | |
1709 scr_CheckAutoAway(TRUE); | |
1710 if (process_command(cmd)) | |
1711 return 255; | |
1712 g_free(cmd); | |
1713 } else { | |
1714 scr_LogPrint(LPRINT_NORMAL, "Unknown key=%d", key); | |
1715 if (utf8_mode) | |
1716 scr_LogPrint(LPRINT_NORMAL, | |
1717 "WARNING: UTF-8 not yet supported!"); | |
1718 } | |
1719 } | |
1720 } | |
1721 } | |
1722 if (completion_started && key != 9 && key != KEY_RESIZE) | 1721 if (completion_started && key != 9 && key != KEY_RESIZE) |
1723 scr_end_current_completion(); | 1722 scr_end_current_completion(); |
1724 refresh_inputline(); | 1723 refresh_inputline(); |
1725 if (!update_roster) | 1724 if (!update_roster) |
1726 doupdate(); | 1725 doupdate(); |