Patchwork oe.terminal: add tmux classes

login
register
mail settings
Submitter Christopher Larson
Date April 4, 2013, 6:41 p.m.
Message ID <1365100897-14142-1-git-send-email-kergoth@gmail.com>
Download mbox | patch
Permalink /patch/47435/
State New
Headers show

Comments

Christopher Larson - April 4, 2013, 6:41 p.m.
From: Christopher Larson <chris_larson@mentor.com>

This adds two new Terminal classes. It's separated into two, so that opening
a split inside a tmux window is preferred to the other terminal types, but
opening a tmux session is prioritized only slightly higher than screen.

- tmuxrunning: Open a new pane in the current running tmux window. Requires
  that the TMUX variable be added to the env whitelist to use it.
- tmux: Open a new tmux session

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
 meta/lib/oe/terminal.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
Christopher Larson - April 4, 2013, 6:42 p.m.
On Thu, Apr 4, 2013 at 11:41 AM, Christopher Larson <kergoth@gmail.com>wrote:

> From: Christopher Larson <chris_larson@mentor.com>
>
> This adds two new Terminal classes. It's separated into two, so that
> opening
> a split inside a tmux window is preferred to the other terminal types, but
> opening a tmux session is prioritized only slightly higher than screen.
>
> - tmuxrunning: Open a new pane in the current running tmux window. Requires
>   that the TMUX variable be added to the env whitelist to use it.
> - tmux: Open a new tmux session
>
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
>

Bah, ignore this, accidentally sent an old version. Resending.

Patch

diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 4c1e318..b271de6 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -105,6 +105,44 @@  class Screen(Terminal):
         else:
             logger.warn(msg)
 
+class TmuxRunning(Terminal):
+    """Open a new pane in the current running tmux window"""
+    priority = 2.75
+    name = 'tmux-running'
+    command = 'tmux split-window {command}'
+
+    def __init__(self, sh_cmd, title=None, env=None, d=None):
+        if not bb.utils.which(os.getenv('PATH'), 'tmux'):
+            raise UnsupportedTerminal('tmux is not installed')
+
+        if not os.getenv('TMUX'):
+            raise UnsupportedTerminal('tmux is not running')
+
+        Terminal.__init__(self, sh_cmd, title, env, d)
+
+class TmuxNewSession(Terminal):
+    """Start a new tmux session and window"""
+    priority = 0.5
+    name = 'tmux'
+
+    def __init__(self, sh_cmd, title=None, env=None, d=None):
+        if not bb.utils.which(os.getenv('PATH'), 'tmux'):
+            raise UnsupportedTerminal('tmux is not installed')
+
+        # TODO: consider using a 'devshell' session shared amongst all
+        # devshells, if it's already there, add a new window to it.
+        window_name = 'devshell-%i' % os.getpid()
+
+        self.command = 'tmux new -d -s {0} -n {0} {{command}}'.format(window_name)
+        Terminal.__init__(self, sh_cmd, title, env, d)
+
+        attach_cmd = 'tmux att -t {0}'.format(window_name)
+        msg = 'Tmux started. Please connect in another terminal with `tmux att -t {0}`'.format(window_name)
+        if d:
+            bb.event.fire(bb.event.LogExecTTY(msg, attach_cmd, 0.5, 10), d)
+        else:
+            logger.warn(msg)
+
 class Custom(Terminal):
     command = 'false' # This is a placeholder
     priority = 3