5858# This for keys
5959from bpython .keys import key_dispatch
6060
61+ from bpython import repl
6162from bpython .pager import page
62- from bpython .repl import Interpreter , Repl
6363import bpython .args
6464
6565
@@ -233,10 +233,25 @@ def make_colors(config):
233233 return c
234234
235235
236- class CLIRepl (Repl ):
236+ class CLIInteraction (repl .Interaction ):
237+ def __init__ (self , config , statusbar = None ):
238+ repl .Interaction .__init__ (self , config , statusbar )
239+
240+ def confirm (self , q ):
241+ """Ask for yes or no and return boolean"""
242+ return self .statusbar .prompt (q ).lower ().startswith ('y' )
243+
244+ def notify (self , s , n = 10 ):
245+ return self .statusbar .message (s , n )
246+
247+ def file_prompt (self , s ):
248+ return self .statusbar .prompt (s )
249+
250+
251+ class CLIRepl (repl .Repl ):
237252
238253 def __init__ (self , scr , interp , statusbar , config , idle = None ):
239- Repl .__init__ (self , interp , config )
254+ repl . Repl .__init__ (self , interp , config )
240255 interp .writetb = self .writetb
241256 self .scr = scr
242257 self .stdout_hist = ''
@@ -251,6 +266,7 @@ def __init__(self, scr, interp, statusbar, config, idle=None):
251266 self .s = ''
252267 self .statusbar = statusbar
253268 self .formatter = BPythonFormatter (config .color_scheme )
269+ self .interact = CLIInteraction (self .config , statusbar = self .statusbar )
254270
255271 def addstr (self , s ):
256272 """Add a string to the current input line and figure out
@@ -334,7 +350,7 @@ def clear_current_line(self):
334350 """Called when a SyntaxError occured in the interpreter. It is
335351 used to prevent autoindentation from occuring after a
336352 traceback."""
337- Repl .clear_current_line (self )
353+ repl . Repl .clear_current_line (self )
338354 self .s = ''
339355
340356 def clear_wrapped_lines (self ):
@@ -359,7 +375,7 @@ def complete(self, tab=False):
359375 return
360376
361377 if self .config .auto_display_list or tab :
362- self .list_win_visible = Repl .complete (self , tab )
378+ self .list_win_visible = repl . Repl .complete (self , tab )
363379 if self .list_win_visible :
364380 try :
365381 self .show_list (self .matches , self .argspec )
@@ -900,7 +916,7 @@ def push(self, s, insert_into_history=True):
900916 # curses.raw(True) prevents C-c from causing a SIGINT
901917 curses .raw (False )
902918 try :
903- return Repl .push (self , s , insert_into_history )
919+ return repl . Repl .push (self , s , insert_into_history )
904920 except SystemExit :
905921 # Avoid a traceback on e.g. quit()
906922 self .do_exit = True
@@ -998,10 +1014,7 @@ def resize(self):
9981014 self .statusbar .resize (refresh = False )
9991015 self .redraw ()
10001016
1001- def ask_confirmation (self , q ):
1002- """Ask for yes or no and return boolean"""
1003- return self .statusbar .prompt (q ).lower ().startswith ('y' )
1004-
1017+
10051018 def getstdout (self ):
10061019 """This method returns the 'spoofed' stdout buffer, for writing to a
10071020 file or sending to a pastebin or whatever."""
@@ -1293,7 +1306,7 @@ def tab(self, back=False):
12931306 return True
12941307
12951308 def undo (self , n = 1 ):
1296- Repl .undo (self , n )
1309+ repl . Repl .undo (self , n )
12971310
12981311 # This will unhighlight highlighted parens
12991312 self .print_line (self .s )
@@ -1613,6 +1626,7 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
16131626 global stdscr
16141627 global DO_RESIZE
16151628 global colors
1629+ global repl
16161630 DO_RESIZE = False
16171631
16181632 old_sigwinch_handler = signal .signal (signal .SIGWINCH ,
@@ -1639,10 +1653,10 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
16391653 if locals_ is None :
16401654 sys .modules ['__main__' ] = ModuleType ('__main__' )
16411655 locals_ = sys .modules ['__main__' ].__dict__
1642- interpreter = Interpreter (locals_ , getpreferredencoding ())
1656+ interpreter = repl . Interpreter (locals_ , getpreferredencoding ())
16431657
1644- repl = CLIRepl (main_win , interpreter , statusbar , config , idle )
1645- repl ._C = cols
1658+ clirepl = CLIRepl (main_win , interpreter , statusbar , config , idle )
1659+ clirepl ._C = cols
16461660
16471661 sys .stdin = FakeStdin (repl )
16481662 sys .stdout = repl
@@ -1652,18 +1666,18 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
16521666 bpython .args .exec_code (interpreter , args )
16531667 if not interactive :
16541668 curses .raw (False )
1655- return repl .getstdout ()
1669+ return clirepl .getstdout ()
16561670 else :
16571671 sys .path .insert (0 , '' )
1658- repl .startup ()
1672+ clirepl .startup ()
16591673
16601674 if banner is not None :
1661- repl .write (banner )
1662- repl .write ('\n ' )
1663- repl .repl ()
1675+ clirepl .write (banner )
1676+ clirepl .write ('\n ' )
1677+ clirepl .repl ()
16641678 if config .hist_length :
16651679 histfilename = os .path .expanduser (config .hist_file )
1666- repl .rl_history .save (histfilename , getpreferredencoding ())
1680+ clirepl .rl_history .save (histfilename , getpreferredencoding ())
16671681
16681682 main_win .erase ()
16691683 main_win .refresh ()
0 commit comments