diff --git a/pyreadline/clipboard/__init__.py b/pyreadline/clipboard/__init__.py index 2852618..b3112bc 100644 --- a/pyreadline/clipboard/__init__.py +++ b/pyreadline/clipboard/__init__.py @@ -1,18 +1,17 @@ import sys -success=False +success=True in_ironpython="IronPython" in sys.version if in_ironpython: try: from ironpython_clipboard import GetClipboardText,SetClipboardText - success=True except ImportError: - pass + from no_clipboard import GetClipboardText,SetClipboardText + else: try: from win32_clipboard import GetClipboardText,SetClipboardText - success=True except ImportError: - raise + from no_clipboard import GetClipboardText,SetClipboardText def send_data(lists): diff --git a/pyreadline/lineeditor/history.py b/pyreadline/lineeditor/history.py index 761a8aa..10012a5 100644 --- a/pyreadline/lineeditor/history.py +++ b/pyreadline/lineeditor/history.py @@ -7,8 +7,6 @@ #***************************************************************************** import re,operator,string,sys,os -#import wordmatcher -#import pyreadline.clipboard as clipboard from pyreadline.unicode_helper import ensure_unicode,ensure_str if "pyreadline" in sys.modules: pyreadline= sys.modules["pyreadline"] diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index 7eb58b5..d16de4c 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -33,6 +33,23 @@ class BaseMode(object): self.completer = None self.begidx = 0 self.endidx = 0 + self.tabstop = 4 + self.startup_hook = None + self.pre_input_hook = None + self.first_prompt = True + + self.prompt = ">>>" + + #Paste settings + #assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n + #and replace \ with / for easier use in ipython + self.enable_ipython_paste_for_paths=True + + #automatically convert tabseparated data to list of lists or array constructors + self.enable_ipython_paste_list_of_lists=True + self.enable_win32_clipboard=True + + self.paste_line_buffer=[] def __repr__(self): return "" @@ -58,12 +75,6 @@ class BaseMode(object): #used in readline ctrl_c_tap_time_interval=property(*_gs("ctrl_c_tap_time_interval")) allow_ctrl_c=property(*_gs("allow_ctrl_c")) - next_meta=property(*_gs("next_meta")) - first_prompt=property(*_gs("first_prompt")) - prompt=property(*_gs("prompt")) - paste_line_buffer=property(*_gs("paste_line_buffer")) - startup_hook=property(*_gs("startup_hook")) - pre_input_hook=property(*_gs("pre_input_hook")) _print_prompt=property(_g("_print_prompt")) _update_line=property(_g("_update_line")) console=property(_g("console")) @@ -77,12 +88,6 @@ class BaseMode(object): _clear_after=property(_g("_clear_after")) _update_prompt_pos=property(_g("_update_prompt_pos")) - - enable_win32_clipboard=property(_g("enable_win32_clipboard")) - enable_ipython_paste_list_of_lists=property(_g("enable_ipython_paste_list_of_lists")) - enable_ipython_paste_for_paths=property(_g("enable_ipython_paste_for_paths")) - - #not used in basemode or emacs def readline_event_available(self): @@ -109,10 +114,6 @@ class BaseMode(object): except KeyboardInterrupt: event=self.handle_ctrl_c() - if self.next_meta: - self.next_meta = False - control, meta, shift, code = event.keyinfo - event.keyinfo = (control, True, shift, code) result=self.process_keyevent(event.keyinfo) self._update_line() return result diff --git a/pyreadline/modes/emacs.py b/pyreadline/modes/emacs.py index 116c9df..9a407e1 100644 --- a/pyreadline/modes/emacs.py +++ b/pyreadline/modes/emacs.py @@ -34,6 +34,7 @@ class EmacsMode(basemode.BaseMode): self.previous_func=None self.prompt=">>>" self._insert_verbatim=False + self.next_meta = False # True to force meta on next character def __repr__(self): return "" @@ -48,6 +49,9 @@ class EmacsMode(basemode.BaseMode): #Process exit keys. Only exit on empty line def nop(e): pass + if self.next_meta: + self.next_meta = False + keyinfo.meta=True keytuple=keyinfo.tuple() if self._insert_verbatim: @@ -224,7 +228,7 @@ class EmacsMode(basemode.BaseMode): def tab_insert(self, e): # (M-TAB) '''Insert a tab character. ''' - ws = ' ' * (self.tabstop - (self.line_cursor%self.tabstop)) + ws = ' ' * (self.tabstop - (self.l_buffer.point%self.tabstop)) self.insert_text(ws) def transpose_chars(self, e): # (C-t) diff --git a/pyreadline/modes/vi.py b/pyreadline/modes/vi.py index a8102ba..d6710ac 100644 --- a/pyreadline/modes/vi.py +++ b/pyreadline/modes/vi.py @@ -112,8 +112,6 @@ class ViMode(basemode.BaseMode): else: self._vi_command = ViCommand (self) self.vi_set_insert_mode (False) -# if self.line_cursor > 0: -# self.line_cursor -= 1 self.l_buffer.point=lineobj.PrevChar elif self._vi_command and self._vi_command.is_replace_one: self._vi_command.add_char (e.char) @@ -358,7 +356,7 @@ class ViCommand: if char == '\x1b': # escape self.escape (char) elif char == '\x09': # tab - ts = self.readline.tabstop + ts = self.tabstop ws = ' ' * (ts - (self.readline.l_buffer.point%ts)) self.set_text (ws) elif char == '\x08': # backspace diff --git a/pyreadline/rlmain.py b/pyreadline/rlmain.py index 44a59c4..58cec4c 100644 --- a/pyreadline/rlmain.py +++ b/pyreadline/rlmain.py @@ -40,8 +40,6 @@ def inword(buffer,point): class Readline(object): def __init__(self): - self.startup_hook = None - self.pre_input_hook = None self.console = console.Console() self.size = self.console.size() self.prompt_color = None @@ -49,9 +47,7 @@ class Readline(object): self.selection_color = self.console.saveattr<<4 self.key_dispatch = {} self.previous_func = None - self.first_prompt = True - self.next_meta = False # True to force meta on next character - self.tabstop = 4 + self.allow_ctrl_c=False self.ctrl_c_tap_time_interval=0.3 self.debug=False @@ -69,34 +65,8 @@ class Readline(object): self.read_inputrc() log("\n".join(self.mode.rl_settings_to_string())) - #Paste settings - #assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n - #and replace \ with / for easier use in ipython - self.enable_ipython_paste_for_paths=True - - #automatically convert tabseparated data to list of lists or array constructors - self.enable_ipython_paste_list_of_lists=True - self.enable_win32_clipboard=True - - self.paste_line_buffer=[] self.callback = None - #Below is for refactoring, raise errors when using old style attributes - #that should be refactored out - def _g(x): - def g(self): - raise GetSetError("GET %s"%x) - def s(self,q): - raise GetSetError("SET %s"%x) - return g,s - line_buffer=property(*_g("line_buffer")) - line_cursor=property(*_g("line_buffer")) - undo_stack =property(*_g("undo_stack")) # each entry is a tuple with cursor_position and line_text - history_length =property(*_g("history_length")) # each entry is a tuple with cursor_position and line_text - history =property(*_g("history")) # each entry is a tuple with cursor_position and line_text - history_cursor =property(*_g("history_cursor")) # each entry is a tuple with cursor_position and line_text - - # To export as readline interface def parse_and_bind(self, string): @@ -134,6 +104,15 @@ class Readline(object): log('error') raise + def _set_prompt(self, prompt): + self.mode.prompt=prompt + + def _get_prompt(self): + return self.mode.prompt + + prompt=property(_get_prompt, _set_prompt) + + def get_line_buffer(self): '''Return the current contents of the line buffer.''' return self.mode.l_buffer.get_line_text() @@ -228,7 +207,7 @@ class Readline(object): before readline prints the first prompt. ''' - self.startup_hook = function + self.mode.startup_hook = function def set_pre_input_hook(self, function=None): '''Set or remove the pre_input_hook function. @@ -240,7 +219,7 @@ class Readline(object): starts reading input characters. ''' - self.pre_input_hook = function + self.mode.pre_input_hook = function ## Internal functions