def _format_ping(self, output: DSA) -> str: prefix = f"net {self.interface} [ping {self.ping_server}] " if output.pop("err_ping_timeout", False): return prefix + color("timed out", RED) elif output.pop("err_ping_loading", False): return prefix + color("loading", VIOLET) elif output.pop("err_ping_fail", False): return prefix + color(output["ping_fail_status"], ORANGE) else: m, std, mx, loss = ( output["ping_med"], output["ping_mad"], output["ping_max"], output["ping_loss"], ) med_str = colorize_float(m, 4, 1, (10.0, 20.0, 50.0, 100.0)) mad_str = colorize_float(std, 3, 1, (1.0, 3.0, 9.0, 27.0)) max_str = colorize_float(mx, 3, 0, (20.0, 50.0, 100.0, 250.0)) loss_str = colorize_float(100 * loss, 4, 1, (1e-4, 1e-1, 1e-0, 5e-0)) return prefix + (f"[med {med_str} mad {mad_str} max {max_str} ms] " f"[loss {loss_str}%]")
def format(self, output: DSA) -> str: mp = output["used_frac"] * 100 ug = output["used_KiB"] / (1 << 20) col = get_color(mp) fug = color(f"{ug:4.1f}", col) fmp = color(f"{mp:3.0f}", col) return f"mem [used {fug} GiB ({fmp}%)]"
def format(self, output: DSA) -> str: mm = output["i_mem_mib"] mp = output["i_mem_pct"] lp = output["i_load_pct"] temp = output["i_temp_C"] return "gpu [mem used {} MiB ({}%)] [load {}%] [temp {}C]".format( color("{: 4d}".format(mm), get_color(mp)), color("{: 3d}".format(mp), get_color(mp)), color("{: 3d}".format(lp), get_color(lp)), mk_tcolor_str(temp), )
def format(self, info: DSA) -> str: context = "disk [" + self.disk + " {}]" if info.pop("err_no_disk", False): return context.format(color("absent", BROWN)) r_bar = self.BARS[bisect(self.THRESHS, info["bps_read"])] w_bar = self.BARS[bisect(self.THRESHS, info["bps_write"])] return context.format(color(r_bar, BLUE) + color(w_bar, ORANGE))
def format(self, output: DSA) -> str: prefix = "wlan {} [".format(self.wlan_if) suffix = "]" if output.pop("err_down", False): return prefix + color("down", RED) + suffix elif output.pop("err_disconnected", False): return prefix + color("---", VIOLET) + suffix template = prefix + "{}] [{}%" + suffix quality = 100 * output["quality"] q_color = get_color(quality, do_reverse=True) q_str = color("{:3.0f}".format(quality), q_color) return template.format(output["ssid"] if self.show_ssid else "<>", q_str)
def _format_bw(self, output: DSA) -> str: prefix = f"net {self.interface} " if output.pop("err_if_gone", False): return prefix + color("gone", RED) if output.pop("err_if_down", False): return prefix + color("down", ORANGE) if output.pop("err_if_loading", False): return prefix + color("loading", VIOLET) sfs = [color("B/s", GREY), color("B/s", GREY)] vals = [output["Bps_down"], output["Bps_up"]] for ix in range(2): for mag, sf in [ (30, color("G/s", VIOLET)), (20, color("M/s", WHITE)), (10, "K/s"), ]: if vals[ix] > 1 << mag: vals[ix] /= 1 << mag sfs[ix] = sf break return (prefix + f"[u {vals[1]:6.1f} {sfs[1]:>3s}] " + f"[d {vals[0]:6.1f} {sfs[0]:>3s}]")
def format(self, info: DSA) -> str: e_prefix = f"bat{self.bat_id}" + " [{}]" if info.pop("err_no_bat", False): return e_prefix.format(color("no bat", RED)) elif info.pop("err_bad_format", False): return e_prefix.format(color("loading", ORANGE)) # if self._clicked, show % of design capacity instead # pct = output['f_chr_pct'] if self._clicked: pct = 100 * info["charged_f_design"] else: pct = 100 * info["charged_f"] pct_str = color(f"{pct:3.0f}", get_color(pct, do_reverse=True)) st = info["status"] if st == self.STATUS_CHR: st_string = color("chr", GREEN) elif st == self.STATUS_DIS: st_string = color("dis", ORANGE) elif st == self.STATUS_FUL: st_string = color("ful", BLUE) elif st == self.STATUS_BAL: st_string = color("bal", CYAN) else: st_string = color("unk", VIOLET) raw_sec_rem = info.get("sec_rem") if raw_sec_rem is None: rem_string = color("loading", VIOLET) elif raw_sec_rem < 0: rem_string = "--:--" else: isr = round(raw_sec_rem) min_rem = (isr // 60) % 60 hr_rem = isr // 3600 rem_string = f"{hr_rem:02d}:{min_rem:02d}" x = ["[", "]"] if not self._clicked else ["<", ">"] return f"bat {x[0]}{pct_str}%{x[1]} [{rem_string} rem, {st_string}]"
def format(self, output: DSA) -> str: pu = output["p_u"] * 100 pk = output["p_k"] * 100 no_temp = output.pop("err_no_temp", False) no_sensors = output.pop("err_no_sensors", False) if no_sensors: temp_str = color("no sensors", RED) elif no_temp: temp_str = color("unk", ORANGE) else: temp = output["temp_C"] temp_str = f"{mk_tcolor_str(temp)} C" if self.show_breakdown: load_str = ("u " + color(f"{pu:3.0f}", get_color(pu)) + "% k" + color(f"{pk:3.0f}", get_color(pk)) + "%") else: load_str = "load " + color(f"{pu + pk:3.0f}%", get_color(pu + pk)) return f"cpu [{load_str}] [temp {temp_str}]"
def format(self, read_output: dict[str, Any]) -> str: if "err_failed_read" in read_output: return color("failed to read ip", "red") else: return read_output["ip"]