return 0;
}
-static void set_window_title(PTYForward *f) {
- _cleanup_free_ char *hn = NULL, *dot = NULL;
-
- assert(f);
-
- if (!shall_set_terminal_title())
- return;
-
- (void) gethostname_strict(&hn);
-
- if (emoji_enabled())
- dot = strjoin(glyph(GLYPH_BLUE_CIRCLE), " ");
-
- if (hn)
- (void) pty_forward_set_titlef(f, "%sContainer %s on %s", strempty(dot), arg_machine, hn);
- else
- (void) pty_forward_set_titlef(f, "%sContainer %s", strempty(dot), arg_machine);
-
- if (dot)
- (void) pty_forward_set_title_prefix(f, dot);
-}
-
static int ptyfwd_hotkey(PTYForward *f, char c, void *userdata) {
pid_t pid = PTR_TO_PID(userdata);
const char *word;
} else if (!isempty(arg_background))
(void) pty_forward_set_background_color(forward, arg_background);
- set_window_title(forward);
+ (void) pty_forward_set_window_title(forward, GLYPH_BLUE_CIRCLE, /* hostname = */ NULL,
+ STRV_MAKE("Container", arg_machine));
pty_forward_set_hotkey_handler(forward, ptyfwd_hotkey, PID_TO_PTR(*pid));
break;
#include "format-table.h"
#include "format-util.h"
#include "fs-util.h"
-#include "hostname-setup.h"
#include "log.h"
#include "main-func.h"
#include "osc-context.h"
return r; /* Return true when we get a non-null invocation ID. */
}
-static void set_window_title(PTYForward *f) {
- _cleanup_free_ char *hn = NULL, *cl = NULL, *dot = NULL;
-
- assert(f);
-
- if (!shall_set_terminal_title())
- return;
-
- if (!arg_host)
- (void) gethostname_strict(&hn);
-
- cl = strv_join(arg_cmdline, " ");
- if (!cl)
- return (void) log_oom();
-
- if (emoji_enabled())
- dot = strjoin(glyph(privileged_execution() ? GLYPH_RED_CIRCLE : GLYPH_YELLOW_CIRCLE), " ");
-
- if (arg_host || hn)
- (void) pty_forward_set_titlef(f, "%s%s on %s", strempty(dot), cl, arg_host ?: hn);
- else
- (void) pty_forward_set_titlef(f, "%s%s", strempty(dot), cl);
-
- (void) pty_forward_set_title_prefix(f, dot);
-}
-
static int fchown_to_capsule(int fd, const char *capsule) {
_cleanup_free_ char *p = NULL;
int r;
if (!isempty(arg_background))
(void) pty_forward_set_background_color(c->forward, arg_background);
- set_window_title(c->forward);
+ (void) pty_forward_set_window_title(c->forward,
+ privileged_execution() ? GLYPH_RED_CIRCLE : GLYPH_YELLOW_CIRCLE,
+ arg_host, arg_cmdline);
return 0;
}
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
+#include "glyph-util.h"
+#include "hostname-setup.h"
#include "io-util.h"
#include "log.h"
#include "ptyfwd.h"
return free_and_strdup(&f->title_prefix, title_prefix);
}
+
+int pty_forward_set_window_title(
+ PTYForward *f,
+ Glyph circle, /* e.g. GLYPH_GREEN_CIRCLE */
+ const char *hostname, /* Can be NULL, and obtained by gethostname_strict() in that case. */
+ char * const *msg) {
+
+ _cleanup_free_ char *hn = NULL, *dot = NULL, *joined = NULL;
+ int r;
+
+ assert(f);
+
+ if (!shall_set_terminal_title())
+ return 0;
+
+ if (!hostname) {
+ (void) gethostname_strict(&hn);
+ hostname = hn;
+ }
+
+ if (circle >= 0 && emoji_enabled()) {
+ dot = strjoin(glyph(circle), " ");
+ if (!dot)
+ return -ENOMEM;
+ }
+
+ joined = strv_join(msg, " ");
+ if (!joined)
+ return -ENOMEM;
+
+ r = pty_forward_set_titlef(f, "%s%s%s%s", strempty(dot), joined, hn ? " on " : "", strempty(hn));
+ if (r < 0)
+ return r;
+
+ if (dot) {
+ r = pty_forward_set_title_prefix(f, dot);
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
+}
bool shall_set_terminal_title(void);
+int pty_forward_set_window_title(
+ PTYForward *f,
+ Glyph circle, /* e.g. GLYPH_GREEN_CIRCLE */
+ const char *hostname, /* Can be NULL, and obtained by gethostname_strict() in that case. */
+ char * const *msg);
+
DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);
return 0;
}
-static void set_window_title(PTYForward *f) {
- _cleanup_free_ char *hn = NULL, *dot = NULL;
-
- assert(f);
-
- if (!shall_set_terminal_title())
- return;
-
- (void) gethostname_strict(&hn);
-
- if (emoji_enabled())
- dot = strjoin(glyph(GLYPH_GREEN_CIRCLE), " ");
-
- if (hn)
- (void) pty_forward_set_titlef(f, "%sVirtual Machine %s on %s", strempty(dot), arg_machine, hn);
- else
- (void) pty_forward_set_titlef(f, "%sVirtual Machine %s", strempty(dot), arg_machine);
-
- if (dot)
- (void) pty_forward_set_title_prefix(f, dot);
-}
-
static int generate_ssh_keypair(const char *key_path, const char *key_type) {
_cleanup_free_ char *ssh_keygen = NULL;
_cleanup_strv_free_ char **cmdline = NULL;
} else if (!isempty(arg_background))
(void) pty_forward_set_background_color(forward, arg_background);
- set_window_title(forward);
+ (void) pty_forward_set_window_title(forward, GLYPH_GREEN_CIRCLE, /* hostname = */ NULL,
+ STRV_MAKE("Virtual Machine", arg_machine));
}
r = sd_event_loop(event);