comparison sat_frontends/jp/base.py @ 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 67e306cae157
children 19bc03743aeb
comparison
equal deleted inserted replaced
3406:4c15271118a2 3407:2f0be2b7de68
232 pass 232 pass
233 else: 233 else:
234 for cache_data in cache: 234 for cache_data in cache:
235 await cache_data[0](*cache_data[1:]) 235 await cache_data[0](*cache_data[1:])
236 236
237 def disp(self, msg, verbosity=0, error=False, no_lf=False): 237 def disp(self, msg, verbosity=0, error=False, end='\n'):
238 """Print a message to user 238 """Print a message to user
239 239
240 @param msg(unicode): message to print 240 @param msg(unicode): message to print
241 @param verbosity(int): minimal verbosity to display the message 241 @param verbosity(int): minimal verbosity to display the message
242 @param error(bool): if True, print to stderr instead of stdout 242 @param error(bool): if True, print to stderr instead of stdout
243 @param no_lf(bool): if True, do not emit line feed at the end of line 243 @param end(str): string appended after the last value, default a newline
244 """ 244 """
245 if self.verbosity >= verbosity: 245 if self.verbosity >= verbosity:
246 if error: 246 if error:
247 if no_lf: 247 print(msg, end=end, file=sys.stderr)
248 print(msg, end=' ', file=sys.stderr)
249 else:
250 print(msg, file=sys.stderr)
251 else: 248 else:
252 if no_lf: 249 print(msg, end=end)
253 print(msg, end=' ')
254 else:
255 print(msg)
256 250
257 async def output(self, type_, name, extra_outputs, data): 251 async def output(self, type_, name, extra_outputs, data):
258 if name in extra_outputs: 252 if name in extra_outputs:
259 method = extra_outputs[name] 253 method = extra_outputs[name]
260 else: 254 else:
682 else: 676 else:
683 stdin_fut.set_exception(EOFError()) 677 stdin_fut.set_exception(EOFError())
684 678
685 async def ainput(self, msg=''): 679 async def ainput(self, msg=''):
686 """Asynchronous version of buildin "input" function""" 680 """Asynchronous version of buildin "input" function"""
687 self.disp(msg, no_lf=True) 681 self.disp(msg, end=' ')
688 sys.stdout.flush() 682 sys.stdout.flush()
689 loop = asyncio.get_running_loop() 683 loop = asyncio.get_running_loop()
690 stdin_fut = loop.create_future() 684 stdin_fut = loop.create_future()
691 loop.add_reader(sys.stdin, self._read_stdin, stdin_fut) 685 loop.add_reader(sys.stdin, self._read_stdin, stdin_fut)
692 return await stdin_fut 686 return await stdin_fut
1148 1142
1149 @param error_msg(unicode): error message as sent by bridge.progressError 1143 @param error_msg(unicode): error message as sent by bridge.progressError
1150 """ 1144 """
1151 self.disp(_(f"Error while doing operation: {e}"), error=True) 1145 self.disp(_(f"Error while doing operation: {e}"), error=True)
1152 1146
1153 def disp(self, msg, verbosity=0, error=False, no_lf=False): 1147 def disp(self, msg, verbosity=0, error=False, end='\n'):
1154 return self.host.disp(msg, verbosity, error, no_lf) 1148 return self.host.disp(msg, verbosity, error, end)
1155 1149
1156 def output(self, data): 1150 def output(self, data):
1157 try: 1151 try:
1158 output_type = self._output_type 1152 output_type = self._output_type
1159 except AttributeError: 1153 except AttributeError: