Skip to content

Commit

Permalink
Replace TFmt with Rich.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Jul 14, 2024
1 parent 933cfaa commit 663f8ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
26 changes: 12 additions & 14 deletions rockit/mount/talon/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

"""Constants and status codes used by talond"""

from rockit.common import TFmt


class CommandStatus:
"""Numeric return codes"""
Expand Down Expand Up @@ -82,14 +80,14 @@ class TelState:
6: 'LIMITING',
}

_formats = {
0: TFmt.Red + TFmt.Bold,
1: TFmt.Red + TFmt.Bold,
2: TFmt.Yellow + TFmt.Bold,
3: TFmt.Green + TFmt.Bold,
4: TFmt.Yellow + TFmt.Bold,
5: TFmt.Yellow + TFmt.Bold,
6: TFmt.Yellow + TFmt.Bold,
_colors = {
0: 'red',
1: 'red',
2: 'yellow',
3: 'green',
4: 'yellow',
5: 'yellow',
6: 'yellow'
}

@classmethod
Expand All @@ -99,9 +97,9 @@ def label(cls, status, formatting=False):
Set formatting=true to enable terminal formatting characters
"""
if formatting:
if status in cls._formats and status in cls._formats:
return cls._formats[status] + cls._labels[status] + TFmt.Clear
return TFmt.Red + TFmt.Bold + 'UNKNOWN' + TFmt.Clear
if status in cls._labels and status in cls._colors:
return f'[b][{cls._colors[status]}]{cls._labels[status]}[/{cls._colors[status]}][/b]'
return '[b][red]UNKNOWN[/red][/b]'

if status in cls._labels:
return cls._labels[status]
Expand Down Expand Up @@ -132,6 +130,6 @@ def label(cls, status, formatting=False):
label = 'UNKNOWN'

if formatting:
return TFmt.Bold + label + TFmt.Clear
return f'[b]{label}[/b]'

return label
30 changes: 15 additions & 15 deletions tel
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import sys
import Pyro4
from astropy.coordinates import Angle, SkyCoord
import astropy.units as u
from rockit.common import print
from rockit.mount.talon import CommandStatus, TelState, Config
from rockit.common import TFmt

SCRIPT_NAME = os.path.basename(sys.argv[0])

Expand All @@ -41,7 +41,7 @@ def run_command(command, args):
files = glob.glob("/etc/mountd/*.json")
if len(files) != 1:
print('error: failed to guess the default config file. ' +
'Run as MOUNTD_CONFIG_PATH=/path/to/config.json tel <command> [<args>]')
'Run as MOUNTD_CONFIG_PATH=/path/to/config.json tel <command> \\[<args>]')
return 1

config = Config(files[0])
Expand Down Expand Up @@ -190,7 +190,7 @@ def calibrate(config, args):
return teld.find_homes()
return teld.find_limits()

print(f'usage: {SCRIPT_NAME} cal [home|limits]')
print(f'usage: {SCRIPT_NAME} cal \\[home|limits]')
return -1


Expand Down Expand Up @@ -218,29 +218,29 @@ def status(config, _):
ra_offset_desc = ''
ra_offset = Angle(data['offset_ra'], unit=u.deg).to(u.hourangle)
if ra_offset != 0:
ra_offset_desc = ' with offset ' + TFmt.Bold + ra_offset.to_string(sep=':', precision=2) + TFmt.Clear
ra_offset_desc = ' with offset [b]' + ra_offset.to_string(sep=':', precision=2) + '[/b]'

dec_offset_desc = ''
dec_offset = Angle(data['offset_dec'], unit=u.deg)
if dec_offset != 0:
dec_offset_desc = ' with offset ' + TFmt.Bold + dec_offset.to_string(sep=':', precision=2) + TFmt.Clear
dec_offset_desc = ' with offset [b]' + dec_offset.to_string(sep=':', precision=2) + '[/b]'

moon_desc = TFmt.Bold + f'{data["moon_separation"]:.0f}\u00B0' + TFmt.Clear
sun_desc = TFmt.Bold + f'{data["sun_separation"]:.0f}\u00B0' + TFmt.Clear
moon_desc = f'[b]{data["moon_separation"]:.0f}\u00B0[/b]'
sun_desc = f'[b]{data["sun_separation"]:.0f}\u00B0[/b]'

print(' RA is ' + TFmt.Bold + ra_desc + TFmt.Clear + ra_offset_desc)
print(' Dec is ' + TFmt.Bold + dec_desc + TFmt.Clear + dec_offset_desc)
print(' Altitude is ' + TFmt.Bold + alt_desc + TFmt.Clear)
print(' Azimuth is ' + TFmt.Bold + az_desc + TFmt.Clear)
print(f' RA is [b]{ra_desc}[/b]' + ra_offset_desc)
print(f' Dec is [b]{dec_desc}[/b]' + dec_offset_desc)
print(f' Altitude is [b]{alt_desc}[/b]')
print(f' Azimuth is [b]{az_desc}[/b]')
print(' Moon separation is ' + moon_desc)
print(' Sun separation is ' + sun_desc)
if 'telescope_focus_um' in data:
print(' Telescope focus is ' + TFmt.Bold + f'{data["telescope_focus_um"]:.2f}' + TFmt.Clear + 'um')
print(f' Telescope focus is [b]{data["telescope_focus_um"]:.2f}[/b]um')
else:
print(' Axes are ' + TFmt.Bold + TFmt.Red + 'NOT HOMED' + TFmt.Clear)
print(' Axes are [b][red]NOT HOMED[/red][/b]')

lst_desc = Angle(data['lst'], unit=u.deg).to(u.hourangle).to_string(sep=':', precision=2)
print(' Local sidereal time is ' + TFmt.Bold + lst_desc + TFmt.Clear)
print(f' Local sidereal time is [b]{lst_desc}[/b]')

return 0

Expand Down Expand Up @@ -280,7 +280,7 @@ def ping_teld(config):

def print_usage():
"""Prints the utility help"""
print(f'usage: {SCRIPT_NAME} <command> [<args>]')
print(f'usage: {SCRIPT_NAME} <command> \\[<args>]')
print()
print('general commands:')
print(' status print a human-readable summary of the telescope status')
Expand Down

0 comments on commit 663f8ae

Please sign in to comment.