initctl: fix remaining lingering artifacts in 'top' output

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2025-12-17 08:19:38 +01:00
1 parent 390a0f48c1
commit a3d9b6e9b1
4 files changed
+24 -6

No files matched your search

+17 -2
View File
@@ -728,13 +728,24 @@ int show_cgps(char *arg)
static void cgtop(uev_t *w, void *arg, int events)
{
static int first = 1;
int lines;
(void)w;
(void)events;
/* Move cursor to home instead of clearing screen to avoid flicker */
fputs("\e[H", stdout);
/* Re-probe screen size in case terminal was resized */
ttinit(1);
/* Clear screen on first run to remove any artifacts */
if (first) {
fputs("\e[?7l\e[2J\e[H", stdout); /* Disable line wrap, clear, home */
first = 0;
} else {
/* Move cursor to home instead of clearing screen to avoid flicker */
fputs("\e[H", stdout);
}
lines = 0;
if (heading) {
print_header(" VmSIZE RSS VmLIB %%MEM %%CPU GROUP");
@@ -749,6 +760,7 @@ static void cgtop(uev_t *w, void *arg, int events)
static void cleanup(void)
{
fputs("\e[?7h", stdout); /* Re-enable line wrap */
ttcooked();
showcursor();
puts("");
@@ -799,6 +811,9 @@ int show_cgtop(char *arg)
if (!hcreate(ttrows + 25))
ERR(70, "failed creating hash table");
/* Ensure we have correct terminal size before starting */
ttinit(1);
sysinfo(&si);
total_ram = si.totalram * si.mem_unit;
+1 -1
View File
@@ -1724,7 +1724,7 @@ int main(int argc, char *argv[])
}
if (interactive)
ttinit();
ttinit(0);
return cmd_parse(argc - optind, &argv[optind], command);
}
+4 -1
View File
@@ -687,7 +687,7 @@ int fistmpfs(char *dir)
* Called by initctl, and by finit at boot and shutdown, to
* (re)initialize the screen size for print() et al.
*/
int ttinit(void)
int ttinit(int probe_size)
{
struct pollfd fd = { STDIN_FILENO, POLLIN, 0 };
struct winsize ws = { 0 };
@@ -707,6 +707,9 @@ int ttinit(void)
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
}
if (probe_size)
goto fallback;
/* 1. Try TIOCWINSZ to query window size from kernel */
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
ttrows = ws.ws_row;
+2 -2
View File
@@ -95,11 +95,11 @@ int fismnt (char *dir);
int fistmpfs (char *dir);
#ifdef HAVE_TERMIOS_H
int ttinit (void);
int ttinit (int probe_size);
int ttraw (void);
int ttcooked (void);
#else
#define ttinit() ttcols
#define ttinit(v) ttcols
#define ttraw() 0
#define ttcooked() 0
#endif