jp: replace no_lf argument by end in disp (same as in print)
This commit is contained in:
parent
883a07c591
commit
f4c7f5e55e
5 changed files with 24 additions and 25 deletions
|
|
@ -234,25 +234,19 @@ class Jp(object):
|
|||
for cache_data in cache:
|
||||
await cache_data[0](*cache_data[1:])
|
||||
|
||||
def disp(self, msg, verbosity=0, error=False, no_lf=False):
|
||||
def disp(self, msg, verbosity=0, error=False, end='\n'):
|
||||
"""Print a message to user
|
||||
|
||||
@param msg(unicode): message to print
|
||||
@param verbosity(int): minimal verbosity to display the message
|
||||
@param error(bool): if True, print to stderr instead of stdout
|
||||
@param no_lf(bool): if True, do not emit line feed at the end of line
|
||||
@param end(str): string appended after the last value, default a newline
|
||||
"""
|
||||
if self.verbosity >= verbosity:
|
||||
if error:
|
||||
if no_lf:
|
||||
print(msg, end=' ', file=sys.stderr)
|
||||
else:
|
||||
print(msg, file=sys.stderr)
|
||||
print(msg, end=end, file=sys.stderr)
|
||||
else:
|
||||
if no_lf:
|
||||
print(msg, end=' ')
|
||||
else:
|
||||
print(msg)
|
||||
print(msg, end=end)
|
||||
|
||||
async def output(self, type_, name, extra_outputs, data):
|
||||
if name in extra_outputs:
|
||||
|
|
@ -684,7 +678,7 @@ class Jp(object):
|
|||
|
||||
async def ainput(self, msg=''):
|
||||
"""Asynchronous version of buildin "input" function"""
|
||||
self.disp(msg, no_lf=True)
|
||||
self.disp(msg, end=' ')
|
||||
sys.stdout.flush()
|
||||
loop = asyncio.get_running_loop()
|
||||
stdin_fut = loop.create_future()
|
||||
|
|
@ -1150,8 +1144,8 @@ class CommandBase(object):
|
|||
"""
|
||||
self.disp(_(f"Error while doing operation: {e}"), error=True)
|
||||
|
||||
def disp(self, msg, verbosity=0, error=False, no_lf=False):
|
||||
return self.host.disp(msg, verbosity, error, no_lf)
|
||||
def disp(self, msg, verbosity=0, error=False, end='\n'):
|
||||
return self.host.disp(msg, verbosity, error, end)
|
||||
|
||||
def output(self, data):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -203,10 +203,14 @@ class Theme(base.CommandBase):
|
|||
color = getattr(C, attr)
|
||||
if attr == 'A_LEVEL_COLORS':
|
||||
# This constant contains multiple colors
|
||||
self.disp('LEVEL COLORS: ', no_lf=True)
|
||||
self.disp('LEVEL COLORS: ', end=' ')
|
||||
for idx, c in enumerate(color):
|
||||
last = idx == len(color)-1
|
||||
self.disp(c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''), no_lf=not last)
|
||||
end = '\n' if last else ' '
|
||||
self.disp(
|
||||
c + f'LEVEL_{idx}' + A.RESET + (', ' if not last else ''),
|
||||
end=end
|
||||
)
|
||||
else:
|
||||
text = attr[2:]
|
||||
self.disp(A.color(color, text))
|
||||
|
|
|
|||
|
|
@ -194,9 +194,10 @@ class InputCommon(base.CommandBase):
|
|||
error=True,
|
||||
)
|
||||
self.host.quit(C.EXIT_DATA_ERROR)
|
||||
end = '\n' if self.args.debug else ' '
|
||||
self.disp(
|
||||
A.color(C.A_HEADER, _("command {idx}").format(idx=self.idx)),
|
||||
no_lf=not self.args.debug,
|
||||
end = end,
|
||||
)
|
||||
stdin = "".join(self._stdin)
|
||||
if self.args.debug:
|
||||
|
|
@ -226,7 +227,7 @@ class InputCommon(base.CommandBase):
|
|||
)
|
||||
self.disp("\n")
|
||||
else:
|
||||
self.disp(" (" + ", ".join(self._values_ori) + ")", 2, no_lf=True)
|
||||
self.disp(" (" + ", ".join(self._values_ori) + ")", 2, end=' ')
|
||||
args = [sys.argv[0]] + self.args.command + self._opts + self._pos
|
||||
p = await asyncio.create_subprocess_exec(
|
||||
*args,
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class Shell(base.CommandBase, cmd.Cmd):
|
|||
def do_help(self, args):
|
||||
"""show help message"""
|
||||
if not args:
|
||||
self.disp(A.color(C.A_HEADER, _("Shell commands:")), no_lf=True)
|
||||
self.disp(A.color(C.A_HEADER, _("Shell commands:")), end=' ')
|
||||
super(Shell, self).do_help(args)
|
||||
if not args:
|
||||
self.disp(A.color(C.A_HEADER, _("Action commands:")))
|
||||
|
|
|
|||
|
|
@ -199,13 +199,13 @@ class LabelWidget(xmlui_base.LabelWidget, ValueWidget):
|
|||
except AttributeError:
|
||||
return None
|
||||
|
||||
async def show(self, no_lf=False, ansi=""):
|
||||
async def show(self, end='\n', ansi=""):
|
||||
"""show label
|
||||
|
||||
@param no_lf(bool): same as for [JP.disp]
|
||||
@param end(str): same as for [JP.disp]
|
||||
@param ansi(unicode): ansi escape code to print before label
|
||||
"""
|
||||
self.disp(A.color(ansi, self.value), no_lf=no_lf)
|
||||
self.disp(A.color(ansi, self.value), end=end)
|
||||
|
||||
|
||||
class JidWidget(xmlui_base.JidWidget, TextWidget):
|
||||
|
|
@ -383,7 +383,7 @@ class LabelContainer(xmlui_base.PairsContainer, Container):
|
|||
|
||||
async def show(self):
|
||||
for child in self.children:
|
||||
no_lf = False
|
||||
end = '\n'
|
||||
# we check linked widget type
|
||||
# to see if we want the label on the same line or not
|
||||
if child.type == "label":
|
||||
|
|
@ -396,10 +396,10 @@ class LabelContainer(xmlui_base.PairsContainer, Container):
|
|||
"string",
|
||||
"jid_input",
|
||||
):
|
||||
no_lf = True
|
||||
end = ' '
|
||||
elif wid_type == "bool" and for_widget.read_only:
|
||||
no_lf = True
|
||||
await child.show(no_lf=no_lf, ansi=A.FG_CYAN)
|
||||
end = ' '
|
||||
await child.show(end=end, ansi=A.FG_CYAN)
|
||||
else:
|
||||
await child.show()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue