11from typing import List
22
33from rich import print
4- from rich .progress import track
5- from rich .table import Table
4+ from rich .progress import BarColumn , Progress , SpinnerColumn , TextColumn , TimeElapsedColumn , track
5+ from rich .table import Column , Table
66
77from mpflash .mpremoteboard import MPRemoteBoard
88
99from .config import config
1010from .logger import console
1111
12+ rp_spinner = SpinnerColumn (finished_text = "✅" )
13+ rp_text = TextColumn ("{task.description} {task.fields[device]}" , table_column = Column (ratio = 1 ))
14+ rp_bar = BarColumn (bar_width = None , table_column = Column (ratio = 2 ))
15+
1216
1317def list_mcus (bluetooth : bool = False ):
1418 """
@@ -21,12 +25,24 @@ def list_mcus(bluetooth: bool = False):
2125 """
2226 conn_mcus = [MPRemoteBoard (sp ) for sp in MPRemoteBoard .connected_boards (bluetooth ) if sp not in config .ignore_ports ]
2327
24- for mcu in track (conn_mcus , description = "Getting board info" , transient = True , update_period = 0.1 ):
28+ # a lot of boilerplate to show a progress bar with the comport currenlty scanned
29+ with Progress (rp_spinner , rp_text , rp_bar , TimeElapsedColumn ()) as progress :
30+ tsk_scan = progress .add_task ("[red]Scanning" , visible = False )
31+ progress .tasks [tsk_scan ].fields ["device" ] = "..."
32+ progress .tasks [tsk_scan ].visible = True
33+ progress .start_task (tsk_scan )
2534 try :
26- mcu .get_mcu_info ()
27- except ConnectionError as e :
28- print (f"Error: { e } " )
29- continue
35+ for mcu in conn_mcus :
36+ progress .update (tsk_scan , device = mcu .serialport .replace ("/dev/" , "" ))
37+ try :
38+ mcu .get_mcu_info ()
39+ except ConnectionError as e :
40+ print (f"Error: { e } " )
41+ continue
42+ finally :
43+ # transient
44+ progress .stop_task (tsk_scan )
45+ progress .tasks [tsk_scan ].visible = False
3046 return conn_mcus
3147
3248
0 commit comments