]> Zhao Yanbai Git Server - minix.git/commitdiff
Get rows from termcap it not available from term, or use 24 rows if none known
authorBen Gras <ben@minix3.org>
Wed, 22 Mar 2006 15:32:44 +0000 (15:32 +0000)
committerBen Gras <ben@minix3.org>
Wed, 22 Mar 2006 15:32:44 +0000 (15:32 +0000)
commands/simple/top.c

index 769e36e11982410620ab0fb5f3e1d8500393b299..03174784c85f9fd0f6e24f9b74b8c0a8216b45bc 100644 (file)
@@ -189,7 +189,7 @@ void print_procs(int maxlines,
        }
 }
 
-void showtop(void)
+void showtop(int r)
 {
 #define NLOADS 3
        double loads[NLOADS];
@@ -237,18 +237,22 @@ void showtop(void)
        lines += print_proc_summary(proc);
        lines += print_memory(&pmi);
 
-       print_procs(winsize.ws_row - lines - 2, prev_proc,
+       if(winsize.ws_row > 0) r = winsize.ws_row;
+
+       print_procs(r - lines - 2, prev_proc,
                proc, uptime-prev_uptime, mproc);
 
        memcpy(prev_proc, proc, sizeof(prev_proc));
        prev_uptime = uptime;
 }
 
-void init(void)
+void init(int *rows)
 {
        char  *term;
        static char   buffer[TC_BUFFER], strings[TC_STRINGS];
-       char *s = strings;
+       char *s = strings, *v;
+
+       *rows = 0;
 
        if(!(term = getenv("TERM"))) {
                fprintf(stderr, "No TERM set\n");
@@ -262,14 +266,19 @@ void init(void)
 
        if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )
                Tclr_all = "\f";
+
+       if((v = tgetstr ("li", &s)) != NULL)
+               sscanf(v, "%d", rows);
+       if(*rows < 1) *rows = 24;
 }
 
 int main(int argc, char *argv[])
 {
-       init();
+       int r;
+       init(&r);
 
        while(1) {
-               showtop();
+               showtop(r);
                sleep(5);
        }
 }