diff --git a/doc/gmnlm.scd b/doc/gmnlm.scd
index b11f3612e044ad0667d8c4d306445ae86e9f73d4..e0a368f8921253c76219790d35380848e486720d 100644
--- a/doc/gmnlm.scd
+++ b/doc/gmnlm.scd
@@ -6,7 +6,7 @@ gmnlm - Gemini line-mode browser
# SYNPOSIS
-*gmnlm* [-PU] [-j _mode_] _gemini://..._
+*gmnlm* [-PU] [-j _mode_] [-W _width_] _gemini://..._
# DESCRIPTION
@@ -25,3 +25,6 @@
*-U*
Disable conservative use of Unicode symbols to render Gemini layout
features.
+
+*-W* _width_
+ Sets the maximum width, in columns, of Gemtext pages.
diff --git a/src/gmnlm.c b/src/gmnlm.c
index 85917dfa97c034af41b9ab15e45139d6b95709de..b4f20de66d50fe9f0287c74b9a9292fe8ddd48d3 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -30,6 +30,7 @@ };
struct browser {
bool pagination, unicode;
+ int max_width;
struct gemini_options opts;
struct gemini_tofu tofu;
enum tofu_action tofu_mode;
@@ -473,6 +474,9 @@ browser->page_title = NULL;
struct winsize ws;
ioctl(fileno(browser->tty), TIOCGWINSZ, &ws);
+ if (browser->max_width != 0 && ws.ws_col > browser->max_width) {
+ ws.ws_col = browser->max_width;
+ }
FILE *out = browser->tty;
bool searching = browser->searching;
@@ -930,7 +934,7 @@ .meta = NULL,
};
int c;
- while ((c = getopt(argc, argv, "hj:PU")) != -1) {
+ while ((c = getopt(argc, argv, "hj:PUW:")) != -1) {
switch (c) {
case 'h':
usage(argv[0]);
@@ -952,6 +956,9 @@ browser.pagination = false;
break;
case 'U':
browser.unicode = false;
+ break;
+ case 'W':
+ browser.max_width = strtoul(optarg, NULL, 10);
break;
default:
fprintf(stderr, "fatal: unknown flag %c\n", c);