diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index b944254..562dc21 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -19,7 +19,6 @@ import re from pyreadline.logger import log,log_sock try: - # I developed this with ctypes 0.6 from ctypes import * from _ctypes import call_function except ImportError: @@ -116,6 +115,13 @@ class CONSOLE_CURSOR_INFO(Structure): _fields_ = [("dwSize", c_int), ("bVisible", c_byte)] +consolecodepage=sys.stdout.encoding +def ensure_text(text): + """helper to ensure that text passed to WriteConsoleA is ascii""" + if isinstance(text, unicode): + return text.encode(consolecodepage,"replace") + return text + # I didn't want to have to individually import these so I made a list, they are # added to the Console class later in this file. @@ -347,7 +353,7 @@ class Console(object): if attr is None: attr = self.attr self.SetConsoleTextAttribute(self.hout, attr) - self.WriteConsoleA(self.hout, chunk, len(chunk), byref(junk), None) + self.WriteConsoleA(self.hout, ensure_text(chunk), len(chunk), byref(junk), None) return n def write_color(self, text, attr=None): @@ -357,7 +363,7 @@ class Console(object): log(str(attr)) log(str(chunk)) self.SetConsoleTextAttribute(self.hout, attr.winattr) - self.WriteConsoleA(self.hout, chunk, len(chunk), byref(junk), None) + self.WriteConsoleA(self.hout, ensure_text(chunk), len(chunk), byref(junk), None) return n @@ -368,7 +374,7 @@ class Console(object): attr = self.attr n = c_int(0) self.SetConsoleTextAttribute(self.hout, attr) - self.WriteConsoleA(self.hout, text, len(text), byref(n), None) + self.WriteConsoleA(self.hout, ensure_text(chunk), len(chunk), byref(junk), None) return len(text) # make this class look like a file object diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index 6ec17dd..aaa7642 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -58,6 +58,8 @@ class BaseMode(object): show_all_if_ambiguous=property(*_gs("show_all_if_ambiguous")) mark_directories=property(*_gs("mark_directories")) completer=property(*_gs("completer")) + begidx=property(*_gs("begidx")) + endidx=property(*_gs("endidx")) console=property(_g("console")) insert_text=property(_g("insert_text")) diff --git a/pyreadline/release.py b/pyreadline/release.py index df18c1f..f3c7026 100644 --- a/pyreadline/release.py +++ b/pyreadline/release.py @@ -22,7 +22,7 @@ name = 'pyreadline' branch = 'refactor' -version = 'refactor' +version = '1.4.svn' revision = '$Revision$'