Mercurial > hg
comparison mcabber/src/screen.c @ 759:a681dc477c7f
Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 17 Mar 2006 17:14:14 +0100 |
parents | 402b0e288433 |
children | 715952c2f37f |
comparison
equal
deleted
inserted
replaced
758:402b0e288433 | 759:a681dc477c7f |
---|---|
1608 char *c, *old = ptr_inputline; | 1608 char *c, *old = ptr_inputline; |
1609 int spaceallowed = 1; | 1609 int spaceallowed = 1; |
1610 | 1610 |
1611 if (ptr_inputline == inputLine) return; | 1611 if (ptr_inputline == inputLine) return; |
1612 | 1612 |
1613 for (c = ptr_inputline-1 ; c > inputLine ; c--) | 1613 for (c = ptr_inputline-1 ; c > inputLine ; c--) { |
1614 if (!isalnum(*c)) { | 1614 if (!isalnum(*c)) { |
1615 if (*c == ' ') | 1615 if (*c == ' ') |
1616 if (!spaceallowed) break; | 1616 if (!spaceallowed) break; |
1617 } else spaceallowed = 0; | 1617 } else spaceallowed = 0; |
1618 } | |
1618 | 1619 |
1619 if (c != inputLine || *c != ' ') | 1620 if (c != inputLine || *c != ' ') |
1620 if ((c < ptr_inputline-1) && (!isalnum(*c))) | 1621 if ((c < ptr_inputline-1) && (!isalnum(*c))) |
1621 c++; | 1622 c++; |
1622 | 1623 |
1625 for (;;) { | 1626 for (;;) { |
1626 *c = *old++; | 1627 *c = *old++; |
1627 if (!*c++) break; | 1628 if (!*c++) break; |
1628 } | 1629 } |
1629 check_offset(-1); | 1630 check_offset(-1); |
1631 } | |
1632 | |
1633 // readline_backward_word() | |
1634 // Move back to the start of the current or previous word | |
1635 void readline_backward_word() | |
1636 { | |
1637 char *old_ptr_inputLine = ptr_inputline; | |
1638 int spaceallowed = 1; | |
1639 | |
1640 if (ptr_inputline == inputLine) return; | |
1641 | |
1642 for (ptr_inputline-- ; ptr_inputline > inputLine ; ptr_inputline--) { | |
1643 if (!isalnum(*ptr_inputline)) { | |
1644 if (*ptr_inputline == ' ') | |
1645 if (!spaceallowed) break; | |
1646 } else spaceallowed = 0; | |
1647 } | |
1648 | |
1649 if (ptr_inputline < old_ptr_inputLine-1 | |
1650 && *ptr_inputline == ' ' && *(ptr_inputline+1) != ' ') | |
1651 ptr_inputline++; | |
1652 | |
1653 check_offset(-1); | |
1654 } | |
1655 | |
1656 // readline_forward_word() | |
1657 // Move forward to the end of the next word | |
1658 void readline_forward_word() | |
1659 { | |
1660 int spaceallowed = 1; | |
1661 | |
1662 while (*ptr_inputline) { | |
1663 ptr_inputline++; | |
1664 if (!isalnum(*ptr_inputline)) { | |
1665 if (*ptr_inputline == ' ') | |
1666 if (!spaceallowed) break; | |
1667 } else spaceallowed = 0; | |
1668 } | |
1669 | |
1670 check_offset(1); | |
1630 } | 1671 } |
1631 | 1672 |
1632 // which_row() | 1673 // which_row() |
1633 // Tells which row our cursor is in, in the command line. | 1674 // Tells which row our cursor is in, in the command line. |
1634 // -2 -> normal text | 1675 // -2 -> normal text |
1971 case 20: // Ctrl-t | 2012 case 20: // Ctrl-t |
1972 readline_transpose_chars(); | 2013 readline_transpose_chars(); |
1973 break; | 2014 break; |
1974 case 23: // Ctrl-w | 2015 case 23: // Ctrl-w |
1975 readline_backward_kill_word(); | 2016 readline_backward_kill_word(); |
2017 break; | |
2018 case 516: // Ctrl-Left | |
2019 readline_backward_word(); | |
2020 break; | |
2021 case 518: // Ctrl-Right | |
2022 readline_forward_word(); | |
1976 break; | 2023 break; |
1977 case 12: // Ctrl-l | 2024 case 12: // Ctrl-l |
1978 scr_CheckAutoAway(TRUE); | 2025 scr_CheckAutoAway(TRUE); |
1979 scr_Resize(); | 2026 scr_Resize(); |
1980 redrawwin(stdscr); | 2027 redrawwin(stdscr); |