From 82e2824891d3aa0a9d95c8266810ea5ddbd09210 Mon Sep 17 00:00:00 2001 From: jstenar <> Date: Mon, 7 Jan 2008 18:46:56 +0000 Subject: [PATCH] pyreadline: Added code to make interoperability with emacs work again. --- doc/ChangeLog | 4 ++++ pyreadline/console/console.py | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 8a30b3f..95bbae0 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-01-07 Jörgen Stenarson + * Reintroduced code to make pyreadline work with emacs. Not tested. + Requested by Frank Wang. + 2008-01-04 Jörgen Stenarson * Chunking calls to WriteConsoleW to ensure not exceeding 64k limit diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index 24afdf3..413b7d9 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -13,7 +13,7 @@ This was modeled after the C extension of the same name by Fredrik Lundh. # primitive debug printing that won't interfere with the screen -import sys +import sys,os import traceback import re from pyreadline.logger import log,log_sock @@ -145,6 +145,7 @@ funcs = [ 'SetConsoleWindowInfo', 'WriteConsoleW', 'WriteConsoleOutputCharacterW', + 'WriteFile', ] # I don't want events for these keys, they are just a bother for my application @@ -345,7 +346,6 @@ class Console(object): self.WriteConsoleW(self.hout, short_chunk, len(short_chunk), byref(junk), None) return n - def write_plain(self, text, attr=None): '''write text at current cursor position.''' log('write("%s", %s)' %(text,attr)) @@ -357,6 +357,15 @@ class Console(object): self.WriteConsoleW(self.hout, ensure_unicode(short_chunk), len(short_chunk), byref(junk), None) return len(text) + #This function must be used to ensure functioning with EMACS + #Emacs sets the EMACS environment variable + if os.environ.has_key("EMACS"): + def write_color(self, text, attr=None): + junk = c_int(0) + self.WriteFile(self.hout, text, len(text), byref(junk),None) + return len(text) + write_plain = write_color + # make this class look like a file object def write(self, text): log('write("%s")' % text)