Skip to content

Commit 3940fe9

Browse files
committed
fix bug in theme loading, add "cancel" option to save, and make filename input
for save use a colour
1 parent 4e90ea4 commit 3940fe9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

bpython/cli.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import pydoc
4646
import types
4747
import unicodedata
48-
from itertools import chain
4948
from cStringIO import StringIO
5049
from locale import LC_ALL, getpreferredencoding, setlocale
5150
from optparse import OptionParser
@@ -325,6 +324,7 @@ def __init__(self, scr, interp, statusbar=None, idle=None):
325324
sys.stdin = FakeStdin(self)
326325
self.paste_mode = False
327326
self.last_key_press = time.time()
327+
self.paste_time = 0.02
328328
sys.path.insert(0, '.')
329329

330330
if not OPTS.arg_spec:
@@ -525,7 +525,8 @@ def check(self):
525525
"""Check if paste mode should still be active and, if not, deactivate
526526
it and force syntax highlighting."""
527527

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):
529530
self.paste_mode = False
530531
self.print_line(self.s)
531532

@@ -818,7 +819,11 @@ def write2file(self):
818819
"""Prompt for a filename and write the current contents of the stdout
819820
buffer to disk."""
820821

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
822827

823828
if fn.startswith('~'):
824829
fn = os.path.expanduser(fn)
@@ -1614,7 +1619,7 @@ def get_key(self):
16141619
return key
16151620
else:
16161621
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)
16181623
self.last_key_press = t
16191624
return key
16201625
finally:
@@ -1722,14 +1727,17 @@ def bs(s):
17221727
o = bs(o)
17231728
continue
17241729

1730+
if c == 27:
1731+
raise ValueError
1732+
17251733
if not c or c < 0 or c > 127:
17261734
continue
17271735
c = chr(c)
17281736

17291737
if c == '\n':
17301738
break
17311739

1732-
self.win.addstr(c)
1740+
self.win.addstr(c, get_colpair('prompt'))
17331741
o += c
17341742

17351743
self.settext(self._s)
@@ -1825,7 +1833,7 @@ def idle(caller):
18251833

18261834
global stdscr
18271835

1828-
if importcompletion.find_coroutine():
1836+
if importcompletion.find_coroutine() or caller.paste_mode:
18291837
stdscr.nodelay(True)
18301838
key = stdscr.getch()
18311839
stdscr.nodelay(False)
@@ -1903,6 +1911,7 @@ def main_curses(scr):
19031911

19041912
scr.timeout(300)
19051913

1914+
curses.raw(True)
19061915
main_win, statusbar = init_wins(scr, cols)
19071916

19081917
curses.raw(True)

bpython/config.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
3+
from itertools import chain
34

45

56
class Struct(object):
@@ -64,11 +65,7 @@ def loadini(struct, configfile):
6465
}
6566
else:
6667
path = os.path.expanduser('~/.bpython/%s.theme' % (color_scheme_name,))
67-
# XXX ConfigParser doesn't raise an IOError if it tries to read a file
68-
# that doesn't exist which isn't helpful to us:
69-
if not os.path.isfile(path):
70-
raise IOError("'%s' is not a readable file" % (path,))
71-
load_theme(struct, color_scheme_name)
68+
load_theme(struct, path)
7269

7370

7471
def load_theme(struct, path):

0 commit comments

Comments
 (0)