Skip to content

Commit 663f8ae

Browse files
committedJul 14, 2024·
Replace TFmt with Rich.
1 parent 933cfaa commit 663f8ae

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed
 

‎rockit/mount/talon/constants.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

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

19-
from rockit.common import TFmt
20-
2119

2220
class CommandStatus:
2321
"""Numeric return codes"""
@@ -82,14 +80,14 @@ class TelState:
8280
6: 'LIMITING',
8381
}
8482

85-
_formats = {
86-
0: TFmt.Red + TFmt.Bold,
87-
1: TFmt.Red + TFmt.Bold,
88-
2: TFmt.Yellow + TFmt.Bold,
89-
3: TFmt.Green + TFmt.Bold,
90-
4: TFmt.Yellow + TFmt.Bold,
91-
5: TFmt.Yellow + TFmt.Bold,
92-
6: TFmt.Yellow + TFmt.Bold,
83+
_colors = {
84+
0: 'red',
85+
1: 'red',
86+
2: 'yellow',
87+
3: 'green',
88+
4: 'yellow',
89+
5: 'yellow',
90+
6: 'yellow'
9391
}
9492

9593
@classmethod
@@ -99,9 +97,9 @@ def label(cls, status, formatting=False):
9997
Set formatting=true to enable terminal formatting characters
10098
"""
10199
if formatting:
102-
if status in cls._formats and status in cls._formats:
103-
return cls._formats[status] + cls._labels[status] + TFmt.Clear
104-
return TFmt.Red + TFmt.Bold + 'UNKNOWN' + TFmt.Clear
100+
if status in cls._labels and status in cls._colors:
101+
return f'[b][{cls._colors[status]}]{cls._labels[status]}[/{cls._colors[status]}][/b]'
102+
return '[b][red]UNKNOWN[/red][/b]'
105103

106104
if status in cls._labels:
107105
return cls._labels[status]
@@ -132,6 +130,6 @@ def label(cls, status, formatting=False):
132130
label = 'UNKNOWN'
133131

134132
if formatting:
135-
return TFmt.Bold + label + TFmt.Clear
133+
return f'[b]{label}[/b]'
136134

137135
return label

‎tel

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import sys
2323
import Pyro4
2424
from astropy.coordinates import Angle, SkyCoord
2525
import astropy.units as u
26+
from rockit.common import print
2627
from rockit.mount.talon import CommandStatus, TelState, Config
27-
from rockit.common import TFmt
2828

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

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

4747
config = Config(files[0])
@@ -190,7 +190,7 @@ def calibrate(config, args):
190190
return teld.find_homes()
191191
return teld.find_limits()
192192

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

196196

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

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

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

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

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

245245
return 0
246246

@@ -280,7 +280,7 @@ def ping_teld(config):
280280

281281
def print_usage():
282282
"""Prints the utility help"""
283-
print(f'usage: {SCRIPT_NAME} <command> [<args>]')
283+
print(f'usage: {SCRIPT_NAME} <command> \\[<args>]')
284284
print()
285285
print('general commands:')
286286
print(' status print a human-readable summary of the telescope status')

0 commit comments

Comments
 (0)
Please sign in to comment.