[PATCH] ui: add new config flag for interface selection
Laurent Charignon
lcharignon at fb.com
Wed Dec 23 05:30:11 UTC 2015
# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1450848537 28800
# Tue Dec 22 21:28:57 2015 -0800
# Node ID 3e4f77c0bd16c78f2de991b483325eef1dc6f3fb
# Parent fe376159a58d9b3d748b669ac011b0eed0346fea
ui: add new config flag for interface selection
This patch introduces a new config flag ui.interface to select the interface
for interactive commands. It currently only applies to chunks selection.
The config can be overridden on a per feature basis with the flag
ui.interface.<feature>.
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1500,6 +1500,17 @@
``interactive``
Allow to prompt the user. (default: True)
+``interface``
+ Select the default interface for interactive features (default: text).
+ Possible values are 'text' and 'curses'.
+
+``interface.chunkselector``
+ Select the interface for chunkselection.
+ Possible values are 'text' and 'crecord'.
+ This config overrides the interface specified by ui.interface.
+ If ui.interface and ui.interface.chunkselector aren't set, we use the text
+ interface.
+
``logtemplate``
Template string for commands that print changesets.
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -696,6 +696,53 @@
return False
return util.isatty(fh)
+ def interface(self, feature):
+ '''what interface to use for interactive console features?
+
+ The interface is controlled by the value of `ui.interface` but also by
+ the value of feature-specific configuration. For example:
+ ui.interface.histedit = text
+ ui.interface.chunkselector = crecord
+
+ Means that the default interfaces for commands is curses, the
+ interface for histedit is text and the interface for selecting chunk
+ is crecord (a curses interface).
+
+ Consider the following exemple:
+ ui.interface = curses
+ ui.interface.histedit = text
+
+ Then histedit will use the text interface and chunkselector will use
+ the default curses interface (crecord at the moment).
+ '''
+
+ alloweddefaultinterfaces = ("text", "curses")
+ defaultfeaturesinterfaces = {
+ "chunkselector": {
+ "text": "text",
+ "curses": "crecord"
+ }
+ }
+
+ # Default interface
+ defaultinterface = "text"
+ i = self.config("ui", "interface", None)
+ if i is not None:
+ if i not in alloweddefaultinterfaces:
+ raise error.Abort(("Unknown interface requested %s") % i)
+ else:
+ defaultinterface = i
+
+ # Feature-specific interface
+ if feature not in ("chunkselector"):
+ raise error.Abort(("Unknown feature requested %s") % feature)
+
+ f = self.config("ui", "interface.%s" % feature, None)
+ if f is None:
+ return defaultfeaturesinterfaces[feature][defaultinterface]
+ else:
+ return f
+
def interactive(self):
'''is interactive input allowed?
diff --git a/tests/test-commit-interactive-curses.t b/tests/test-commit-interactive-curses.t
--- a/tests/test-commit-interactive-curses.t
+++ b/tests/test-commit-interactive-curses.t
@@ -193,3 +193,35 @@
+++ b/x Thu Jan 01 00:00:00 1970 +0000
@@ -0,0 +1,1 @@
+hello world
+
+Check ui.interface logic for the chunkselector
+
+The default interface is text
+ $ chunkselectorinterface() {
+ > python <<EOF
+ > from mercurial import hg, ui, parsers;\
+ > repo = hg.repository(ui.ui(), ".");\
+ > print repo.ui.interface("chunkselector")
+ > EOF
+ > }
+ $ chunkselectorinterface
+ text
+
+The default curses interface is crecord
+ $ cat <<EOF >> $HGRCPATH
+ > [ui]
+ > interface = curses
+ > EOF
+ $ chunkselectorinterface
+ crecord
+
+It is possible to override the default interface with a feature specific
+interface
+ $ cat <<EOF >> $HGRCPATH
+ > [ui]
+ > interface = text
+ > interface.chunkselector = crecord
+ > EOF
+
+ $ chunkselectorinterface
+ crecord
More information about the Mercurial-devel
mailing list