configwizard: prompt to enable curses interfaces (
bug 1279596); r?glob
MozReview-Commit-ID: I7tPnkaoA3
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -8,16 +8,17 @@ import io
import os
import stat
import subprocess
import sys
import uuid
from mercurial import (
cmdutil,
+ demandimport,
error,
scmutil,
util,
)
from mercurial.i18n import _
OUR_DIR = os.path.dirname(__file__)
execfile(os.path.join(OUR_DIR, '..', 'bootstrap.py'))
@@ -88,16 +89,23 @@ Please select one of the following for c
1. Enable pager and configure with recommended settings (preferred)
2. Enable pager with default configuration
3. Don't enable pager
Which option would you like? $$ &1 $$ &2 $$ &3
'''.strip()
+CURSES_INFO = '''
+Mercurial can provide richer terminal interactions for some operations
+by using the popular "curses" library.
+
+Would you like to enable "curses" interfaces (Yn)? $$ &Yes $$ &No
+'''.strip()
+
FSMONITOR_INFO = '''
The fsmonitor extension integrates the watchman filesystem watching tool
with Mercurial. Commands like `hg status`, `hg diff`, and `hg commit`
(which need to examine filesystem state) can query watchman to obtain
this state, allowing these commands to complete much quicker.
When installed, the fsmonitor extension will automatically launch a
background watchman daemon for accessed Mercurial repositories. It
@@ -253,16 +261,17 @@ cmdtable = {}
command = cmdutil.command(cmdtable)
wizardsteps = {
'hgversion',
'username',
'diff',
'color',
'pager',
+ 'curses',
'historyediting',
'fsmonitor',
'blackbox',
'wip',
'security',
'firefoxtree',
'codereview',
'pushtotry',
@@ -303,16 +312,19 @@ def configwizard(ui, repo, statedir=None
_checkdiffsettings(ui, cw)
if 'color' in runsteps:
_promptnativeextension(ui, cw, 'color', 'Enable color output to your terminal')
if 'pager' in runsteps:
_checkpager(ui, cw)
+ if 'curses' in runsteps:
+ _checkcurses(ui, cw)
+
if 'historyediting' in runsteps:
_checkhistoryediting(ui, cw)
if 'fsmonitor' in runsteps:
_checkfsmonitor(ui, cw, hgversion)
if 'blackbox' in runsteps:
_promptnativeextension(ui, cw, 'blackbox',
@@ -507,16 +519,38 @@ def _checkpager(ui, cw):
if not haveconfig:
cw.c['pager']['pager'] = 'LESS=FRSXQ less'
for a in sorted(attends):
if not ui.hasconfig('pager', 'attend-%s' % a):
cw.c['pager']['attend-%s' % a] = 'true'
+def _checkcurses(ui, cw):
+ if ui.hasconfig('ui', 'interface'):
+ return
+
+ # curses isn't available on all platforms. Don't prompt if not
+ # available.
+ with demandimport.deactivated():
+ try:
+ import curses
+ except Exception:
+ try:
+ import wcurses
+ except Exception:
+ return
+
+ if ui.promptchoice(CURSES_INFO):
+ return
+
+ cw.c.setdefault('ui', {})
+ cw.c['ui']['interface'] = 'curses'
+
+
def _checkhistoryediting(ui, cw):
if all(ui.hasconfig('extensions', e) for e in ('histedit', 'rebase')):
return
if ui.promptchoice('Enable history rewriting commands (Yn)? $$ &Yes $$ &No'):
return
if 'extensions' not in cw.c:
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-curses.t
@@ -0,0 +1,58 @@
+ $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+Rejecting curses doesn't enable it
+
+ $ hg --config ui.interactive=true --config configwizard.steps=curses,configchange configwizard << EOF
+ >
+ > n
+ > EOF
+ This wizard will guide you through configuring Mercurial for an optimal
+ experience contributing to Mozilla projects.
+
+ The wizard makes no changes without your permission.
+
+ To begin, press the enter/return key.
+ <RETURN>
+ Mercurial can provide richer terminal interactions for some operations
+ by using the popular "curses" library.
+
+ Would you like to enable "curses" interfaces (Yn)? n
+
+No prompt if interface already set
+
+ $ hg --config configwizard.steps=curses --config ui.interface=text configwizard
+ This wizard will guide you through configuring Mercurial for an optimal
+ experience contributing to Mozilla projects.
+
+ The wizard makes no changes without your permission.
+
+ To begin, press the enter/return key.
+ <RETURN>
+
+curses interfaces enabled
+
+ $ hg --config configwizard.steps=curses,configchange configwizard
+ This wizard will guide you through configuring Mercurial for an optimal
+ experience contributing to Mozilla projects.
+
+ The wizard makes no changes without your permission.
+
+ To begin, press the enter/return key.
+ <RETURN>
+ Mercurial can provide richer terminal interactions for some operations
+ by using the popular "curses" library.
+
+ Would you like to enable "curses" interfaces (Yn)? y
+ Your config file needs updating.
+ Would you like to see a diff of the changes first (Yn)? y
+ --- hgrc.old
+ +++ hgrc.new
+ @@ -0,0 +1,2 @@
+ +[ui]
+ +interface = curses
+
+ Write changes to hgrc file (Yn)? y
+
+ $ cat .hgrc
+ [ui]
+ interface = curses