add cwd to TabBarData

this option add current working directory to the tab by using active windows child directory.
This commit is contained in:
noval 2022-07-26 09:33:55 +07:00
parent fe8892ec54
commit 237bfc9a6e
3 changed files with 17 additions and 8 deletions

View File

@ -1164,13 +1164,13 @@ optional symbols for bell and activity. If you wish to include the tab-index as
well, use something like: :code:`{index}:{title}`. Useful if you have shortcuts
mapped for :code:`goto_tab N`. If you prefer to see the index as a superscript,
use :code:`{sup.index}`. In addition you can use :code:`{layout_name}` for the
current layout name, :code:`{num_windows}` for the number of windows in the tab
and :code:`{num_window_groups}` for the number of window groups (not counting
overlay windows) in the tab. Note that formatting is done by Python's string
formatting machinery, so you can use, for instance,
:code:`{layout_name[:2].upper()}` to show only the first two letters of the
layout name, upper-cased. If you want to style the text, you can use styling
directives, for example:
current layout name, :code:`{num_windows}` for the number of windows in the tab,
:code:`{num_window_groups}` for the number of window groups (not counting
overlay windows) in the tab, and {cwd} for current working directory.
Note that formatting is done by Python's string formatting machinery, so you can
use, for instance, :code:`{layout_name[:2].upper()}` to show only the first two
letters of the layout name, upper-cased. If you want to style the text, you can
use styling directives, for example:
``{fmt.fg.red}red{fmt.fg.tab}normal{fmt.bg._00FF00}greenbg{fmt.bg.tab}``.
Similarly, for bold and italic:
``{fmt.bold}bold{fmt.nobold}normal{fmt.italic}italic{fmt.noitalic}``.

View File

@ -25,6 +25,7 @@ class TabBarData(NamedTuple):
title: str
is_active: bool
needs_attention: bool
cwd: str
num_windows: int
num_window_groups: int
layout_name: str
@ -179,6 +180,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int)
'num_windows': tab.num_windows,
'num_window_groups': tab.num_window_groups,
'title': tab.title,
'cwd': tab.cwd,
}
ColorFormatter.draw_data = draw_data
ColorFormatter.tab_data = tab
@ -188,6 +190,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int)
'num_windows': tab.num_windows,
'num_window_groups': tab.num_window_groups,
'title': tab.title,
'cwd': tab.cwd,
'fmt': Formatter,
'sup': SupSub(data),
'sub': SupSub(data, True),

View File

@ -230,6 +230,11 @@ class Tab: # {{{
ans += 1
return ans
@property
def get_cwd(self) -> str:
w = self.active_window
return w.cwd_of_child if w and w.cwd_of_child else self.cwd
def set_title(self, title: str) -> None:
self.name = title or ''
self.mark_tab_bar_dirty()
@ -1078,13 +1083,14 @@ class TabManager: # {{{
title = (t.name or t.title or appname).strip()
needs_attention = False
has_activity_since_last_focus = False
cwd = os.path.abspath(t.get_cwd)
for w in t:
if w.needs_attention:
needs_attention = True
if w.has_activity_since_last_focus:
has_activity_since_last_focus = True
ans.append(TabBarData(
title, t is at, needs_attention,
title, t is at, needs_attention, cwd,
len(t), t.num_window_groups, t.current_layout.name or '',
has_activity_since_last_focus, t.active_fg, t.active_bg,
t.inactive_fg, t.inactive_bg