From 9f752ce1f6ec7b7544b15a6e48682da5065c297b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 27 Jul 2020 17:04:47 +0200 Subject: [PATCH] top: Don't print more lines than the terminal can fit --- Userland/top.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/top.cpp b/Userland/top.cpp index 56d6db8e15..46c82d0479 100644 --- a/Userland/top.cpp +++ b/Userland/top.cpp @@ -211,6 +211,7 @@ int main(int, char**) return p2->times_scheduled_since_prev < p1->times_scheduled_since_prev; }); + int row = 0; for (auto* thread : threads) { int nprinted = printf("%6d %3d %2u %-9s %-10s %6zu %6zu %2u.%1u ", thread->pid, @@ -226,6 +227,9 @@ int main(int, char**) int remaining = g_window_size.ws_col - nprinted; fwrite(thread->name.characters(), 1, max(0, min(remaining, (int)thread->name.length())), stdout); putchar('\n'); + + if (++row >= (g_window_size.ws_row - 2)) + break; } threads.clear_with_capacity(); prev = move(current);