Commit 7017829a authored by Jibril Mammeri's avatar Jibril Mammeri
Browse files

Copy from 27f69535 to solve #2825

parent 313fa9e6
Pipeline #58415 passed with stages
in 86 minutes and 1 second
......@@ -868,41 +868,40 @@ def __umove(*args, **kwargs):
else:
motor_names.append(global_map.alias_or_name(axis))
col_len = max(max(map(len, motor_names)), 8)
hfmt = "^{width}".format(width=col_len)
rfmt = ">{width}.03f".format(width=col_len)
print("")
print(" \n")
# print(" " + __row(motor_names, hfmt, sep=" "))
first_row = __row(motor_names, hfmt, sep=" ")
row_len = len(first_row)
print(first_row.rjust(row_len + 5))
print("")
magic_char = "\033[F"
def format_group(group):
positions = group.position_with_reals
dials = group.dial_with_reals
user_pos = __row_positions(positions, motors, rfmt, sep=" ")
dial_pos = __row_positions(dials, motors, rfmt, sep=" ")
row = f"user {user_pos}\ndial {dial_pos}"
ret_depth = magic_char * row.count("\n")
return f"{ret_depth}{row}"
previous_line = None
while group.is_moving:
__print_names_and_positions(group, motors, motor_names, col_len)
previous_line = format_group(group)
print(previous_line, end="", flush=True)
sleep(0.1)
# print last time for final positions
__print_names_and_positions(group, motors, motor_names, col_len)
last_line = format_group(group)
if previous_line != last_line:
print(last_line, end="", flush=True)
print("")
return group, motor_pos
def __print_names_and_positions(group, motors, motor_names, col_len):
hfmt = "^{width}".format(width=col_len)
rfmt = ">{width}.03f".format(width=col_len)
xrow, xcol = os.popen("stty size").read().split()
xslots = int((int(xcol) - 5) / (col_len + 2))
positions = [group.position_with_reals[m] for m in motors]
dials = [group.dial_with_reals[m] for m in motors]
idx = 0
while idx < len(motor_names):
if idx == 0:
row = str()
names = __row(motor_names[idx : idx + xslots], hfmt, sep=" ")
user_pos = __row(positions[idx : idx + xslots], rfmt, sep=" ")
dial_pos = __row(dials[idx : idx + xslots], rfmt, sep=" ")
row += f" {names}\nuser {user_pos}\ndial {dial_pos}\n \n"
idx += xslots
ret_depth = "\033[F" * row.count("\n")
print("{}{}".format(ret_depth, row), end="", flush=True)
def __pyhighlight(code, bg="dark", outfile=None):
formatter = TerminalFormatter(bg=bg)
return highlight(code, PythonLexer(), formatter, outfile=outfile)
......
......@@ -226,26 +226,35 @@ def test_umv_signature(session):
assert str(umv.__signature__) == "(*args: 'motor1, pos1, motor2, pos2, ...')"
OUTPUT_UMV_ROBY = """
roby
\x1b[Fuser 0.000
dial 0.000\x1b[Fuser 1.000
dial 1.000
"""
OUTPUT_UMV_CALC_MOT2 = """
calc_mot2[keV] calc_mot1[keV] roby
\x1b[Fuser 0.000 0.000 0.000
dial 0.000 0.000 0.000\x1b[Fuser 4.000 2.000 1.000
dial 4.000 2.000 1.000
"""
def test_umv_shell(capfd, default_session):
# output will contain ANSI control chars, including \x03f[ (return to
# start of line) so it is much easier to test for some expected strings
# than testing strict equality
roby = default_session.config.get("roby")
umv(roby, 1)
output = capfd.readouterr().out
assert output.startswith("\n roby")
assert "user 1.000\n" in output
assert "dial 1.000\n" in output
assert output == OUTPUT_UMV_ROBY
def test_umv_calc_shell(capfd, default_session):
calc_mot2 = default_session.config.get("calc_mot2")
try:
umv(calc_mot2, 8)
umv(calc_mot2, 4)
output = capfd.readouterr().out
assert output.startswith(
"\n calc_mot2[keV] calc_mot1[keV] roby \n"
)
assert "user 8.000 4.000 2.000\n" in output
assert "dial 8.000 4.000 2.000\n" in output
assert output == OUTPUT_UMV_CALC_MOT2
finally:
default_session.config.get("calc_mot1").controller.close()
calc_mot2.controller.close()
......
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