[PATCH] ui: add new config flag for interface selection
Yuya Nishihara
yuya at tcha.org
Fri Jan 1 06:09:26 UTC 2016
On Tue, 22 Dec 2015 21:30:11 -0800, Laurent Charignon wrote:
> # 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.
I prefer new section rather than putting everything under pseudo 'ui.interface.'
sub section. For example,
[interactive-ui]
default = text
chunkselector = curses
And we have to remove all of them if HGPLAIN is specified.
> 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)
_("unknown interface requested %s")
> + else:
> + defaultinterface = i
> +
> + # Feature-specific interface
> + if feature not in ("chunkselector"):
("chunkselector",)
> + raise error.Abort(("Unknown feature requested %s") % feature)
Unknown "feature" is an implementation bug. Perhaps it should raise ValueError
or something.
More information about the Mercurial-devel
mailing list