Allow naming of session tabs

This commit is contained in:
Kovid Goyal 2016-12-07 09:39:43 +05:30
parent aca13ba05e
commit 1b67195b7c
3 changed files with 13 additions and 7 deletions

View File

@ -68,8 +68,10 @@ launch zsh
launch vim
launch irssi --profile x
# Create a new tab
new_tab
# Create a new tab (the part after new_tab is the optional tab name which will
# be displayed in the tab bar, if ommitted, the title of the active window will
# be used instead)
new_tab my tab
cd ~/somewhere
# Set the layouts allowed in this tab
enabled_layouts tall, stack

View File

@ -11,8 +11,9 @@ from .layout import all_layouts
class Tab:
def __init__(self, opts):
def __init__(self, opts, name):
self.windows = []
self.name = name.strip()
self.active_window_idx = 0
self.enabled_layouts = opts.enabled_layouts
self.layout = (self.enabled_layouts or ['tall'])[0]
@ -25,8 +26,10 @@ class Session:
self.tabs = []
self.active_tab_idx = 0
def add_tab(self, opts):
self.tabs.append(Tab(opts))
def add_tab(self, opts, name=''):
if self.tabs and not self.tabs[-1].windows:
del self.tabs[-1]
self.tabs.append(Tab(opts, name))
def set_layout(self, val):
if val not in all_layouts:
@ -60,7 +63,7 @@ def parse_session(raw, opts):
cmd, rest = line.partition(' ')[::2]
cmd, rest = cmd.strip(), rest.strip()
if cmd == 'new_tab':
ans.add_tab(opts)
ans.add_tab(opts, rest)
elif cmd == 'layout':
ans.set_layout(rest)
elif cmd == 'launch':

View File

@ -21,6 +21,7 @@ class Tab:
def __init__(self, opts, args, on_title_change, session_tab=None):
self.opts, self.args = opts, args
self.name = getattr(session_tab, 'name', '')
self.on_title_change = on_title_change
self.enabled_layouts = list((session_tab or opts).enabled_layouts)
self.borders = Borders(opts)
@ -225,7 +226,7 @@ class TabManager:
at = self.active_tab
for t in self.tabs:
title = (t.title or appname) + ' '
title = (t.name or t.title or appname) + ' '
s.cursor.bg = self.active_bg if t is at else 0
s.cursor.fg = self.active_fg if t is at else 0
s.cursor.bold = t is at