Module: check_mk
Branch: master
Commit: 63b24937b1f248301895fa489fe2abd7e8ebd9a1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=63b24937b1f248…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 23 21:07:55 2011 +0100
gb: honor terminal width when listing
---
gb | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/gb b/gb
index 021dced..fa90c9d 100755
--- a/gb
+++ b/gb
@@ -40,6 +40,18 @@ else:
def tty_colors(c):
return ""
+def get_tty_size():
+ import termios,struct,fcntl
+ try:
+ ws = struct.pack("HHHH", 0, 0, 0, 0)
+ ws = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, ws)
+ lines, columns, x, y = struct.unpack("HHHH", ws)
+ if lines > 0 and columns > 0:
+ return lines, columns
+ except:
+ pass
+ return (24, 99999)
+
grep_colors = [
tty_bold + tty_magenta,
tty_bold + tty_cyan,
@@ -196,11 +208,13 @@ def list_bug(bug):
bold = tty_bold + tty_cyan + "(*) "
else:
bold = ""
- sys.stdout.write("#%04d %-8s %-9s %-10s %s%-6s%s %s%-60s%s\n" %
+ lines, cols = get_tty_size()
+ title = bug["title"][:cols - 45]
+ sys.stdout.write("#%04d %-8s %-9s %-10s %s%-8s%s %s%s%s\n" %
(int(bug["id"]),
bug_state(bug),
bug["class"], bug["component"], tty_bold,
- bug["targetversion"], tty_normal, bold, bug["title"],
tty_normal))
+ bug["targetversion"], tty_normal, bold, title, tty_normal))
def show_bug(bug):
list_bug(bug)