Commits

nakamura committed 0856dff

press Enter to restart command

Comments (0)

Files changed (1)

 and send keyboard input for all/some/one terminal.
 """
 
+import gobject
 import os
 
 from gi.repository import Gtk
         super(TerminalFrame, self).__init__()
         self.set_border_width(1)
 
+        self._command = command
+
         self._hbox = Gtk.HBox()
         self.pack_start(self._hbox, False, False, 0)
 
         self._sync_check.connect('button-release-event',
                                  lambda *_: self.terminal.grab_focus())
 
-        # TODO: "press Enter to restert command"
+        self.terminal.connect('child-exited', self.do_terminal_child_exited)
+
         # TODO: provide keyboard shortcut to toggle sync check button
 
     @property
         self._sync_check.set_active(not self._sync_check.get_active())
         self.terminal.grab_focus()
 
+    def do_terminal_child_exited(self, *args):
+        self._sync_check.set_active(False)
+        msg = '\n[Press Enter to restart command]'
+        self.terminal.feed(msg, len(msg))
+        self.terminal.connect('commit', self.do_terminal_commit)
+
+    def do_terminal_commit(self, term, text, length):
+        if text in ('\n', '\r', '\r\n'):
+            self.terminal.disconnect_by_func(self.do_terminal_commit)
+            self.terminal.feed('\r\n', 2)
+            self._sync_check.set_active(True)
+
+            # to avoid this input being feeded to this command,
+            # call run_command after this callback
+            gobject.timeout_add(0, self.terminal.run_command, self._command)
+
+            return True
+
 
 class Config(object):
     def __init__(self, **kwargs):