mirror of
https://github.com/troglobit/finit.git
synced 2026-11-18 19:30:56 +00:00
initctl: fix remaining lingering artifacts in 'top' output
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
4 files changed
+24
-6
No files matched your search
+17
-2
@@ -728,13 +728,24 @@ int show_cgps(char *arg)
|
|||||||
|
|
||||||
static void cgtop(uev_t *w, void *arg, int events)
|
static void cgtop(uev_t *w, void *arg, int events)
|
||||||
{
|
{
|
||||||
|
static int first = 1;
|
||||||
int lines;
|
int lines;
|
||||||
|
|
||||||
(void)w;
|
(void)w;
|
||||||
(void)events;
|
(void)events;
|
||||||
|
|
||||||
/* Move cursor to home instead of clearing screen to avoid flicker */
|
/* Re-probe screen size in case terminal was resized */
|
||||||
fputs("\e[H", stdout);
|
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;
|
lines = 0;
|
||||||
if (heading) {
|
if (heading) {
|
||||||
print_header(" VmSIZE RSS VmLIB %%MEM %%CPU GROUP");
|
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)
|
static void cleanup(void)
|
||||||
{
|
{
|
||||||
|
fputs("\e[?7h", stdout); /* Re-enable line wrap */
|
||||||
ttcooked();
|
ttcooked();
|
||||||
showcursor();
|
showcursor();
|
||||||
puts("");
|
puts("");
|
||||||
@@ -799,6 +811,9 @@ int show_cgtop(char *arg)
|
|||||||
if (!hcreate(ttrows + 25))
|
if (!hcreate(ttrows + 25))
|
||||||
ERR(70, "failed creating hash table");
|
ERR(70, "failed creating hash table");
|
||||||
|
|
||||||
|
/* Ensure we have correct terminal size before starting */
|
||||||
|
ttinit(1);
|
||||||
|
|
||||||
sysinfo(&si);
|
sysinfo(&si);
|
||||||
total_ram = si.totalram * si.mem_unit;
|
total_ram = si.totalram * si.mem_unit;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1724,7 +1724,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (interactive)
|
if (interactive)
|
||||||
ttinit();
|
ttinit(0);
|
||||||
|
|
||||||
return cmd_parse(argc - optind, &argv[optind], command);
|
return cmd_parse(argc - optind, &argv[optind], command);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -687,7 +687,7 @@ int fistmpfs(char *dir)
|
|||||||
* Called by initctl, and by finit at boot and shutdown, to
|
* Called by initctl, and by finit at boot and shutdown, to
|
||||||
* (re)initialize the screen size for print() et al.
|
* (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 pollfd fd = { STDIN_FILENO, POLLIN, 0 };
|
||||||
struct winsize ws = { 0 };
|
struct winsize ws = { 0 };
|
||||||
@@ -707,6 +707,9 @@ int ttinit(void)
|
|||||||
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
|
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (probe_size)
|
||||||
|
goto fallback;
|
||||||
|
|
||||||
/* 1. Try TIOCWINSZ to query window size from kernel */
|
/* 1. Try TIOCWINSZ to query window size from kernel */
|
||||||
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
if (!ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws)) {
|
||||||
ttrows = ws.ws_row;
|
ttrows = ws.ws_row;
|
||||||
|
|||||||
+2
-2
@@ -95,11 +95,11 @@ int fismnt (char *dir);
|
|||||||
int fistmpfs (char *dir);
|
int fistmpfs (char *dir);
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
int ttinit (void);
|
int ttinit (int probe_size);
|
||||||
int ttraw (void);
|
int ttraw (void);
|
||||||
int ttcooked (void);
|
int ttcooked (void);
|
||||||
#else
|
#else
|
||||||
#define ttinit() ttcols
|
#define ttinit(v) ttcols
|
||||||
#define ttraw() 0
|
#define ttraw() 0
|
||||||
#define ttcooked() 0
|
#define ttcooked() 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in new issue
Block a user