mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-24 13:10:49 +08:00
pyreadline-refactor: Fix buggy get_begidx and get_endidx. Ensure unicode can print in write_x methods on Console.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -22,7 +22,7 @@ name = 'pyreadline'
|
||||
|
||||
branch = 'refactor'
|
||||
|
||||
version = 'refactor'
|
||||
version = '1.4.svn'
|
||||
|
||||
revision = '$Revision$'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user