Show More
@@ -1613,6 +1613,15 b' User interface controls.' | |||||
1613 | ``interactive`` |
|
1613 | ``interactive`` | |
1614 | Allow to prompt the user. (default: True) |
|
1614 | Allow to prompt the user. (default: True) | |
1615 |
|
1615 | |||
|
1616 | ``interface`` | |||
|
1617 | Select the default interface for interactive features (default: text). | |||
|
1618 | Possible values are 'text' and 'curses'. | |||
|
1619 | ||||
|
1620 | ``interface.chunkselector`` | |||
|
1621 | Select the interface for change recording (e.g. :hg:`commit` -i). | |||
|
1622 | Possible values are 'text' and 'curses'. | |||
|
1623 | This config overrides the interface specified by ui.interface. | |||
|
1624 | ||||
1616 | ``logtemplate`` |
|
1625 | ``logtemplate`` | |
1617 | Template string for commands that print changesets. |
|
1626 | Template string for commands that print changesets. | |
1618 |
|
1627 |
@@ -697,6 +697,77 b' class ui(object):' | |||||
697 | return False |
|
697 | return False | |
698 | return util.isatty(fh) |
|
698 | return util.isatty(fh) | |
699 |
|
699 | |||
|
700 | def interface(self, feature): | |||
|
701 | """what interface to use for interactive console features? | |||
|
702 | ||||
|
703 | The interface is controlled by the value of `ui.interface` but also by | |||
|
704 | the value of feature-specific configuration. For example: | |||
|
705 | ||||
|
706 | ui.interface.histedit = text | |||
|
707 | ui.interface.chunkselector = curses | |||
|
708 | ||||
|
709 | Here the features are "histedit" and "chunkselector". | |||
|
710 | ||||
|
711 | The configuration above means that the default interfaces for commands | |||
|
712 | is curses, the interface for histedit is text and the interface for | |||
|
713 | selecting chunk is crecord (the best curses interface available). | |||
|
714 | ||||
|
715 | Consider the following exemple: | |||
|
716 | ui.interface = curses | |||
|
717 | ui.interface.histedit = text | |||
|
718 | ||||
|
719 | Then histedit will use the text interface and chunkselector will use | |||
|
720 | the default curses interface (crecord at the moment). | |||
|
721 | """ | |||
|
722 | alldefaults = frozenset(["text", "curses"]) | |||
|
723 | ||||
|
724 | featureinterfaces = { | |||
|
725 | "chunkselector": [ | |||
|
726 | "text", | |||
|
727 | "curses", | |||
|
728 | ] | |||
|
729 | } | |||
|
730 | ||||
|
731 | # Feature-specific interface | |||
|
732 | if feature not in featureinterfaces.keys(): | |||
|
733 | # Programming error, not user error | |||
|
734 | raise ValueError("Unknown feature requested %s" % feature) | |||
|
735 | ||||
|
736 | availableinterfaces = frozenset(featureinterfaces[feature]) | |||
|
737 | if alldefaults > availableinterfaces: | |||
|
738 | # Programming error, not user error. We need a use case to | |||
|
739 | # define the right thing to do here. | |||
|
740 | raise ValueError( | |||
|
741 | "Feature %s does not handle all default interfaces" % | |||
|
742 | feature) | |||
|
743 | ||||
|
744 | if self.plain(): | |||
|
745 | return "text" | |||
|
746 | ||||
|
747 | # Default interface for all the features | |||
|
748 | defaultinterface = "text" | |||
|
749 | i = self.config("ui", "interface", None) | |||
|
750 | if i in alldefaults: | |||
|
751 | defaultinterface = i | |||
|
752 | ||||
|
753 | choseninterface = defaultinterface | |||
|
754 | f = self.config("ui", "interface.%s" % feature, None) | |||
|
755 | if f in availableinterfaces: | |||
|
756 | choseninterface = f | |||
|
757 | ||||
|
758 | if i is not None and defaultinterface != i: | |||
|
759 | if f is not None: | |||
|
760 | self.warn(_("invalid value for ui.interface: %s\n") % | |||
|
761 | (i,)) | |||
|
762 | else: | |||
|
763 | self.warn(_("invalid value for ui.interface: %s (using %s)\n") % | |||
|
764 | (i, choseninterface)) | |||
|
765 | if f is not None and choseninterface != f: | |||
|
766 | self.warn(_("invalid value for ui.interface.%s: %s (using %s)\n") % | |||
|
767 | (feature, f, choseninterface)) | |||
|
768 | ||||
|
769 | return choseninterface | |||
|
770 | ||||
700 | def interactive(self): |
|
771 | def interactive(self): | |
701 | '''is interactive input allowed? |
|
772 | '''is interactive input allowed? | |
702 |
|
773 |
@@ -1,5 +1,6 b'' | |||||
1 | Set up a repo |
|
1 | Set up a repo | |
2 |
|
2 | |||
|
3 | $ cp $HGRCPATH $HGRCPATH.pretest | |||
3 | $ cat <<EOF >> $HGRCPATH |
|
4 | $ cat <<EOF >> $HGRCPATH | |
4 | > [ui] |
|
5 | > [ui] | |
5 | > interactive = true |
|
6 | > interactive = true | |
@@ -223,3 +224,90 b' of the edit.' | |||||
223 | hello world |
|
224 | hello world | |
224 |
|
225 | |||
225 |
|
226 | |||
|
227 | Check ui.interface logic for the chunkselector | |||
|
228 | ||||
|
229 | The default interface is text | |||
|
230 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
231 | $ chunkselectorinterface() { | |||
|
232 | > python <<EOF | |||
|
233 | > from mercurial import hg, ui, parsers;\ | |||
|
234 | > repo = hg.repository(ui.ui(), ".");\ | |||
|
235 | > print repo.ui.interface("chunkselector") | |||
|
236 | > EOF | |||
|
237 | > } | |||
|
238 | $ chunkselectorinterface | |||
|
239 | text | |||
|
240 | ||||
|
241 | If only the default is set, we'll use that for the feature, too | |||
|
242 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
243 | $ cat <<EOF >> $HGRCPATH | |||
|
244 | > [ui] | |||
|
245 | > interface = curses | |||
|
246 | > EOF | |||
|
247 | $ chunkselectorinterface | |||
|
248 | curses | |||
|
249 | ||||
|
250 | It is possible to override the default interface with a feature specific | |||
|
251 | interface | |||
|
252 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
253 | $ cat <<EOF >> $HGRCPATH | |||
|
254 | > [ui] | |||
|
255 | > interface = text | |||
|
256 | > interface.chunkselector = curses | |||
|
257 | > EOF | |||
|
258 | ||||
|
259 | $ chunkselectorinterface | |||
|
260 | curses | |||
|
261 | ||||
|
262 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
263 | $ cat <<EOF >> $HGRCPATH | |||
|
264 | > [ui] | |||
|
265 | > interface = curses | |||
|
266 | > interface.chunkselector = text | |||
|
267 | > EOF | |||
|
268 | ||||
|
269 | $ chunkselectorinterface | |||
|
270 | text | |||
|
271 | ||||
|
272 | If a bad interface name is given, we use the default value (with a nice | |||
|
273 | error message to suggest that the configuration needs to be fixed) | |||
|
274 | ||||
|
275 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
276 | $ cat <<EOF >> $HGRCPATH | |||
|
277 | > [ui] | |||
|
278 | > interface = blah | |||
|
279 | > EOF | |||
|
280 | $ chunkselectorinterface | |||
|
281 | invalid value for ui.interface: blah (using text) | |||
|
282 | text | |||
|
283 | ||||
|
284 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
285 | $ cat <<EOF >> $HGRCPATH | |||
|
286 | > [ui] | |||
|
287 | > interface = curses | |||
|
288 | > interface.chunkselector = blah | |||
|
289 | > EOF | |||
|
290 | $ chunkselectorinterface | |||
|
291 | invalid value for ui.interface.chunkselector: blah (using curses) | |||
|
292 | curses | |||
|
293 | ||||
|
294 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
295 | $ cat <<EOF >> $HGRCPATH | |||
|
296 | > [ui] | |||
|
297 | > interface = blah | |||
|
298 | > interface.chunkselector = curses | |||
|
299 | > EOF | |||
|
300 | $ chunkselectorinterface | |||
|
301 | invalid value for ui.interface: blah | |||
|
302 | curses | |||
|
303 | ||||
|
304 | $ cp $HGRCPATH.pretest $HGRCPATH | |||
|
305 | $ cat <<EOF >> $HGRCPATH | |||
|
306 | > [ui] | |||
|
307 | > interface = blah | |||
|
308 | > interface.chunkselector = blah | |||
|
309 | > EOF | |||
|
310 | $ chunkselectorinterface | |||
|
311 | invalid value for ui.interface: blah | |||
|
312 | invalid value for ui.interface.chunkselector: blah (using text) | |||
|
313 | text |
General Comments 0
You need to be logged in to leave comments.
Login now