[modules/git] Nicer formatting of stati
Add separate widgets for each state, so that each state can have a custom icon *and* a custom coloring.
This commit is contained in:
parent
1698e4ad4c
commit
87f185e62b
11 changed files with 75 additions and 31 deletions
|
@ -23,50 +23,53 @@ import bumblebee.util
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config,
|
widgets = []
|
||||||
bumblebee.output.Widget(full_text=self.gitinfo)
|
super(Module, self).__init__(engine, config, widgets)
|
||||||
)
|
|
||||||
self._engine = engine
|
self._engine = engine
|
||||||
self._fmt = self.parameter("format", "{branch} {flags}")
|
|
||||||
self._error = False
|
self._error = False
|
||||||
|
self.update(self.widgets())
|
||||||
|
|
||||||
def hidden(self):
|
def hidden(self):
|
||||||
return self._error
|
return self._error
|
||||||
|
|
||||||
def gitinfo(self, widget):
|
def update(self, widgets):
|
||||||
info = ""
|
state = {}
|
||||||
directory = None
|
new_widgets = []
|
||||||
data = {
|
|
||||||
"branch": "n/a",
|
|
||||||
"directory": "n/a",
|
|
||||||
"flags": {},
|
|
||||||
}
|
|
||||||
try:
|
try:
|
||||||
directory = bumblebee.util.execute("xcwd").strip()
|
directory = bumblebee.util.execute("xcwd").strip()
|
||||||
directory = self._get_git_root(directory)
|
directory = self._get_git_root(directory)
|
||||||
repo = pygit2.Repository(directory)
|
repo = pygit2.Repository(directory)
|
||||||
|
|
||||||
|
new_widgets.append(bumblebee.output.Widget(name='git.main', full_text=repo.head.shorthand))
|
||||||
|
|
||||||
for filepath, flags in repo.status().items():
|
for filepath, flags in repo.status().items():
|
||||||
if flags == pygit2.GIT_STATUS_WT_NEW or \
|
if flags == pygit2.GIT_STATUS_WT_NEW or \
|
||||||
flags == pygit2.GIT_STATUS_INDEX_NEW:
|
flags == pygit2.GIT_STATUS_INDEX_NEW:
|
||||||
data["flags"]["new"] = True
|
state['new'] = True
|
||||||
if flags == pygit2.GIT_STATUS_WT_DELETED or \
|
if flags == pygit2.GIT_STATUS_WT_DELETED or \
|
||||||
flags == pygit2.GIT_STATUS_INDEX_DELETED:
|
flags == pygit2.GIT_STATUS_INDEX_DELETED:
|
||||||
data["flags"]["deleted"] = True
|
state['deleted'] = True
|
||||||
if flags == pygit2.GIT_STATUS_WT_MODIFIED or \
|
if flags == pygit2.GIT_STATUS_WT_MODIFIED or \
|
||||||
flags == pygit2.GIT_STATUS_INDEX_MODIFIED:
|
flags == pygit2.GIT_STATUS_INDEX_MODIFIED:
|
||||||
data["flags"]["modified"] = True
|
state['modified'] = True
|
||||||
|
|
||||||
data["branch"] = repo.head.shorthand
|
|
||||||
data["directory"] = directory
|
|
||||||
data["flags"] = " ".join([self._engine._theme.symbol(widget, name, name[0]) for name in data["flags"].keys()])
|
|
||||||
self._error = False
|
self._error = False
|
||||||
|
if 'new' in state:
|
||||||
|
new_widgets.append(bumblebee.output.Widget(name='git.new'))
|
||||||
|
if 'modified' in state:
|
||||||
|
new_widgets.append(bumblebee.output.Widget(name='git.modified'))
|
||||||
|
if 'deleted' in state:
|
||||||
|
new_widgets.append(bumblebee.output.Widget(name='git.deleted'))
|
||||||
|
|
||||||
|
while len(widgets) > 0:
|
||||||
|
del widgets[0]
|
||||||
|
for widget in new_widgets:
|
||||||
|
widgets.append(widget)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._error = True
|
self._error = True
|
||||||
logging.error(e)
|
|
||||||
return "n/a"
|
|
||||||
|
|
||||||
return string.Formatter().vformat(self._fmt, (), data)
|
def state(self, widget):
|
||||||
|
return widget.name.split('.')[1]
|
||||||
|
|
||||||
def _get_git_root(self, directory):
|
def _get_git_root(self, directory):
|
||||||
while len(directory) > 1:
|
while len(directory) > 1:
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.9 KiB |
|
@ -49,5 +49,10 @@
|
||||||
"fg": "#1d2021",
|
"fg": "#1d2021",
|
||||||
"bg": "#b8bb26"
|
"bg": "#b8bb26"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#458588" },
|
||||||
|
"deleted": { "bg": "#9d0006" },
|
||||||
|
"new": { "bg": "#b16286" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,5 +49,10 @@
|
||||||
"fg": "#1d2021",
|
"fg": "#1d2021",
|
||||||
"bg": "#b8bb26"
|
"bg": "#b8bb26"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#458588" },
|
||||||
|
"deleted": { "bg": "#9d0006" },
|
||||||
|
"new": { "bg": "#b16286" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,5 +49,10 @@
|
||||||
"fg": "#1d2021",
|
"fg": "#1d2021",
|
||||||
"bg": "#b8bb26"
|
"bg": "#b8bb26"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#458588" },
|
||||||
|
"deleted": { "bg": "#9d0006" },
|
||||||
|
"new": { "bg": "#b16286" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,5 +49,10 @@
|
||||||
"fg": "#1d2021",
|
"fg": "#1d2021",
|
||||||
"bg": "#b8bb26"
|
"bg": "#b8bb26"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#458588" },
|
||||||
|
"deleted": { "bg": "#9d0006" },
|
||||||
|
"new": { "bg": "#b16286" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,5 +121,11 @@
|
||||||
"ONLINE": {"prefix": "pool"},
|
"ONLINE": {"prefix": "pool"},
|
||||||
"FAULTED": {"prefix": "pool (!)"},
|
"FAULTED": {"prefix": "pool (!)"},
|
||||||
"DEGRADED": {"prefix": "pool (!)"}
|
"DEGRADED": {"prefix": "pool (!)"}
|
||||||
|
},
|
||||||
|
"git": {
|
||||||
|
"main": { "prefix": "" },
|
||||||
|
"new": { "prefix": "[n]" },
|
||||||
|
"modified": { "prefix": "[m]" },
|
||||||
|
"deleted": { "prefix": "[d]" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,9 +186,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"git": {
|
"git": {
|
||||||
"prefix": "",
|
"main": { "prefix": "" },
|
||||||
"new": "",
|
"new": { "prefix": "" },
|
||||||
"modified": "",
|
"modified": { "prefix": "" },
|
||||||
"deleted": ""
|
"deleted": { "prefix": "" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,5 +40,10 @@
|
||||||
"fg": "#002b36",
|
"fg": "#002b36",
|
||||||
"bg": "#859900"
|
"bg": "#859900"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#2aa198" },
|
||||||
|
"deleted": { "bg": "#d33682" },
|
||||||
|
"new": { "bg": "#859900" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,5 +42,10 @@
|
||||||
"fg": "#002b36",
|
"fg": "#002b36",
|
||||||
"bg": "#859900"
|
"bg": "#859900"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#2aa198" },
|
||||||
|
"deleted": { "bg": "#d33682" },
|
||||||
|
"new": { "bg": "#859900" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,5 +44,10 @@
|
||||||
"fg": "#002b36",
|
"fg": "#002b36",
|
||||||
"bg": "#859900"
|
"bg": "#859900"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"git": {
|
||||||
|
"modified": { "bg": "#2aa198" },
|
||||||
|
"deleted": { "bg": "#d33682" },
|
||||||
|
"new": { "bg": "#859900" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue