|
45 | 45 | import pydoc |
46 | 46 | import types |
47 | 47 | import unicodedata |
48 | | -from itertools import chain |
49 | 48 | from cStringIO import StringIO |
50 | 49 | from locale import LC_ALL, getpreferredencoding, setlocale |
51 | 50 | from optparse import OptionParser |
@@ -325,6 +324,7 @@ def __init__(self, scr, interp, statusbar=None, idle=None): |
325 | 324 | sys.stdin = FakeStdin(self) |
326 | 325 | self.paste_mode = False |
327 | 326 | self.last_key_press = time.time() |
| 327 | + self.paste_time = 0.02 |
328 | 328 | sys.path.insert(0, '.') |
329 | 329 |
|
330 | 330 | if not OPTS.arg_spec: |
@@ -525,7 +525,8 @@ def check(self): |
525 | 525 | """Check if paste mode should still be active and, if not, deactivate |
526 | 526 | it and force syntax highlighting.""" |
527 | 527 |
|
528 | | - if self.paste_mode and time.time() - self.last_key_press > 0.01: |
| 528 | + if (self.paste_mode |
| 529 | + and time.time() - self.last_key_press > self.paste_time): |
529 | 530 | self.paste_mode = False |
530 | 531 | self.print_line(self.s) |
531 | 532 |
|
@@ -818,7 +819,11 @@ def write2file(self): |
818 | 819 | """Prompt for a filename and write the current contents of the stdout |
819 | 820 | buffer to disk.""" |
820 | 821 |
|
821 | | - fn = self.statusbar.prompt('Save to file: ') |
| 822 | + try: |
| 823 | + fn = self.statusbar.prompt('Save to file (Esc to cancel): ') |
| 824 | + except ValueError: |
| 825 | + self.statusbar.message("Save cancelled.") |
| 826 | + return |
822 | 827 |
|
823 | 828 | if fn.startswith('~'): |
824 | 829 | fn = os.path.expanduser(fn) |
@@ -1614,7 +1619,7 @@ def get_key(self): |
1614 | 1619 | return key |
1615 | 1620 | else: |
1616 | 1621 | t = time.time() |
1617 | | - self.paste_mode = (t - self.last_key_press <= 0.01) |
| 1622 | + self.paste_mode = (t - self.last_key_press <= self.paste_time) |
1618 | 1623 | self.last_key_press = t |
1619 | 1624 | return key |
1620 | 1625 | finally: |
@@ -1722,14 +1727,17 @@ def bs(s): |
1722 | 1727 | o = bs(o) |
1723 | 1728 | continue |
1724 | 1729 |
|
| 1730 | + if c == 27: |
| 1731 | + raise ValueError |
| 1732 | + |
1725 | 1733 | if not c or c < 0 or c > 127: |
1726 | 1734 | continue |
1727 | 1735 | c = chr(c) |
1728 | 1736 |
|
1729 | 1737 | if c == '\n': |
1730 | 1738 | break |
1731 | 1739 |
|
1732 | | - self.win.addstr(c) |
| 1740 | + self.win.addstr(c, get_colpair('prompt')) |
1733 | 1741 | o += c |
1734 | 1742 |
|
1735 | 1743 | self.settext(self._s) |
@@ -1825,7 +1833,7 @@ def idle(caller): |
1825 | 1833 |
|
1826 | 1834 | global stdscr |
1827 | 1835 |
|
1828 | | - if importcompletion.find_coroutine(): |
| 1836 | + if importcompletion.find_coroutine() or caller.paste_mode: |
1829 | 1837 | stdscr.nodelay(True) |
1830 | 1838 | key = stdscr.getch() |
1831 | 1839 | stdscr.nodelay(False) |
@@ -1903,6 +1911,7 @@ def main_curses(scr): |
1903 | 1911 |
|
1904 | 1912 | scr.timeout(300) |
1905 | 1913 |
|
| 1914 | + curses.raw(True) |
1906 | 1915 | main_win, statusbar = init_wins(scr, cols) |
1907 | 1916 |
|
1908 | 1917 | curses.raw(True) |
|
0 commit comments