summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:43 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 12:38:43 +0300
commitcaf7d446446a0af0b30886a6c4ee5851aab553e2 (patch)
tree28cb796f01711d8484bc6cb3daa8e551db18fe68 /src
parent6cd9ab6f73994b68e8453c92a014d1a372af2a24 (diff)
parent7ed78a31debb0250bae16d8b4098a4689f29bb60 (diff)
Merge branch 'wt/host-name' into api-hardening
# Conflicts: # src/screen.c
Diffstat (limited to 'src')
-rw-r--r--src/escape.c4
-rw-r--r--src/internal.h2
-rw-r--r--src/osc/misc.c2
-rw-r--r--src/screen.c17
4 files changed, 22 insertions, 3 deletions
diff --git a/src/escape.c b/src/escape.c
index da0449a..dceb7a6 100644
--- a/src/escape.c
+++ b/src/escape.c
@@ -834,7 +834,9 @@ static inline TERM_ALWAYS_INLINE void dispatch_csi(struct term *t, const struct
case 'q': {
if (csi->prefix == '>' && !csi->intermediate &&
(!csi->nparams || !csi->params[0])) {
- send_response(t, "\033P>|wsap_term\033\\");
+ char resp[96];
+ snprintf(resp, sizeof(resp), "\033P>|%s\033\\", t->name);
+ send_response(t, resp);
} else if (!csi->prefix && csi->intermediate == ' ') {
term_sc_set_cursor_style(t, csi->nparams > 0 ? csi->params[0] : 0);
}
diff --git a/src/internal.h b/src/internal.h
index 8c02c91..5da114d 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -208,6 +208,8 @@ struct term {
bool custom_tabs;
char osc_buf[256];
+ /* The host's name. A DCS sequence can change tcap_name, not this. */
+ char name[64];
char tcap_name[64];
char *osc_heap;
diff --git a/src/osc/misc.c b/src/osc/misc.c
index 5d6b506..74b35cf 100644
--- a/src/osc/misc.c
+++ b/src/osc/misc.c
@@ -53,7 +53,7 @@ void term_osc_misc_dispatch(struct term *t, long code, const char *params)
break;
case 9:
if (t->cb.notify && strncmp(params, "4;", 2))
- t->cb.notify(t->cb.ud, "wsap_term", params);
+ t->cb.notify(t->cb.ud, t->name, params);
break;
case 22:
free(t->pointer_shape);
diff --git a/src/screen.c b/src/screen.c
index ab912a1..0857f17 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -840,6 +840,17 @@ bool term_tables_ready(void)
return atomic_load_explicit(&tables_state, memory_order_relaxed) == 2;
}
+/* A name is 1 to 63 printable ASCII bytes. DCS replies echo it. */
+static bool name_valid(const char *s)
+{
+ for (size_t i = 0; s[i]; i++) {
+ unsigned char c = (unsigned char)s[i];
+ if (i >= 63 || c < 0x20 || c > 0x7e)
+ return false;
+ }
+ return true;
+}
+
struct term *term_new(const struct term_options *opt)
{
tables_init();
@@ -853,6 +864,9 @@ struct term *term_new(const struct term_options *opt)
return NULL;
if (opt->scrollback < 0 || (unsigned)opt->cursor_style > TERM_CURSOR_BAR)
return NULL;
+ const char *name = opt->name && *opt->name ? opt->name : "term";
+ if (!name_valid(name))
+ return NULL;
int cols = opt->size.x == 0 ? 80 : opt->size.x;
int rows = opt->size.y == 0 ? 24 : opt->size.y;
@@ -860,6 +874,7 @@ struct term *term_new(const struct term_options *opt)
struct term *t = calloc(1, sizeof(*t));
if (!t)
return NULL;
+ memcpy(t->name, name, strlen(name) + 1);
atomic_init(&t->seq, 0);
atomic_init(&t->writer_tid, 0);
t->write_depth = 0;
@@ -906,7 +921,7 @@ struct term *term_new(const struct term_options *opt)
t->autowrap = true;
t->charsets[0] = t->charsets[1] = 'B';
t->saved = term_saved_cursor_initial();
- memcpy(t->tcap_name, "wsap_term", sizeof("wsap_term"));
+ memcpy(t->tcap_name, t->name, sizeof(t->name));
term_tabs_default(t);
t->full_gen = 1;
memset(t->text_width.lo, 0xFF, sizeof(t->text_width.lo));