diff options
-rw-r--r-- | saneterm/pty.py | 4 | ||||
-rw-r--r-- | saneterm/terminal.py | 6 | ||||
-rw-r--r-- | saneterm/termview.py | 18 |
3 files changed, 10 insertions, 18 deletions
diff --git a/saneterm/pty.py b/saneterm/pty.py index d294770..7f9995a 100644 --- a/saneterm/pty.py +++ b/saneterm/pty.py @@ -43,7 +43,6 @@ class EventType(Enum): TEXT = auto() BELL = auto() CARRIAGE_RETURN = auto() - NEWLINE = auto() class Parser(object): """ @@ -98,9 +97,6 @@ class Parser(object): if code == '\a': flush_until = pos special_ev = (EventType.BELL, None) - elif code == '\n': - flush_until = pos - special_ev = (EventType.NEWLINE, None) elif code == '\r': flush_until = pos special_ev = (EventType.CARRIAGE_RETURN, None) diff --git a/saneterm/terminal.py b/saneterm/terminal.py index 41044b4..00eb022 100644 --- a/saneterm/terminal.py +++ b/saneterm/terminal.py @@ -168,12 +168,8 @@ class Terminal(Gtk.Window): for (ev, data) in self.pty_parser.parse(decoded): if ev is pty.EventType.TEXT: self.termview.insert_data(data) - elif ev is pty.EventType.NEWLINE: - self.termview.set_replace(False) - self.termview.insert_data("\n") elif ev is pty.EventType.CARRIAGE_RETURN: - self.termview.goto_line_start() - self.termview.set_replace(True) + self.termview.replace_line() elif ev is pty.EventType.BELL: self.termview.error_bell() self.set_urgency_hint(True) diff --git a/saneterm/termview.py b/saneterm/termview.py index 0d48b66..6823962 100644 --- a/saneterm/termview.py +++ b/saneterm/termview.py @@ -124,20 +124,20 @@ class TermView(Gtk.TextView): def insert_data(self, str): if self.__replace: - self.do_delete_from_cursor(Gtk.DeleteType.CHARS, len(str)) - self._textbuffer.insert(self._textbuffer.get_end_iter(), str) + insert = self._textbuffer.get_iter_at_mark(self._textbuffer.get_insert()) + if insert.ends_line(): + self.__replace = False + else: + self.do_delete_from_cursor(Gtk.DeleteType.CHARS, len(str)) + self._textbuffer.insert_at_cursor(str) end = self._textbuffer.get_end_iter() self._last_mark = self._textbuffer.create_mark(None, end, True) self._last_output_mark = self._last_mark - def set_replace(self, value): - self.__replace = value - if not value: # FIXME - buffer = self.get_buffer() - buffer.place_cursor(buffer.get_end_iter()) - - def goto_line_start(self): + def replace_line(self): + """Start replacing the current line and turn off replace mode when + the end of the line is reached, useful for implementing \r.""" buffer = self.get_buffer() lstart = buffer.get_end_iter() |