@@ -635,6 +635,7 @@ def __init__(
635635 sort_reverse : bool ,
636636 sort_col_index : int | None ,
637637 columns : dict [str , "Column" ],
638+ thin_columns : bool ,
638639 ):
639640 # pylint: disable=too-many-positional-arguments
640641 self .allow_color = allow_color
@@ -645,6 +646,7 @@ def __init__(
645646 self .sort_reverse = sort_reverse
646647 self .sort_col_index = sort_col_index
647648 self .columns = columns
649+ self .thin_columns = thin_columns
648650
649651 self .log = gen_logger (f"{ self .__class__ .__qualname__ } " )
650652 self .getch_timeout = 1000
@@ -1142,6 +1144,9 @@ def draw_table(self) -> None:
11421144 ):
11431145 color_attr = self .label_colors ["gray" ]
11441146
1147+ if attr == "state" and self .thin_columns :
1148+ data = POWER_STATES [data ]["short" ]
1149+
11451150 line_content .setdefault (column .machine_header , {}).setdefault (
11461151 curr_height , (data , sel_attr or color_attr )
11471152 )
@@ -1229,6 +1234,32 @@ def draw_table(self) -> None:
12291234 max (curr_width , column .min_width ) + 1
12301235 )
12311236
1237+ state_counts = Counter (states )
1238+ total_states = len (states )
1239+ total_states_len = len (str (total_states ))
1240+ all_states = list (POWER_STATES )
1241+
1242+ if self .thin_columns :
1243+ top_text = "top"
1244+ domain_text = "D"
1245+ mem_text = "M"
1246+ mem_unit = MEMORY_UNIT [0 ]
1247+ cpu_text = "C"
1248+ selected_text = "*"
1249+ assigned_text = "a"
1250+ used_text = "u"
1251+ swap_text = "s"
1252+ else :
1253+ top_text = "qvm-top"
1254+ domain_text = "Domain{}" .format ("s" if total_states > 0 else "" )
1255+ mem_text = "Mem"
1256+ mem_unit = MEMORY_UNIT
1257+ cpu_text = "CPUs"
1258+ selected_text = "selected"
1259+ assigned_text = "assigned"
1260+ used_text = "used"
1261+ swap_text = "swap"
1262+
12321263 memory_total = Stats .host_memory_max
12331264 sum_memory_used_noswap = sum (memory_used_noswap_total )
12341265 sum_memory_used_swap = sum (memory_used_swap_total )
@@ -1254,24 +1285,28 @@ def draw_table(self) -> None:
12541285 header_cpu_prefix = " CPUs"
12551286 header_cpu_suffix = ": {} @ {}" .format (no_cpus , cpu_mhz )
12561287 if MEMORY_UNIT_PRECISION == 0 :
1257- header_mem_prefix = "Mem ({})" .format (MEMORY_UNIT )
1288+ header_mem_prefix = "{} ({})" .format (mem_text , mem_unit )
12581289 else :
1259- header_mem_prefix = "Mem ({}.{})" .format (
1260- MEMORY_UNIT , MEMORY_UNIT_PRECISION
1290+ header_mem_prefix = "{} ({}.{})" .format (
1291+ mem_text , mem_unit , MEMORY_UNIT_PRECISION
12611292 )
12621293 total_mem_len = len (str (memory_total ))
12631294 header_mem_total = "{}" .format (memory_total )
1264- header_mem_assigned_max_total = "{}({}%) assigned" .format (
1295+
1296+ header_mem_assigned_max_total = "{}({}%) {}" .format (
12651297 str (sum_memory_assigned_max_total ).rjust (total_mem_len ),
12661298 pct_memory_assigned_max_total ,
1299+ assigned_text ,
12671300 )
1268- header_mem_used_noswap = "{}({}%) used " .format (
1301+ header_mem_used_noswap = "{}({}%) {} " .format (
12691302 str (sum_memory_used_noswap ).rjust (total_mem_len ),
12701303 pct_memory_used_noswap ,
1304+ used_text ,
12711305 )
1272- header_mem_used_swap = "{}({}%) swap " .format (
1306+ header_mem_used_swap = "{}({}%) {} " .format (
12731307 str (sum_memory_used_swap ).rjust (total_mem_len ),
12741308 pct_memory_used_swap ,
1309+ swap_text ,
12751310 )
12761311 header_mem_suffix = ": "
12771312 header_mem_values = [
@@ -1282,21 +1317,21 @@ def draw_table(self) -> None:
12821317 ]
12831318 header_mem_suffix += ", " .join (header_mem_values )
12841319
1285- state_counts = Counter (states )
1286- total_states = len (states )
1287- total_states_len = len (str (total_states ))
1288- all_states = list (POWER_STATES )
12891320 state_parts = ["{}" .format (total_states )]
12901321 state_parts .append (
1291- "({} selected )" .format (
1292- str (len (self .selected_stats )).rjust (total_states_len )
1322+ "({} {} )" .format (
1323+ str (len (self .selected_stats )).rjust (total_states_len ), selected_text
12931324 )
12941325 )
12951326 for state in all_states :
1327+ if self .thin_columns :
1328+ pretty_state = POWER_STATES [state ]["short" ]
1329+ else :
1330+ pretty_state = state .lower () if state != "NA" else "NA"
12961331 state_parts .append (
12971332 "{} {}" .format (
12981333 str (state_counts .get (state , 0 )).rjust (total_states_len ),
1299- state . lower () if state != "NA" else "NA" ,
1334+ pretty_state ,
13001335 )
13011336 )
13021337 extra = [state for state in state_counts if state not in all_states ]
@@ -1307,7 +1342,7 @@ def draw_table(self) -> None:
13071342 state .lower (),
13081343 )
13091344 )
1310- header_dom_prefix = "Domain{}" . format ( "s" if total_states > 0 else "" )
1345+ header_dom_prefix = domain_text
13111346 header_dom_suffix = ": " + ", " .join (state_parts )
13121347
13131348 current_time = strftime ("%H:%M:%S" )
@@ -1323,7 +1358,7 @@ def draw_table(self) -> None:
13231358 )
13241359 sorted_header += sort_sign
13251360
1326- header_desc_prefix = "qvm-top"
1361+ header_desc_prefix = top_text
13271362 header_desc_suffix = f": { self .version } - { current_time } "
13281363 scroll_hint = (
13291364 f"{ scroll_start + 1 } -{ scroll_end } /{ total_items } "
@@ -1893,6 +1928,7 @@ def __init__(
18931928 sort_reverse : bool = False ,
18941929 sort_column : str | None = None ,
18951930 filter_query : str = "" ,
1931+ thin_columns : bool = False ,
18961932 ) -> None :
18971933 # pylint: disable=too-many-positional-arguments
18981934 self .app = app
@@ -1911,6 +1947,7 @@ def __init__(
19111947 sort_reverse = sort_reverse ,
19121948 sort_col_index = sort_col_index ,
19131949 columns = columns ,
1950+ thin_columns = thin_columns ,
19141951 )
19151952 self .log = gen_logger (f"{ self .__class__ .__qualname__ } " )
19161953 root_logger = getLogger ()
@@ -2152,6 +2189,7 @@ class Column:
21522189 def __init__ (
21532190 self ,
21542191 header : str ,
2192+ min_header : str | None = None ,
21552193 min_width : int | Callable = 0 ,
21562194 internal : bool = False ,
21572195 total : bool = False ,
@@ -2169,6 +2207,7 @@ def __init__(
21692207 self .percentage = percentage
21702208 self .summable_for_overall = summable_for_overall
21712209 self .untrusted = untrusted
2210+ self .min_header = min_header
21722211 if percentage_intensity is None :
21732212 self .percentage_intensity = [75 , 50 ]
21742213 else :
@@ -2281,6 +2320,7 @@ def __call__(self, _parser, _namespace, _values, option_string=None):
22812320)
22822321Column (
22832322 header = "STATE" ,
2323+ min_header = "S" ,
22842324 machine_header = "state" ,
22852325 min_width = max (len (state ) for state in POWER_STATES ),
22862326 doc = "Qube's power state." ,
@@ -2626,6 +2666,8 @@ async def run_async(args) -> int:
26262666 columns = {col : Column .columns [col ] for col in user_columns }
26272667 if args .thin_columns :
26282668 for col , column in columns .items ():
2669+ if column .min_header :
2670+ columns [col ].header = column .min_header
26292671 columns [col ].min_width = len (column .header )
26302672
26312673 sort_column = args .sort_column or None
@@ -2646,6 +2688,7 @@ async def run_async(args) -> int:
26462688 columns = columns ,
26472689 allow_color = not (args .no_color or NO_COLOR ),
26482690 filter_query = args .filter ,
2691+ thin_columns = args .thin_columns
26492692 )
26502693 tasks = [
26512694 create_task (dispatcher .listen_for_events ()),
0 commit comments