chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

commit 1efb49035ee7a17c6d9784b79d80d7be89eaed38
parent e891ed3c40c15f59fc1647195933a0cbbe5237b9
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sun,  8 Nov 2026 13:44:46 +0000

tyrmel, launchel and interber 0.1.1: fixes

tyrmel: changing scrollback in the config takes effect without a restart, strikethrough
survives scrolling back, pictures over 4096 pixels get scaled down instead of eating memory,
paste drops control characters (except tab and enter) so a pasted escape can't run things,
and it only deletes the temp files it made, in temp folders.
launchel: a broken history line can't crash it on start.
interber: interber:search only works from interber pages, downloads can't be named
../something, ctrl+q saves your tabs first, and a bad certificate shows a warning page
instead of a blank one.

Diffstat:
Mtools/pkg/interber/files/Makefile | 2+-
Mtools/pkg/interber/files/interber.c | 40++++++++++++++++++++++++++++++++++++----
Mtools/pkg/interber/recipe | 2+-
Mtools/pkg/launchel/files/Makefile | 2+-
Mtools/pkg/launchel/files/launchel.c | 8++++++--
Mtools/pkg/launchel/recipe | 2+-
Mtools/pkg/tyrmel/files/Makefile | 2+-
Mtools/pkg/tyrmel/files/tyrmel.c | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mtools/pkg/tyrmel/recipe | 4++--
9 files changed, 130 insertions(+), 19 deletions(-)

diff --git a/tools/pkg/interber/files/Makefile b/tools/pkg/interber/files/Makefile @@ -1,5 +1,5 @@ # interber -VERSION = 0.1 +VERSION = 0.1.1 PREFIX = /usr/local PKGS = gtk+-3.0 webkit2gtk-4.1 diff --git a/tools/pkg/interber/files/interber.c b/tools/pkg/interber/files/interber.c @@ -525,6 +525,30 @@ onhover(WebKitWebView *v, WebKitHitTestResult *h, guint mods, gpointer data) updatestatus(); } +/* a site whose certificate doesn't check out isn't loaded. say why instead of showing nothing */ +static gboolean +ontls(WebKitWebView *v, char *uri, GTlsCertificate *cert, GTlsCertificateFlags errors, gpointer data) +{ + GUri *gu = g_uri_parse(uri, G_URI_FLAGS_NONE, NULL); + char *e, *html; + + e = g_markup_escape_text(gu && g_uri_get_host(gu) ? g_uri_get_host(gu) : uri, -1); + html = g_strdup_printf("<!doctype html><meta charset=utf-8><style>body{background:%s;color:%s;" + "font:16px VGA,monospace;margin:16px}</style><pre>%s isn't safe to open.\n\n" + "Its certificate doesn't check out%s, so someone could be in the middle\n" + "reading or changing what you send. interber didn't load it.</pre>", + colourhex(bg), colourhex(fg), e, + errors & G_TLS_CERTIFICATE_EXPIRED ? " (it's expired)" : + errors & G_TLS_CERTIFICATE_BAD_IDENTITY ? " (it's for a different site)" : + errors & G_TLS_CERTIFICATE_UNKNOWN_CA ? " (nobody we trust vouches for it)" : ""); + webkit_web_view_load_alternate_html(v, html, uri, NULL); + g_free(html); + g_free(e); + if (gu) + g_uri_unref(gu); + return TRUE; +} + /* target=_blank and window.open: a new tab */ static GtkWidget * oncreate(WebKitWebView *v, WebKitNavigationAction *a, gpointer data) @@ -543,10 +567,13 @@ onpolicy(WebKitWebView *v, WebKitPolicyDecision *d, WebKitPolicyDecisionType typ if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) { a = webkit_navigation_policy_decision_get_navigation_action(WEBKIT_NAVIGATION_POLICY_DECISION(d)); u = webkit_uri_request_get_uri(webkit_navigation_action_get_request(a)); - /* the home page's search box */ + /* the home page's search box. only from our own pages: a website sending you to + interber:search?q=file:///... would get us to open your files for it */ if (u && !strncmp(u, "interber:search", 15)) { + const char *from = webkit_web_view_get_uri(v); + webkit_policy_decision_ignore(d); - if ((q = strstr(u, "q="))) { + if (from && !strncmp(from, "interber:", 9) && (q = strstr(u, "q="))) { t = g_strdup(q + 2); for (p = t; *p; p++) if (*p == '+') @@ -648,6 +675,7 @@ newtab(const char *uri, WebKitWebView *related, int show) g_signal_connect(t->view, "enter-fullscreen", G_CALLBACK(onfull), GINT_TO_POINTER(1)); g_signal_connect(t->view, "leave-fullscreen", G_CALLBACK(onfull), GINT_TO_POINTER(0)); g_signal_connect(t->view, "button-press-event", G_CALLBACK(onbutton), NULL); + g_signal_connect(t->view, "load-failed-with-tls-errors", G_CALLBACK(ontls), NULL); t->label = gtk_button_new_with_label("[ new tab ]"); gtk_button_set_relief(GTK_BUTTON(t->label), GTK_RELIEF_NONE); @@ -733,8 +761,12 @@ ondest(WebKitDownload *d, char *name, gpointer data) char path[2048], base[1024], *dot, *uri; int i; + char *b = name && *name ? g_path_get_basename(name) : NULL; + g_mkdir_with_parents(downloads, 0755); - snprintf(base, sizeof base, "%s", name && *name ? name : "download"); + /* the website picks the name: only the last part of it, so it can't climb out of Downloads */ + snprintf(base, sizeof base, "%s", b && strcmp(b, ".") && strcmp(b, "..") && strcmp(b, "/") ? b : "download"); + g_free(b); snprintf(path, sizeof path, "%s/%s", downloads, base); /* never over something that's there: name (1).ext */ for (i = 1; access(path, F_OK) == 0 && i < 1000; i++) { @@ -838,7 +870,7 @@ onkey(GtkWidget *w, GdkEventKey *e, gpointer data) switch (k) { case GDK_KEY_t: newtab(home, NULL, 1); gtk_widget_grab_focus(entry); return TRUE; case GDK_KEY_w: closetab(t); return TRUE; - case GDK_KEY_q: gtk_main_quit(); return TRUE; + case GDK_KEY_q: savetabs(); gtk_main_quit(); return TRUE; case GDK_KEY_l: gtk_widget_grab_focus(entry); return TRUE; case GDK_KEY_r: webkit_web_view_reload(t->view); return TRUE; case GDK_KEY_h: go(t, home); return TRUE; diff --git a/tools/pkg/interber/recipe b/tools/pkg/interber/recipe @@ -1,5 +1,5 @@ name=interber -version=0.1 +version=0.1.1 rel=0 desc="Web browser that looks like a tty" url=https://chamesle.org diff --git a/tools/pkg/launchel/files/Makefile b/tools/pkg/launchel/files/Makefile @@ -1,5 +1,5 @@ # launchel -VERSION = 0.1 +VERSION = 0.1.1 PREFIX = /usr/local PKGS = x11 xft fontconfig diff --git a/tools/pkg/launchel/files/launchel.c b/tools/pkg/launchel/files/launchel.c @@ -333,8 +333,12 @@ readhistory(void) trim(line); if ((it = find(line))) it->used++; - else if (*line) - add(line, line, 0), find(line)->used = 1; + else if (*line) { + /* the list can be full, then it isn't added */ + add(line, line, 0); + if ((it = find(line))) + it->used = 1; + } } fclose(f); } diff --git a/tools/pkg/launchel/recipe b/tools/pkg/launchel/recipe @@ -1,5 +1,5 @@ name=launchel -version=0.1 +version=0.1.1 rel=0 desc="One line to type what you want to run" url=https://chamesle.org diff --git a/tools/pkg/tyrmel/files/Makefile b/tools/pkg/tyrmel/files/Makefile @@ -1,5 +1,5 @@ # tyrmel -VERSION = 0.1 +VERSION = 0.1.1 PREFIX = /usr/local PKGS = x11 xft xrender fontconfig vterm libpng zlib diff --git a/tools/pkg/tyrmel/files/tyrmel.c b/tools/pkg/tyrmel/files/tyrmel.c @@ -537,6 +537,7 @@ sbpop(int n, VTermScreenCell *cells, void *user) cells[i].attrs.bold = !!(l->cells[i].flags & FBold); cells[i].attrs.underline = !!(l->cells[i].flags & FUnder); cells[i].attrs.reverse = !!(l->cells[i].flags & FReverse); + cells[i].attrs.strike = !!(l->cells[i].flags & FStrike); if (!(l->cells[i].flags & FDefFg)) vterm_color_rgb(&cells[i].fg, l->cells[i].fg[0], l->cells[i].fg[1], l->cells[i].fg[2]); if (!(l->cells[i].flags & FDefBg)) @@ -549,6 +550,32 @@ sbpop(int n, VTermScreenCell *cells, void *user) return 1; } +/* the scrollback setting changed while running: the lines that fit go into a ring of the new size */ +static void +setscrollback(int n) +{ + Line *nsb = n ? calloc(n, sizeof *nsb) : NULL; + int keep = MIN(sbn, n), i; + + if (n && !nsb) + return; + for (i = 0; i < sbn; i++) { + if (i < sbn - keep) + free(sbline(i)->cells); + else + nsb[i - (sbn - keep)] = *sbline(i); + } + free(sb); + sb = nsb; + sbhead = 0; + sbn = keep; + scrollmax = n; + view = MIN(view, sbn); + sel.on = 0; + dropplaces(); + dirty = 1; +} + static int sbclear(void *user) { @@ -739,6 +766,13 @@ makepic(Place *p) h = MAX(1, (long)p->sh * w / p->sw); else w = MAX(1, (long)p->sw * h / p->sh); + /* a program asking for a picture a million cells wide gets one X can actually make */ + if (w > 4096 || h > 4096) { + if (w >= h) + h = MAX(1, (long)h * 4096 / w), w = 4096; + else + w = MAX(1, (long)w * 4096 / h), h = 4096; + } if (!(px = malloc((size_t)w * h * 4))) return; for (y = 0; y < h; y++) { @@ -854,6 +888,28 @@ delete(int what, unsigned int id, int x, int y) dirty = 1; } +static int +intemp(const char *path) +{ + const char *dirs[] = { "/tmp/", "/dev/shm/", "/var/tmp/", getenv("TMPDIR") }; + struct stat st; + char real[PATH_MAX], dir[PATH_MAX]; + unsigned int i; + size_t n; + + if (lstat(path, &st) < 0 || !S_ISREG(st.st_mode) || !realpath(path, real) || strstr(real, "/../")) + return 0; + for (i = 0; i < LENGTH(dirs); i++) { + if (!dirs[i] || !*dirs[i]) + continue; + snprintf(dir, sizeof dir, "%s%s", dirs[i], dirs[i][strlen(dirs[i]) - 1] == '/' ? "" : "/"); + n = strlen(dir); + if (!strncmp(real, dir, n) && !strchr(real + n, '/')) + return 1; + } + return 0; +} + /* ESC _ G key=value,... ; base64 ESC \ */ static void graphics(char *s, size_t n) @@ -952,7 +1008,9 @@ graphics(char *s, size_t n) rawlen = raw ? fread(raw, 1, st.st_size, f) : 0; fclose(f); } - if (k.medium == 't' && strstr(path, "tty-graphics-protocol")) + /* t means "delete it after": only ever in a temporary folder, or anything a program prints + could delete your files */ + if (k.medium == 't' && strstr(path, "tty-graphics-protocol") && intemp(path)) unlink(path); } else if (k.medium != 'd') { free(raw); @@ -1491,10 +1549,22 @@ selectionnotify(XSelectionEvent *e) if (XGetWindowProperty(dpy, win, e->property, 0, 1 << 20, True, AnyPropertyType, &type, &fmt, &n, &after, &data) != Success) return; - /* new lines are enter keys */ - for (i = 0; i < n; i++) - if (data[i] == '\n') - data[i] = '\r'; + /* new lines are enter keys. other control characters go, like xterm does it: otherwise pasted + text could end the paste early and the rest would run as if you'd typed it */ + { + unsigned long j = 0; + + for (i = 0; i < n; i++) { + if (data[i] == '\n') + data[i] = '\r'; + if (data[i] < 0x20 && data[i] != '\r' && data[i] != '\t') + continue; + if (data[i] == 0x7f) + continue; + data[j++] = data[i]; + } + n = j; + } vterm_keyboard_start_paste(vt); writepty((char *)data, n); vterm_keyboard_end_paste(vt); @@ -1856,13 +1926,18 @@ static void checkconfig(void) { struct stat st; - int oldsize = fontsize; + int oldsize = fontsize, oldscroll = scrollmax, newscroll; char oldfont[256]; if (stat(cfgpath, &st) < 0 || st.st_mtime == cfgmtime) return; snprintf(oldfont, sizeof oldfont, "%s", fontname); loadconfig(); + /* the ring is still the old size until it's moved */ + newscroll = scrollmax; + scrollmax = oldscroll; + if (newscroll != oldscroll) + setscrollback(newscroll); if (forcesize > 3) fontsize = forcesize; setcolours(); diff --git a/tools/pkg/tyrmel/recipe b/tools/pkg/tyrmel/recipe @@ -1,6 +1,6 @@ name=tyrmel -version=0.1 -rel=1 +version=0.1.1 +rel=0 desc="Terminal that looks like the console and shows pictures" url=https://chamesle.org license="MIT AND GPL-2.0-only"