sane-sysload: make the format CLI args friendlier
This commit is contained in:
@@ -66,6 +66,7 @@ end
|
|||||||
if vars.percent ~= nil then
|
if vars.percent ~= nil then
|
||||||
bat_args = bat_args .. " --percent-suffix '" .. vars.percent .. "'"
|
bat_args = bat_args .. " --percent-suffix '" .. vars.percent .. "'"
|
||||||
end
|
end
|
||||||
|
bat_args = bat_args .. " {bat}"
|
||||||
|
|
||||||
-- N.B.: `[[ <text> ]]` is Lua's multiline string literal
|
-- N.B.: `[[ <text> ]]` is Lua's multiline string literal
|
||||||
conky.text = [[
|
conky.text = [[
|
||||||
@@ -73,8 +74,8 @@ ${color1}${shadecolor 707070}${font sans-serif:size=50:style=Bold}${alignc}${exe
|
|||||||
${color2}${shadecolor a4d7d0}${font sans-serif:size=20}${alignc}${exec date +"%a %d %b"}${font}
|
${color2}${shadecolor a4d7d0}${font sans-serif:size=20}${alignc}${exec date +"%a %d %b"}${font}
|
||||||
|
|
||||||
|
|
||||||
${color1}${shadecolor}${font sans-serif:size=22:style=Bold}${alignc}${execp @bat@ ]] .. bat_args .. [[ }${font}
|
${color1}${shadecolor}${font sans-serif:size=22:style=Bold}${alignc}${execp sane-sysload ]] .. bat_args .. [[ }${font}
|
||||||
${color1}${shadecolor}${font sans-serif:size=20:style=Bold}${alignc}${texeci 600 @weather@ }${font}
|
${color1}${shadecolor}${font sans-serif:size=20:style=Bold}${alignc}${texeci 600 timeout 20 sane-weather }${font}
|
||||||
|
|
||||||
|
|
||||||
${color2}${shadecolor a4d7d0}${font sans-serif:size=16}${alignc}⇅ ${downspeedf wlan0}]] .. vars.kBps .. [[${font}
|
${color2}${shadecolor a4d7d0}${font sans-serif:size=16}${alignc}⇅ ${downspeedf wlan0}]] .. vars.kBps .. [[${font}
|
||||||
|
@@ -16,11 +16,7 @@
|
|||||||
"sane-weather"
|
"sane-weather"
|
||||||
];
|
];
|
||||||
|
|
||||||
fs.".config/conky/conky.conf".symlink.target = pkgs.substituteAll {
|
fs.".config/conky/conky.conf".symlink.target = ./conky.conf;
|
||||||
src = ./conky.conf;
|
|
||||||
bat = "sane-sysload";
|
|
||||||
weather = "timeout 20 sane-weather";
|
|
||||||
};
|
|
||||||
|
|
||||||
services.conky = {
|
services.conky = {
|
||||||
description = "conky dynamic desktop background";
|
description = "conky dynamic desktop background";
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env nix-shell
|
#!/usr/bin/env nix-shell
|
||||||
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ])"
|
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ])"
|
||||||
"""
|
"""
|
||||||
usage: sane-sysload [options...]
|
usage: sane-sysload [options...] formatstr
|
||||||
|
|
||||||
pretty-prints a battery estimate (icon to indicate state, and a duration estimate)
|
pretty-prints a battery estimate (icon to indicate state, and a duration estimate)
|
||||||
|
|
||||||
@@ -11,6 +11,16 @@ options:
|
|||||||
--hour-suffix <string>: use the provided string as an hours suffix
|
--hour-suffix <string>: use the provided string as an hours suffix
|
||||||
--icon-suffix <string>: use the provided string as an icon suffix
|
--icon-suffix <string>: use the provided string as an icon suffix
|
||||||
--percent-suffix <string>: use the provided string when displaying percents
|
--percent-suffix <string>: use the provided string when displaying percents
|
||||||
|
|
||||||
|
formatstr is a Python format string.
|
||||||
|
variables available for formatting:
|
||||||
|
- {bat_icon}
|
||||||
|
- {bat_time}
|
||||||
|
- {mem_icon}
|
||||||
|
- {mem_pct}
|
||||||
|
and some presets, encapsulating the above:
|
||||||
|
- {bat}
|
||||||
|
- {mem}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
@@ -266,6 +276,13 @@ class AllInfo:
|
|||||||
_mem: MemInfo | None
|
_mem: MemInfo | None
|
||||||
_bat: BatteryInfo | None
|
_bat: BatteryInfo | None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bat(self) -> str:
|
||||||
|
return f"{self.bat_icon}{self.bat_time}"
|
||||||
|
@property
|
||||||
|
def mem(self) -> str:
|
||||||
|
return f"{self.mem_icon}{self.mem_pct}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mem_icon(self) -> str:
|
def mem_icon(self) -> str:
|
||||||
if self._mem is None: return ""
|
if self._mem is None: return ""
|
||||||
@@ -307,6 +324,17 @@ class AllInfo:
|
|||||||
else:
|
else:
|
||||||
return self._fmt.render_percent(self._bat.percent_charged)
|
return self._fmt.render_percent(self._bat.percent_charged)
|
||||||
|
|
||||||
|
class LazyFormatter:
|
||||||
|
def __init__(self, obj: object, attr: str):
|
||||||
|
self.obj = obj
|
||||||
|
self.attr = attr
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return repr(getattr(self.obj, self.attr))
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return str(getattr(self.obj, self.attr))
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
@@ -317,8 +345,7 @@ def main() -> None:
|
|||||||
parser.add_argument("--hour-suffix", default=SUFFIX_HR)
|
parser.add_argument("--hour-suffix", default=SUFFIX_HR)
|
||||||
parser.add_argument("--minute-suffix", default=SUFFIX_MIN)
|
parser.add_argument("--minute-suffix", default=SUFFIX_MIN)
|
||||||
parser.add_argument("--percent-suffix", default=SUFFIX_PERCENT)
|
parser.add_argument("--percent-suffix", default=SUFFIX_PERCENT)
|
||||||
parser.add_argument("--template", default="{_.bat_icon}{_.bat_time}")
|
parser.add_argument("formatstr")
|
||||||
# parser.add_argument("--template", default="{_.mem_icon}{_.mem_pct}")
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
@@ -335,7 +362,14 @@ def main() -> None:
|
|||||||
MemInfo(),
|
MemInfo(),
|
||||||
try_all_batteries(),
|
try_all_batteries(),
|
||||||
)
|
)
|
||||||
print(args.template.format(_=info))
|
print(args.formatstr.format(
|
||||||
|
bat=LazyFormatter(info, "bat"),
|
||||||
|
bat_icon=LazyFormatter(info, "bat_icon"),
|
||||||
|
bat_time=LazyFormatter(info, "bat_time"),
|
||||||
|
mem=LazyFormatter(info, "mem"),
|
||||||
|
mem_icon=LazyFormatter(info, "mem_icon"),
|
||||||
|
mem_pct=LazyFormatter(info, "mem_pct"),
|
||||||
|
))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user