Mercurial > libervia-backend
changeset 3407:2f0be2b7de68
jp: replace `no_lf` argument by `end` in `disp` (same as in `print`)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Nov 2020 14:53:16 +0100 |
parents | 4c15271118a2 |
children | 19bc03743aeb |
files | sat_frontends/jp/base.py sat_frontends/jp/cmd_debug.py sat_frontends/jp/cmd_input.py sat_frontends/jp/cmd_shell.py sat_frontends/jp/xmlui_manager.py |
diffstat | 5 files changed, 24 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/sat_frontends/jp/base.py Thu Nov 12 14:53:15 2020 +0100 +++ b/sat_frontends/jp/base.py Thu Nov 12 14:53:16 2020 +0100 @@ -234,25 +234,19 @@ 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 @@ 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 @@ """ 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:
--- a/sat_frontends/jp/cmd_debug.py Thu Nov 12 14:53:15 2020 +0100 +++ b/sat_frontends/jp/cmd_debug.py Thu Nov 12 14:53:16 2020 +0100 @@ -203,10 +203,14 @@ 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))
--- a/sat_frontends/jp/cmd_input.py Thu Nov 12 14:53:15 2020 +0100 +++ b/sat_frontends/jp/cmd_input.py Thu Nov 12 14:53:16 2020 +0100 @@ -194,9 +194,10 @@ 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 @@ ) 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,
--- a/sat_frontends/jp/cmd_shell.py Thu Nov 12 14:53:15 2020 +0100 +++ b/sat_frontends/jp/cmd_shell.py Thu Nov 12 14:53:16 2020 +0100 @@ -146,7 +146,7 @@ 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:")))
--- a/sat_frontends/jp/xmlui_manager.py Thu Nov 12 14:53:15 2020 +0100 +++ b/sat_frontends/jp/xmlui_manager.py Thu Nov 12 14:53:16 2020 +0100 @@ -199,13 +199,13 @@ 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 @@ 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 @@ "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()