...
>
+Optionally the process' uptime may be displayed in the prompt. In order to
+enable this, the "prompt timed" command will enable the prompt and toggle the
+displaying of the time. The uptime is displayed in format "d:hh:mm:ss" where
+"d" is the number of days, and "hh", "mm", "ss" are respectively the number
+of hours, minutes and seconds on two digits each:
+
+ # socat /var/run/haproxy readline
+ prompt timed
+
+ [23:03:34:39]> show version
+ 2.8-dev9-e5e622-18
+
+ [23:03:34:41]> quit
+
Since multiple commands may be issued at once, haproxy uses the empty line as a
delimiter to mark an end of output for each command, and takes care of ensuring
that no command can emit an empty line on output. A script can thus easily
#define APPCTX_CLI_ST1_PROMPT (1 << 0)
#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
#define APPCTX_CLI_ST1_NOLF (1 << 2)
+#define APPCTX_CLI_ST1_TIMED (1 << 3)
#define CLI_PREFIX_KW_NB 5
#define CLI_MAX_MATCHES 5
/* always show the prompt/help/quit commands */
chunk_strcat(tmp,
" help [<command>] : list matching or all commands\n"
- " prompt : toggle interactive mode with prompt\n"
+ " prompt [timed] : toggle interactive mode with prompt\n"
" quit : disconnect\n");
chunk_init(&out, NULL, 0);
/* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
if (appctx->st0 == CLI_ST_PROMPT) {
+ char prompt_buf[20];
const char *prompt = "";
if (appctx->st1 & APPCTX_CLI_ST1_PROMPT) {
*/
if (appctx->chunk->data && appctx->st1 & APPCTX_CLI_ST1_PAYLOAD)
prompt = "+ ";
+ else if (appctx->st1 & APPCTX_CLI_ST1_TIMED) {
+ uint up = ns_to_sec(now_ns - start_time_ns);
+ snprintf(prompt_buf, sizeof(prompt_buf),
+ "\n[%u:%02u:%02u:%02u]> ",
+ (up / 86400), (up / 3600) % 24, (up / 60) % 60, up % 60);
+ prompt = prompt_buf;
+ }
else
prompt = "\n> ";
}
cli_gen_usage_msg(appctx, args);
else if (*args[0] == 'p')
/* prompt */
- appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;
+ if (strcmp(args[1], "timed") == 0) {
+ appctx->st1 |= APPCTX_CLI_ST1_PROMPT;
+ appctx->st1 ^= APPCTX_CLI_ST1_TIMED;
+ }
+ else
+ appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;
else if (*args[0] == 'q') {
/* quit */
se_fl_set(appctx->sedesc, SE_FL_EOI);