Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 49798:a51328ba33ca
ui: split the `default` arg out of **kwargs for the internal prompt method
This arg was required anyway, based on how it was accessed. Having it separate
allows it to be typed though, and this will simplify things for the callers- if
a non-None `default` is passed, the return can never be None. That can be
expressed with `@overload` when the arg can be typed, but that's not possible
when it is rolled up in **kwargs.
The default value is simply copied from the public `prompt()` above it.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 12 Dec 2022 14:17:05 -0500 |
parents | 0449fb7729d7 |
children | de284a0b5614 |
comparison
equal
deleted
inserted
replaced
49797:0449fb7729d7 | 49798:a51328ba33ca |
---|---|
1784 """Prompt user with msg, read response. | 1784 """Prompt user with msg, read response. |
1785 If ui is not interactive, the default is returned. | 1785 If ui is not interactive, the default is returned. |
1786 """ | 1786 """ |
1787 return self._prompt(msg, default=default) | 1787 return self._prompt(msg, default=default) |
1788 | 1788 |
1789 def _prompt(self, msg, **opts): | 1789 def _prompt(self, msg, default=b'y', **opts): |
1790 default = opts['default'] | 1790 opts = {**opts, 'default': default} |
1791 if not self.interactive(): | 1791 if not self.interactive(): |
1792 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) | 1792 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) |
1793 self._writemsg( | 1793 self._writemsg( |
1794 self._fmsgout, default or b'', b"\n", type=b'promptecho' | 1794 self._fmsgout, default or b'', b"\n", type=b'promptecho' |
1795 ) | 1795 ) |