watch: Add hostname to the header
watch has the hostname added to the header so you know what device if you have many it is running on. Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
parent
96da4bad5e
commit
80594403cc
1
NEWS
1
NEWS
@ -6,6 +6,7 @@ procps-ng-NEXT
|
|||||||
* tests: Conditionally add prctl Debian #816237
|
* tests: Conditionally add prctl Debian #816237
|
||||||
* pidof: check cmd if space in argv0. GitLab #4
|
* pidof: check cmd if space in argv0. GitLab #4
|
||||||
* kill: report error if cannot kill process #733172
|
* kill: report error if cannot kill process #733172
|
||||||
|
* watch: Add hostname to header
|
||||||
|
|
||||||
procps-ng-3.3.11
|
procps-ng-3.3.11
|
||||||
----------------
|
----------------
|
||||||
|
44
watch.c
44
watch.c
@ -371,40 +371,45 @@ static void output_header(char *restrict command, double interval)
|
|||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
char *ts = ctime(&t);
|
char *ts = ctime(&t);
|
||||||
int tsl = strlen(ts);
|
|
||||||
char *header;
|
char *header;
|
||||||
|
char *right_header;
|
||||||
|
char hostname[HOST_NAME_MAX + 1];
|
||||||
|
|
||||||
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* left justify interval and command, right justify time,
|
* left justify interval and command, right justify hostname and time,
|
||||||
* clipping all to fit window width
|
* clipping all to fit window width
|
||||||
*/
|
*/
|
||||||
int hlen = asprintf(&header, _("Every %.1fs: "), interval);
|
int hlen = asprintf(&header, _("Every %.1fs: "), interval);
|
||||||
|
int rhlen = asprintf(&right_header, _("%s: %s"), hostname, ts);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the rules:
|
* the rules:
|
||||||
* width < tsl : print nothing
|
* width < rhlen : print nothing
|
||||||
* width < tsl + hlen + 1: print ts
|
* width < rhlen + hlen + 1: print hostname, ts
|
||||||
* width = tsl + hlen + 1: print header, ts
|
* width = rhlen + hlen + 1: print header, hostname, ts
|
||||||
* width < tsl + hlen + 4: print header, ..., ts
|
* width < rhlen + hlen + 4: print header, ..., hostname, ts
|
||||||
* width < tsl + hlen + wcommand_columns: print header,
|
* width < rhlen + hlen + wcommand_columns: print header,
|
||||||
* truncated wcommand, ..., ts
|
* truncated wcommand, ..., hostname, ts
|
||||||
* width > "": print header, wcomand, ts
|
* width > "": print header, wcomand, hostname, ts
|
||||||
* this is slightly different from how it used to be
|
* this is slightly different from how it used to be
|
||||||
*/
|
*/
|
||||||
if (width < tsl) {
|
if (width < rhlen) {
|
||||||
free(header);
|
free(header);
|
||||||
|
free(right_header);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tsl + hlen + 1 <= width) {
|
if (rhlen + hlen + 1 <= width) {
|
||||||
mvaddstr(0, 0, header);
|
mvaddstr(0, 0, header);
|
||||||
if (tsl + hlen + 2 <= width) {
|
if (rhlen + hlen + 2 <= width) {
|
||||||
if (width < tsl + hlen + 4) {
|
if (width < rhlen + hlen + 4) {
|
||||||
mvaddstr(0, width - tsl - 4, "... ");
|
mvaddstr(0, width - rhlen - 4, "... ");
|
||||||
} else {
|
} else {
|
||||||
#ifdef WITH_WATCH8BIT
|
#ifdef WITH_WATCH8BIT
|
||||||
if (width < tsl + hlen + wcommand_columns) {
|
if (width < rhlen + hlen + wcommand_columns) {
|
||||||
/* print truncated */
|
/* print truncated */
|
||||||
int available = width - tsl - hlen;
|
int available = width - rhlen - hlen;
|
||||||
int in_use = wcommand_columns;
|
int in_use = wcommand_columns;
|
||||||
int wcomm_len = wcommand_characters;
|
int wcomm_len = wcommand_characters;
|
||||||
while (available - 4 < in_use) {
|
while (available - 4 < in_use) {
|
||||||
@ -412,18 +417,19 @@ static void output_header(char *restrict command, double interval)
|
|||||||
in_use = wcswidth(wcommand, wcomm_len);
|
in_use = wcswidth(wcommand, wcomm_len);
|
||||||
}
|
}
|
||||||
mvaddnwstr(0, hlen, wcommand, wcomm_len);
|
mvaddnwstr(0, hlen, wcommand, wcomm_len);
|
||||||
mvaddstr(0, width - tsl - 4, "... ");
|
mvaddstr(0, width - rhlen - 4, "... ");
|
||||||
} else {
|
} else {
|
||||||
mvaddwstr(0, hlen, wcommand);
|
mvaddwstr(0, hlen, wcommand);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
mvaddnstr(0, hlen, command, width - tsl - hlen);
|
mvaddnstr(0, hlen, command, width - rhlen - hlen);
|
||||||
#endif /* WITH_WATCH8BIT */
|
#endif /* WITH_WATCH8BIT */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mvaddstr(0, width - tsl + 1, ts);
|
mvaddstr(0, width - rhlen + 1, right_header);
|
||||||
free(header);
|
free(header);
|
||||||
|
free(right_header);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user