[PATCH] top(1) inverse display of table header

Xin LI delphij at delphij.net
Tue Oct 26 00:43:15 UTC 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Here is a patch that makes top(1) to inverse its table header (PID
USERNAME THR, etc).

Cheers,
- -- 
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!	       Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (FreeBSD)

iQEcBAEBCAAGBQJMxiQSAAoJEATO+BI/yjfBbcgH/iy/y0MBHY++srGtZc5BqyWm
Kh0jpRKdE1f7G708Zok501b3rbVqeXTqAHcBU/xA0JNRruTYn7ByU2kijsuMBeQC
eB6LK8wurtLHu+kqBzbbgmyeUIonWht25RWrqXH1Hr1zSoTmpAOdQKz0RCoQu2W5
yeJyS9geQoZXaTTbxHrCpYbUjQ2vp6+gvBVhi5n7c4lT0wBZJ/7p1LJOu2DiGHVO
TWlBh+SjKoZWrLt7LqxU/dyJ6kxpl3RVNBlRlIvL/jn/ICBBhgSfldzpckAQJ/Bt
IgPTfiKjax+38RH3L62ob9B99nPF5V7Jc3JKTWdDCuJren8MH0zdtC1zM4KG8NA=
=6RQi
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: contrib/top/display.c
===================================================================
--- contrib/top/display.c	(revision 214355)
+++ contrib/top/display.c	(working copy)
@@ -694,7 +694,7 @@
 	int width;
 
 	s = NULL;
-	width = display_width;
+	width = screen_width;
 	header_length = strlen(text);
 	if (header_length >= width) {
 		s = malloc((width + 1) * sizeof(char));
@@ -702,6 +702,14 @@
 			return (NULL);
 		strncpy(s, text, width);
 		s[width] = '\0';
+	} else {
+		s = malloc((width + 1) * sizeof(char));
+		if (s == NULL)
+			return (NULL);
+		strncpy(s, text, width);
+		while (screen_width > header_length)
+			s[header_length++] = ' ';
+		s[width] = '\0';
 	}
 	return (s);
 }
@@ -726,7 +734,7 @@
     if (header_status == ON)
     {
 	putchar('\n');
-	fputs(text, stdout);
+	standout(text, stdout);
 	lastline++;
     }
     else if (header_status == ERASE)
Index: contrib/top/top.h
===================================================================
--- contrib/top/top.h	(revision 214355)
+++ contrib/top/top.h	(working copy)
@@ -14,7 +14,7 @@
 extern int Header_lines;	/* 7 */
 
 /* Maximum number of columns allowed for display */
-#define MAX_COLS	128
+#define MAX_COLS	512
 
 /* Log base 2 of 1024 is 10 (2^10 == 1024) */
 #define LOG1024		10


More information about the freebsd-current mailing list