1. Yuya Nishihara
  2. hgext-workarounds

Commits

Yuya Nishihara  committed 6fcbb16

add experimental extension to expose ui attributes to stdout

  • Participants
  • Parent commits 63addd4
  • Branches default

Comments (0)

Files changed (1)

File hgext/exposeui.py

View file
  • Ignore whitespace
+# exposeui.py
+"""expose ui.label
+
+Note: This extension does not work if color is enabled.
+"""
+
+from mercurial import extensions, templater, util
+
+propertycache = util.propertycache
+
+def uisetup(ui):
+    if ui.plain():
+        return
+
+    class exposeui(ui.__class__):
+        # TODO: progress
+        # TODO: popbuffer and _buffers
+
+        def write(self, *args, **opts):
+            label = opts.get('label', '')
+            super(exposeui, self).write(self.label(''.join(args), label),
+                                        **opts)
+
+        def write_err(self, *args, **opts):
+            label = opts.get('label', '')
+            super(exposeui, self).write_err(self.label(''.join(args), label),
+                                            **opts)
+
+        def label(self, msg, label):
+            t = self._exposetemplater
+            return templater.stringify(t('uilabel', msg=msg, label=label))
+
+        @propertycache
+        def _exposetemplater(self):
+            mapfile = None  # TODO
+            tmplmap = {
+                'uilabel': '{msg}\0{label}',
+                }
+            tmpl = self.config('ui', 'labeltemplate')
+            if tmpl:
+                tmplmap['uilabel'] = tmpl
+            return templater.templater(mapfile, cache=tmplmap)
+
+    ui.__class__ = exposeui