@@ -291,10 +291,17 @@ def make(
291291
292292 possible_columns : dict [str , Column ] = {}
293293
294- def add_column (key : str , name : str , ** kwargs : Any ) -> None :
294+ def add_column (
295+ flag : Flag | str , key : str , name : str | None = None , ** kwargs : Any
296+ ) -> None :
297+ if isinstance (flag , Flag ):
298+ assert flag .name is not None , f"invalid flag: { flag } "
299+ fname = flag .name
300+ else :
301+ fname = flag
295302 if config is not None :
296303 try :
297- cfg = config [name .lower ()]
304+ cfg = config [fname .lower ()]
298305 except KeyError :
299306 pass
300307 else :
@@ -308,10 +315,13 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
308315 )
309316 kwargs ["default_color" ] = cfg .color
310317 assert key not in possible_columns , f"duplicated key { key } "
311- possible_columns [key ] = Column (key = key , name = name , ** kwargs )
318+ possible_columns [key ] = Column (
319+ key = key , name = name if name is not None else fname , ** kwargs
320+ )
312321
313322 if Flag .APPNAME & flag :
314323 add_column (
324+ Flag .APPNAME ,
315325 key = "application_name" ,
316326 name = "APP" ,
317327 min_width = 16 ,
@@ -321,8 +331,8 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
321331 )
322332 if Flag .CLIENT & flag :
323333 add_column (
334+ Flag .CLIENT ,
324335 key = "client" ,
325- name = "CLIENT" ,
326336 min_width = 16 ,
327337 max_width = 16 ,
328338 justify = "right" ,
@@ -331,13 +341,15 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
331341 )
332342 if Flag .CPU & flag :
333343 add_column (
344+ Flag .CPU ,
334345 key = "cpu" ,
335346 name = "CPU%" ,
336347 min_width = 6 ,
337348 sort_key = SortKey .cpu ,
338349 )
339350 if Flag .DATABASE & flag :
340351 add_column (
352+ Flag .DATABASE ,
341353 key = "database" ,
342354 name = "DATABASE(*)" if filters .dbname else "DATABASE" ,
343355 min_width = max_db_length ,
@@ -349,6 +361,7 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
349361 )
350362 if Flag .IOWAIT & flag :
351363 add_column (
364+ Flag .IOWAIT ,
352365 key = "io_wait" ,
353366 name = "IOW" ,
354367 min_width = 4 ,
@@ -357,6 +370,7 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
357370 )
358371 if Flag .MEM & flag :
359372 add_column (
373+ Flag .MEM ,
360374 key = "mem" ,
361375 name = "MEM%" ,
362376 min_width = 4 ,
@@ -365,27 +379,29 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
365379 )
366380 if Flag .MODE & flag :
367381 add_column (
382+ Flag .MODE ,
368383 key = "mode" ,
369- name = "MODE" ,
370384 min_width = 16 ,
371385 max_width = 16 ,
372386 justify = "right" ,
373387 value_color = colors .lock_mode ,
374388 )
375389 if Flag .PID & flag :
376390 add_column (
391+ Flag .PID ,
377392 key = "pid" ,
378- name = "PID" ,
379393 min_width = 6 ,
380394 default_color = "cyan" ,
381395 )
382396 add_column (
397+ "query" ,
383398 key = "query" ,
384399 name = "Query" ,
385400 min_width = 2 ,
386401 )
387402 if Flag .READ & flag :
388403 add_column (
404+ Flag .READ ,
389405 key = "read" ,
390406 name = "READ/s" ,
391407 min_width = 8 ,
@@ -394,23 +410,24 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
394410 )
395411 if Flag .RELATION & flag :
396412 add_column (
413+ Flag .RELATION ,
397414 key = "relation" ,
398- name = "RELATION" ,
399415 min_width = 9 ,
400416 max_width = 9 ,
401417 justify = "right" ,
402418 default_color = "cyan" ,
403419 )
404420 add_column (
421+ "state" ,
405422 key = "state" ,
406- name = "state" ,
407423 min_width = 17 ,
408424 justify = "right" ,
409425 transform = utils .short_state ,
410426 value_color = colors .short_state ,
411427 )
412428 if Flag .TIME & flag :
413429 add_column (
430+ Flag .TIME ,
414431 key = "duration" ,
415432 name = "TIME+" ,
416433 min_width = 9 ,
@@ -421,23 +438,24 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
421438 )
422439 if Flag .TYPE & flag :
423440 add_column (
441+ Flag .TYPE ,
424442 key = "type" ,
425- name = "TYPE" ,
426443 min_width = 16 ,
427444 max_width = 16 ,
428445 justify = "right" ,
429446 )
430447 if Flag .USER & flag :
431448 add_column (
449+ Flag .USER ,
432450 key = "user" ,
433- name = "USER" ,
434451 min_width = 16 ,
435452 max_width = 16 ,
436453 justify = "right" ,
437454 default_color = "bold_black" ,
438455 )
439456 if Flag .WAIT & flag :
440457 add_column (
458+ Flag .WAIT ,
441459 key = "wait" ,
442460 name = "Waiting" ,
443461 min_width = 16 ,
@@ -448,6 +466,7 @@ def add_column(key: str, name: str, **kwargs: Any) -> None:
448466 )
449467 if Flag .WRITE & flag :
450468 add_column (
469+ Flag .WRITE ,
451470 key = "write" ,
452471 name = "WRITE/s" ,
453472 min_width = 8 ,
0 commit comments