Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mercurial-devel
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mercurial
mercurial-devel
Commits
ca0d0222
Commit
ca0d0222
authored
17 years ago
by
Bryan O'Sullivan
Browse files
Options
Downloads
Patches
Plain Diff
ui: get readline and prompt to behave better depending on interactivity
parent
a675f6d5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mercurial/ui.py
+27
-6
27 additions, 6 deletions
mercurial/ui.py
with
27 additions
and
6 deletions
mercurial/ui.py
+
27
−
6
View file @
ca0d0222
...
...
@@ -24,6 +24,8 @@
dest
.
set
(
section
,
name
,
value
)
class
ui
(
object
):
_isatty
=
None
def
__init__
(
self
,
verbose
=
False
,
debug
=
False
,
quiet
=
False
,
interactive
=
True
,
traceback
=
False
,
report_untrusted
=
True
,
parentui
=
None
):
...
...
@@ -62,6 +64,11 @@
def
__getattr__
(
self
,
key
):
return
getattr
(
self
.
parentui
,
key
)
def
isatty
(
self
):
if
ui
.
_isatty
is
None
:
ui
.
_isatty
=
os
.
isatty
(
sys
.
stdin
.
fileno
())
return
ui
.
_isatty
def
updateopts
(
self
,
verbose
=
False
,
debug
=
False
,
quiet
=
False
,
interactive
=
True
,
traceback
=
False
,
config
=
[]):
for
section
,
name
,
value
in
config
:
...
...
@@ -204,7 +211,9 @@
if
name
is
None
or
name
in
(
'
quiet
'
,
'
verbose
'
,
'
debug
'
):
self
.
verbosity_constraints
()
if
name
is
None
or
name
==
'
interactive
'
:
self
.
interactive
=
self
.
configbool
(
"
ui
"
,
"
interactive
"
,
True
)
self
.
interactive
=
self
.
configbool
(
"
ui
"
,
"
interactive
"
,
None
)
if
self
.
interactive
is
None
:
self
.
interactive
=
self
.
isatty
()
if
name
is
None
or
name
==
'
report_untrusted
'
:
self
.
report_untrusted
=
(
self
.
configbool
(
"
ui
"
,
"
report_untrusted
"
,
True
))
...
...
@@ -382,7 +391,17 @@
try
:
sys
.
stderr
.
flush
()
except
:
pass
def
readline
(
self
):
return
sys
.
stdin
.
readline
()[:
-
1
]
def
readline
(
self
,
prompt
=
''
):
if
self
.
isatty
():
try
:
# magically add command line editing support, where
# available
import
readline
# force demandimport to really load the module
readline
.
read_history_file
except
ImportError
:
pass
return
raw_input
(
prompt
)
def
prompt
(
self
,
msg
,
pat
=
None
,
default
=
"
y
"
):
if
not
self
.
interactive
:
return
default
...
...
@@ -387,9 +406,8 @@
def
prompt
(
self
,
msg
,
pat
=
None
,
default
=
"
y
"
):
if
not
self
.
interactive
:
return
default
while
1
:
self
.
write
(
msg
,
"
"
)
r
=
self
.
readline
()
try
:
r
=
self
.
readline
(
msg
+
'
'
)
if
not
pat
or
re
.
match
(
pat
,
r
):
return
r
else
:
self
.
write
(
_
(
"
unrecognized response
\n
"
))
...
...
@@ -392,7 +410,10 @@
if
not
pat
or
re
.
match
(
pat
,
r
):
return
r
else
:
self
.
write
(
_
(
"
unrecognized response
\n
"
))
except
EOFError
:
raise
util
.
Abort
(
_
(
'
response expected
'
))
def
getpass
(
self
,
prompt
=
None
,
default
=
None
):
if
not
self
.
interactive
:
return
default
return
getpass
.
getpass
(
prompt
or
_
(
'
password:
'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment