aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-30 11:02:48 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-30 11:02:48 +0200
commitba1b441e1da4e99546b3b7e755c8d31b73055343 (patch)
treeec809dd3e33d351a1ab91454db961a5fb2d5370d
parent00b51e3292062f52a4699440cb36b3aa337dbd17 (diff)
downloadclectio-ba1b441e1da4e99546b3b7e755c8d31b73055343.tar.gz
clectio-ba1b441e1da4e99546b3b7e755c8d31b73055343.zip
reader: verse number in a left column, hang-indent wrapped textv1.0
putwrapped now peels the leading chap:verse token into a fixed VNUM-wide column (new config knob, default 8) and hang-indents continuation lines under the text, so the reading has a straight left margin instead of wrapping flush to column 0. Verses without a numeric prefix still wrap flush-left; the WRAP<=0 (terminal-fit) path is unchanged.
-rw-r--r--clectio.c50
-rw-r--r--config.def.h3
2 files changed, 41 insertions, 12 deletions
diff --git a/clectio.c b/clectio.c
index 61d25a0..0032557 100644
--- a/clectio.c
+++ b/clectio.c
@@ -98,17 +98,42 @@ static int termwidth(void) {
return 72;
}
-/* Print s wrapped at w columns, breaking on spaces (greedy). w <= 0 prints s
- * unwrapped. UTF-8 aware: continuation bytes (0x80-0xBF) do not count as a
- * column, so multibyte letters measure as one. */
+/* Print one verse: a leading "chap:verse" number in a fixed left column (VNUM
+ * wide), then the text wrapped at w columns, breaking on spaces (greedy), with
+ * continuation lines hang-indented under the text so its left edge stays
+ * straight. w <= 0 prints the text on one line after the number column. UTF-8
+ * aware: continuation bytes (0x80-0xBF) do not count as a column, so multibyte
+ * letters measure as one. A verse that does not begin with a digit gets no
+ * number column (indent 0) and wraps flush-left, as before. */
static void putwrapped(const char *s, int w) {
+ const char *text = s;
+ int indent = 0, first = 1;
+
+ if (*s >= '0' && *s <= '9') { /* peel the leading "chap:verse " token */
+ const char *sp = strchr(s, ' ');
+ if (sp) {
+ int numlen = (int)(sp - s), pad = VNUM - numlen;
+ fwrite(s, 1, (size_t)numlen, stdout);
+ if (pad < 1)
+ pad = 1; /* always a space, even after a long number */
+ while (pad-- > 0)
+ putchar(' ');
+ indent = VNUM;
+ text = sp + 1;
+ }
+ }
+
if (w <= 0) {
- printf("%s\n", s);
+ printf("%s\n", text);
return;
}
- while (*s) {
- const char *p = s, *brk = NULL;
- int col = 0;
+
+ while (*text) {
+ const char *p = text, *brk = NULL;
+ int col = indent, k;
+ if (!first) /* hang-indent continuation lines under the text */
+ for (k = 0; k < indent; k++)
+ putchar(' ');
while (*p && col < w) {
if (*p == ' ')
brk = p;
@@ -116,16 +141,17 @@ static void putwrapped(const char *s, int w) {
col++;
p++;
}
- if (!*p) { /* the rest fits on one line */
- printf("%s\n", s);
+ if (!*p) { /* the rest fits on this line */
+ printf("%s\n", text);
return;
}
- if (!brk) /* a single word longer than w: hard-break at the column */
+ if (!brk) /* a single word longer than the line: hard-break */
brk = p;
- fwrite(s, 1, (size_t)(brk - s), stdout);
+ fwrite(text, 1, (size_t)(brk - text), stdout);
putchar('\n');
- for (s = brk; *s == ' '; s++) /* skip the space(s) we broke on */
+ for (text = brk; *text == ' '; text++) /* skip the break space(s) */
;
+ first = 0;
}
}
diff --git a/config.def.h b/config.def.h
index 53f3378..25d1fe0 100644
--- a/config.def.h
+++ b/config.def.h
@@ -18,6 +18,9 @@
/* --- Wrap reading text at a column width. --------------------------------- */
#define WRAP 0 /* 0 = fit the terminal (no wrap when piped); N = fixed cols */
+/* --- Verse-number column. ------------------------------------------------- */
+#define VNUM 8 /* width of the left "chap:verse" column; text hangs under it */
+
/* ------------------------- derived (do not edit) ------------------------- */
#if GOSPEL_ONLY
# define READMODE "Gospel only"