diff options
author | Giorgos Keramidas <keramida@FreeBSD.org> | 2005-05-18 13:48:33 +0000 |
---|---|---|
committer | Giorgos Keramidas <keramida@FreeBSD.org> | 2005-05-18 13:48:33 +0000 |
commit | cd660671cea3aebb46b9cf4b88a975279e1e92ee (patch) | |
tree | b37c0e552600f59b50506cb200587658607c35d4 /contrib/top | |
parent | 58ea49c98eb6d433dedc0bcead38f5358e092c0b (diff) | |
download | src-cd660671cea3aebb46b9cf4b88a975279e1e92ee.tar.gz src-cd660671cea3aebb46b9cf4b88a975279e1e92ee.zip |
Properly trim the header line too, to fix wrap-around problems that
have been noticed by running top(1) in terminals that are too narrow
(or on systems with usernames that were too long, pushing everything
too far to the right).
Note that this does *not* solve the wrap-around problem of the system
statistics, which is an entirely different matter :-/
Tested on: i386, sparc64 (panther), amd64 (sledge)
Approved by: davidxu (in principle)
Notes
Notes:
svn path=/head/; revision=146344
Diffstat (limited to 'contrib/top')
-rw-r--r-- | contrib/top/display.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/contrib/top/display.c b/contrib/top/display.c index b1b643577ff8..08814b3f5723 100644 --- a/contrib/top/display.c +++ b/contrib/top/display.c @@ -626,6 +626,33 @@ u_message() static int header_length; /* + * Trim a header string to the current display width and return a newly + * allocated area with the trimmed header. + */ + +char * +trim_header(text) + +char *text; + +{ + char *s; + int width; + + s = NULL; + width = display_width; + header_length = strlen(text); + if (header_length >= width) { + s = malloc((width + 1) * sizeof(char)); + if (s == NULL) + return (NULL); + strncpy(s, text, width); + s[width] = '\0'; + } + return (s); +} + +/* * *_header(text) - print the header for the process area * * Assumptions: cursor is on the previous line and lastline is consistent @@ -636,7 +663,12 @@ i_header(text) char *text; { - header_length = strlen(text); + char *s; + + s = trim_header(text); + if (s != NULL) + text = s; + if (header_status == ON) { putchar('\n'); @@ -647,6 +679,7 @@ char *text; { header_status = OFF; } + free(s); } /*ARGSUSED*/ @@ -655,6 +688,12 @@ u_header(text) char *text; /* ignored */ { + char *s; + + s = trim_header(text); + if (s != NULL) + text = s; + if (header_status == ERASE) { putchar('\n'); @@ -662,6 +701,7 @@ char *text; /* ignored */ clear_eol(header_length); header_status = OFF; } + free(s); } /* |