Data and Math
vtextwrap
Wraps and fills text to the width you choose.
Released v1.0.0 · 2026-09-28use "stdlib/textwrap.ven"
Wraps and fills text to a width you choose, and splits text into words.
print words_of(" hello world ")
:: ["hello", "world"]
Reference (11 functions)
API reference
words_of(text)
Splits text into a list of whitespace-separated words.
print(words_of(" hello world "))
:: prints: ["hello", "world"]collapse_whitespace(text)
Collapses every run of whitespace in text down to a single space.
print(collapse_whitespace(" hello world "))
:: prints: hello worldhard_break_word(word, width)
Splits word into width-sized chunks, hard-breaking it as needed.
print(hard_break_word("abcdefgh", 3))
:: prints: ["abc", "def", "gh"]wrap_to_width(text, width)
Wraps text into a list of lines, each at most width characters.
print(wrap_to_width("The quick brown fox jumps over the lazy dog", 10))
:: prints: ["The quick", "brown fox", "jumps over", "the lazy", "dog"]fill_to_width(text, width)
Wraps text to width, then joins the lines back into one Text.
print(fill_to_width("The quick brown fox jumps over the lazy dog", 10))
:: prints: The quick
:: brown fox
:: jumps over
:: the lazy
:: dogindent_lines(text, prefix)
Prepends prefix to every line of text.
print(indent_lines("a\nb\nc", "> "))
:: prints: > a
:: > b
:: > cis_blank_line(l)
Tests whether l is empty or contains only whitespace.
print(is_blank_line(" "))
:: prints: yesleading_whitespace(l)
Gives back the leading run of whitespace characters at the start of l.
print(length(leading_whitespace(" abc")))
:: prints: 3common_prefix_of(a, b)
Gives back the longest common leading substring shared by a and b.
print(common_prefix_of("hello", "help"))
:: prints: heldedent_lines(text)
Removes the common leading whitespace shared by every line of text.
print(dedent_lines(" a\n b\n c"))
:: prints: a
:: b
:: cshorten_to_width(text, width, placeholder)
Collapses whitespace in text, then truncates it to fit width.
print(shorten_to_width("The quick brown fox jumps over the lazy dog", 20, "..."))
:: prints: The quick brown...