Commit a4cc57fd authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho Committed by Jose Tiago Macara Coutinho
Browse files

scan: add output_mode option

Allows to choose between usual tail mode and monitor mode:
- Tail mode prints a scan_line in a new console line.
- Monitor mode keeps printing scan line in the same console line.
parent 31b68b14
......@@ -497,11 +497,15 @@ def timescan(count_time, *counters, **kwargs):
scan object and acquisition chain
return_scan (bool): False by default
npoints (int): number of points [default: 0, meaning infinite number of points]
output_mode (str): valid are 'tail' (append each line to output) or
'monitor' (refresh output in single line)
[default: 'tail']
"""
scan_info = { 'type': kwargs.get('type', 'timescan'),
'save': kwargs.get('save', True),
'title': kwargs.get('title'),
'sleep_time': kwargs.get('sleep_time') }
'sleep_time': kwargs.get('sleep_time') ,
'output_mode': kwargs.get('output_mode', 'tail') }
if scan_info['title'] is None:
args = scan_info['type'], count_time
......@@ -562,6 +566,9 @@ def loopscan(npoints, count_time, *counters, **kwargs):
run (bool): if True (default), run the scan. False means just create
scan object and acquisition chain
return_scan (bool): False by default
output_mode (str): valid are 'tail' (append each line to output) or
'monitor' (refresh output in single line)
[default: 'tail']
"""
kwargs.setdefault('npoints', npoints)
kwargs.setdefault('name', 'loopscan')
......
......@@ -152,8 +152,10 @@ class ScanListener:
self._point_nb += 1
line = " ".join([self.col_templ[i].format(v) for i, v in enumerate(values)])
if self.term.is_a_tty:
print_(self.term.clear_bol + '\r', end='')
print_(line)
monitor = scan_info.get('output_mode', 'tail') == 'monitor'
print_(line, end=monitor and '\r' or '\n', flush=True)
else:
print_(line)
def __on_scan_end(self, scan_info):
if scan_info['type'] == 'ct':
......@@ -166,7 +168,9 @@ class ScanListener:
end = datetime.datetime.fromtimestamp(time.time())
start = datetime.datetime.fromtimestamp(scan_info['start_time_stamp'])
dt = end - start
msg = 'Took {0}'.format(dt)
if scan_info.get('output_mode', 'tail') == 'monitor' and self.term.is_a_tty:
print_()
msg = '\nTook {0}'.format(dt)
if 'estimation' in scan_info:
time_estimation = scan_info['estimation']['total_time']
msg += ' (estimation was for {0})'.format(datetime.timedelta(seconds=time_estimation))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment