Patchwork [V2] ui: add new config flag for interface selection

login
register
mail settings
Submitter Laurent Charignon
Date Feb. 5, 2016, 1:20 a.m.
Message ID <229eebf1a275b253f6b8.1454635227@dev5073.prn1.facebook.com>
Download mbox | patch
Permalink /patch/12993/
State Superseded
Commit 71e12fc53b80180ca20e8192abf8ee4d70727fbe
Delegated to: Augie Fackler
Headers show

Comments

Laurent Charignon - Feb. 5, 2016, 1:20 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1454635156 28800
#      Thu Feb 04 17:19:16 2016 -0800
# Branch stable
# Node ID 229eebf1a275b253f6b8a2ea509b52ccce3e3f83
# Parent  b163d0993d788fb7c5a55a8a052b1115ba7b66e6
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>.

features for the moment can only be 'chunkselector', moving forward we expect
to have 'histedit' and other commands there.

If an incorrect value is given to ui.interface we print a warning and use the
default interface: text. If HGPLAIN is specified we also use the default
interface: text.
Augie Fackler - Feb. 5, 2016, 3:27 p.m.
On Thu, Feb 04, 2016 at 05:20:27PM -0800, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1454635156 28800
> #      Thu Feb 04 17:19:16 2016 -0800
> # Branch stable
> # Node ID 229eebf1a275b253f6b8a2ea509b52ccce3e3f83
> # Parent  b163d0993d788fb7c5a55a8a052b1115ba7b66e6
> 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>.
>
> features for the moment can only be 'chunkselector', moving forward we expect
> to have 'histedit' and other commands there.
>
> If an incorrect value is given to ui.interface we print a warning and use the
> default interface: text. If HGPLAIN is specified we also use the default
> interface: text.
>
> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -1587,6 +1587,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'.

Why is "curses" not a valid entry here?

> +    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
> @@ -699,6 +699,63 @@
>              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
> +
> +        Here the features are "histedit" and "chunkselector".
> +
> +        The configuration above 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).
> +        '''
> +        if self.plain():
> +            return "text"
> +
> +        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:
> +                self.warn(_("invalid value for ui.interface: %s") % i)
> +                self.warn(_("(using default interface instead %s)")
> +                          % defaultinterface)
> +            else:
> +                defaultinterface = i
> +
> +        # Feature-specific interface
> +        if feature not in defaultfeaturesinterfaces.keys():
> +            # This is a programming error, not a user facing error, it is
> +            # ok to Abort here as we should never hit this case
> +            raise ValueError("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
> @@ -223,3 +223,34 @@
>    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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Laurent Charignon - Feb. 5, 2016, 4:17 p.m.
By mistake I didn't base this patch on a public rev.
I will send a rebased v3, Augie could you have a look?

On 2/4/16, 5:20 PM, "Mercurial-devel on behalf of Laurent Charignon"
<mercurial-devel-bounces@mercurial-scm.org on behalf of lcharignon@fb.com>
wrote:

># HG changeset patch
># User Laurent Charignon <lcharignon@fb.com>
># Date 1454635156 28800
>#      Thu Feb 04 17:19:16 2016 -0800
># Branch stable
># Node ID 229eebf1a275b253f6b8a2ea509b52ccce3e3f83
># Parent  b163d0993d788fb7c5a55a8a052b1115ba7b66e6
>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>.
>
>features for the moment can only be 'chunkselector', moving forward we
>expect
>to have 'histedit' and other commands there.
>
>If an incorrect value is given to ui.interface we print a warning and use
>the
>default interface: text. If HGPLAIN is specified we also use the default
>interface: text.
>
>diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
>--- a/mercurial/help/config.txt
>+++ b/mercurial/help/config.txt
>@@ -1587,6 +1587,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
>@@ -699,6 +699,63 @@
>             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
>+
>+        Here the features are "histedit" and "chunkselector".
>+
>+        The configuration above 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).
>+        '''
>+        if self.plain():
>+            return "text"
>+
>+        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:
>+                self.warn(_("invalid value for ui.interface: %s") % i)
>+                self.warn(_("(using default interface instead %s)")
>+                          % defaultinterface)
>+            else:
>+                defaultinterface = i
>+
>+        # Feature-specific interface
>+        if feature not in defaultfeaturesinterfaces.keys():
>+            # This is a programming error, not a user facing error, it is
>+            # ok to Abort here as we should never hit this case
>+            raise ValueError("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
>@@ -223,3 +223,34 @@
>   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
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel@mercurial-scm.org
>https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.o
>rg_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=
>qmwlQ6ljsf0--v3ANP53-V-RM6PPUtJ5zK5Y1fStJGg&m=Fx2SGllfizy3cYbCv6yO8pOay4qO
>3FRll-a74otgcR4&s=ILKvQNgvdkXhWyZrTDQPADrRJtYDkFVpz6c-KA2Qw4U&e=

Patch

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1587,6 +1587,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
@@ -699,6 +699,63 @@ 
             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
+
+        Here the features are "histedit" and "chunkselector".
+
+        The configuration above 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).
+        '''
+        if self.plain():
+            return "text"
+
+        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:
+                self.warn(_("invalid value for ui.interface: %s") % i)
+                self.warn(_("(using default interface instead %s)")
+                          % defaultinterface)
+            else:
+                defaultinterface = i
+
+        # Feature-specific interface
+        if feature not in defaultfeaturesinterfaces.keys():
+            # This is a programming error, not a user facing error, it is
+            # ok to Abort here as we should never hit this case
+            raise ValueError("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
@@ -223,3 +223,34 @@ 
   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