Skip to content

Commit

Permalink
Refactor column widths and add local and remote name getters
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmoreno committed Dec 20, 2023
1 parent 6dd6950 commit ce5beaa
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions cli/rtpmidid-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ def __init__(self, conn: Connection):
"align": "left",
},
{
"name": "Name",
"get": lambda data: safe_get(data, "name"),
"name": "Local Name",
"get": self.get_local_name,
"width": 0,
"align": "left",
},
{
"name": "Remote Name",
"get": self.get_remote_name,
"width": 0,
"align": "left",
},
Expand Down Expand Up @@ -219,11 +225,11 @@ def __init__(self, conn: Connection):
]

# make Name column as wide as possible
self.COLUMNS[2]["width"] = (
self.width
- sum(x["width"] for x in self.COLUMNS)
- (1 * (len(self.COLUMNS) - 1))
)
auto_width_count = len([x for x in self.COLUMNS if x["width"] == 0])
extra_width = self.width - sum((x["width"] + 1) for x in self.COLUMNS) + 1
for col in self.COLUMNS:
if col["width"] == 0:
col["width"] = extra_width // auto_width_count
self.max_cols = len(self.COLUMNS)
self.print_data = []

Expand Down Expand Up @@ -430,6 +436,18 @@ def get_latency(self, data):
stddev = safe_get(data, "peer", "latency_ms", "stddev")
return f"{avg}ms \u00B1 {stddev}ms"

def get_local_name(self, data):
type_ = safe_get(data, "type")
if type_.startswith("local:"):
return safe_get(data, "name")
return safe_get(data, "peer", "local", "name")

def get_remote_name(self, data):
type_ = safe_get(data, "type")
if type_.startswith("network:"):
return safe_get(data, "name")
return safe_get(data, "peer", "remote", "name")

##
## Top level components
##
Expand Down

0 comments on commit ce5beaa

Please sign in to comment.