Author: Ronny Pfannschmidt <[email protected]>
Branch: codecheck-clean
Changeset: r236:38d594adcc53
Date: 2013-02-25 09:20 +0100
http://bitbucket.org/pypy/pyrepl/changeset/38d594adcc53/
Log: more simple cleanups
diff --git a/pyrepl/fancy_termios.py b/pyrepl/fancy_termios.py
--- a/pyrepl/fancy_termios.py
+++ b/pyrepl/fancy_termios.py
@@ -19,10 +19,12 @@
import termios
+
class TermState:
def __init__(self, tuples):
self.iflag, self.oflag, self.cflag, self.lflag, \
- self.ispeed, self.ospeed, self.cc = tuples
+ self.ispeed, self.ospeed, self.cc = tuples
+
def as_list(self):
return [self.iflag, self.oflag, self.cflag, self.lflag,
self.ispeed, self.ospeed, self.cc]
@@ -30,23 +32,30 @@
def copy(self):
return self.__class__(self.as_list())
+
def tcgetattr(fd):
return TermState(termios.tcgetattr(fd))
+
def tcsetattr(fd, when, attrs):
termios.tcsetattr(fd, when, attrs.as_list())
+
class Term(TermState):
+ #XXX: fix this mess
TS__init__ = TermState.__init__
+
def __init__(self, fd=0):
self.TS__init__(termios.tcgetattr(fd))
self.fd = fd
self.stack = []
+
def save(self):
- self.stack.append( self.as_list() )
+ self.stack.append(self.as_list())
+
def set(self, when=termios.TCSANOW):
termios.tcsetattr(self.fd, when, self.as_list())
+
def restore(self):
self.TS__init__(self.stack.pop())
self.set()
-
diff --git a/pyrepl/historical_reader.py b/pyrepl/historical_reader.py
--- a/pyrepl/historical_reader.py
+++ b/pyrepl/historical_reader.py
@@ -17,15 +17,15 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from pyrepl import reader, commands
+from pyrepl import commands
from pyrepl.reader import Reader as R
isearch_keymap = tuple(
- [('\\%03o'%c, 'isearch-end') for c in range(256) if chr(c) != '\\'] + \
+ [('\\%03o' % c, 'isearch-end') for c in range(256) if chr(c) != '\\'] +
[(c, 'isearch-add-character')
- for c in map(chr, range(32, 127)) if c != '\\'] + \
- [('\\%03o'%c, 'isearch-add-character')
- for c in range(256) if chr(c).isalpha() and chr(c) != '\\'] + \
+ for c in map(chr, range(32, 127)) if c != '\\'] +
+ [('\\%03o' % c, 'isearch-add-character')
+ for c in range(256) if chr(c).isalpha() and chr(c) != '\\'] +
[('\\\\', 'self-insert'),
(r'\C-r', 'isearch-backwards'),
(r'\C-s', 'isearch-forwards'),
@@ -40,6 +40,7 @@
ISEARCH_DIRECTION_BACKWARDS = 'r'
ISEARCH_DIRECTION_FORWARDS = 'f'
+
class next_history(commands.Command):
def do(self):
r = self.reader
@@ -48,6 +49,7 @@
return
r.select_item(r.historyi + 1)
+
class previous_history(commands.Command):
def do(self):
r = self.reader
@@ -56,6 +58,7 @@
return
r.select_item(r.historyi - 1)
+
class restore_history(commands.Command):
def do(self):
r = self.reader
@@ -65,18 +68,22 @@
r.pos = len(r.buffer)
r.dirty = 1
+
class first_history(commands.Command):
def do(self):
self.reader.select_item(0)
+
class last_history(commands.Command):
def do(self):
self.reader.select_item(len(self.reader.history))
+
class operate_and_get_next(commands.FinishCommand):
def do(self):
self.reader.next_history = self.reader.historyi + 1
+
class yank_arg(commands.Command):
def do(self):
r = self.reader
@@ -104,6 +111,7 @@
r.pos += len(w) - o
r.dirty = 1
+
class forward_history_isearch(commands.Command):
def do(self):
r = self.reader
@@ -112,7 +120,7 @@
r.isearch_term = ''
r.dirty = 1
r.push_input_trans(r.isearch_trans)
-
+
class reverse_history_isearch(commands.Command):
def do(self):
@@ -123,6 +131,7 @@
r.push_input_trans(r.isearch_trans)
r.isearch_start = r.historyi, r.pos
+
class isearch_cancel(commands.Command):
def do(self):
r = self.reader
@@ -132,6 +141,7 @@
r.pos = r.isearch_start[1]
r.dirty = 1
+
class isearch_add_character(commands.Command):
def do(self):
r = self.reader
@@ -139,9 +149,10 @@
r.isearch_term += self.event[-1]
r.dirty = 1
p = r.pos + len(r.isearch_term) - 1
- if b[p:p+1] != [r.isearch_term[-1]]:
+ if b[p:p + 1] != [r.isearch_term[-1]]:
r.isearch_next()
+
class isearch_backspace(commands.Command):
def do(self):
r = self.reader
@@ -151,18 +162,21 @@
else:
r.error("nothing to rubout")
+
class isearch_forwards(commands.Command):
def do(self):
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_FORWARDS
r.isearch_next()
+
class isearch_backwards(commands.Command):
def do(self):
r = self.reader
r.isearch_direction = ISEARCH_DIRECTION_BACKWARDS
r.isearch_next()
+
class isearch_end(commands.Command):
def do(self):
r = self.reader
@@ -171,6 +185,7 @@
r.pop_input_trans()
r.dirty = 1
+
class HistoricalReader(R):
"""Adds history support (with incremental history searching) to the
Reader class.
@@ -199,7 +214,6 @@
(r'\<page down>', 'last-history'),
(r'\<page up>', 'first-history'))
-
def __init__(self, console):
super(HistoricalReader, self).__init__(console)
self.history = []
@@ -219,7 +233,7 @@
self.isearch_trans = input.KeymapTranslator(
isearch_keymap, invalid_cls=isearch_end,
character_cls=isearch_add_character)
-
+
def select_item(self, i):
self.transient_history[self.historyi] = self.get_unicode()
buf = self.transient_history.get(i)
@@ -240,8 +254,8 @@
super(HistoricalReader, self).prepare()
try:
self.transient_history = {}
- if self.next_history is not None \
- and self.next_history < len(self.history):
+ if self.next_history is not None and \
+ self.next_history < len(self.history):
self.historyi = self.next_history
self.buffer[:] = list(self.history[self.next_history])
self.pos = len(self.buffer)
@@ -256,9 +270,8 @@
def get_prompt(self, lineno, cursor_on_line):
if cursor_on_line and self.isearch_direction != ISEARCH_DIRECTION_NONE:
d = 'rf'[self.isearch_direction == ISEARCH_DIRECTION_FORWARDS]
- return "(%s-search `%s') "%(d, self.isearch_term)
- else:
- return super(HistoricalReader, self).get_prompt(lineno,
cursor_on_line)
+ return "(%s-search `%s') " % (d, self.isearch_term)
+ return super(HistoricalReader, self).get_prompt(lineno, cursor_on_line)
def isearch_next(self):
st = self.isearch_term
@@ -298,6 +311,7 @@
if ret:
self.history.append(ret)
+
def test():
from pyrepl.unix_console import UnixConsole
reader = HistoricalReader(UnixConsole())
@@ -308,5 +322,5 @@
while reader.readline():
pass
-if __name__=='__main__':
+if __name__ == '__main__':
test()
diff --git a/pyrepl/input.py b/pyrepl/input.py
--- a/pyrepl/input.py
+++ b/pyrepl/input.py
@@ -40,8 +40,10 @@
class InputTranslator(object):
def push(self, evt):
pass
+
def get(self):
pass
+
def empty(self):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit