Python ntpq
Achim Gratz
Stromeko at nexgo.de
Sun Nov 27 14:02:56 UTC 2016
Achim Gratz writes:
> Although I still think the limiting should be done in ntpq (or any other
> program using utils) rather than there so that one can override the
> termwidth from the top-level caller without second-guessing by util.
The more general way to do that would be to have util.termsize take
optional arguments that specify the maximum termsize to return.
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -61,7 +61,7 @@ def canonicalize_dns(hostname, family=socket.AF_UNSPEC):
return canonicalized.lower() + portsuffix
return name[0].lower() + portsuffix
-def termsize():
+def termsize(maxrows=0, maxcols=0):
"Return the current terminal size."
# Should work under Linux and Solaris at least.
# Alternatives at http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
@@ -72,8 +72,10 @@ def termsize():
return (24, 80)
for pattern in ('rows\D+(\d+); columns\D+(\d+);', '\s+(\d+)\D+rows;\s+(\d+)\D+columns;'):
m = re.search(pattern, output)
+ rows = int(m.group(1))
+ cols = int(m.group(2))
if m:
- return int(m.group(1)), int(m.group(2))
+ return ((min(rows,maxrows) or rows), (min(cols,maxcols) or cols))
return (24, 80)
Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+
Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds
More information about the devel
mailing list