align-equal-1.0.0.0: Aligns text prefixes before '=' for consistent formatting
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Text.AlignEqual

Description

A module providing functions for text alignment and padding.

Synopsis

Documentation

prefixLength Source #

Arguments

:: Text

The input text line

-> Maybe Int

The number of characters before the first '=' sign, or Nothing if no '=' is found, or Just the length otherwise

Calculates the number of characters preceding the first '=' sign in a text line. If no '=' is found, returns Nothing. If '=' is found, returns Just the length of the prefix before it.

>>> prefixLength "key=value"
Just 3
>>> prefixLength "a=b"
Just 1
>>> prefixLength "noequals"
Nothing

adjustLine Source #

Arguments

:: Int

The desired prefix length

-> Text

The text line to pad

-> Text

The padded text line

Adjusts the prefix of a text line to a desired length by adding padding spaces.

>>> adjustLine 5 "key=value"
"key  =value"
>>> adjustLine 3 "a=b"
"a  =b"

adjustText Source #

Arguments

:: Text

The input text (possibly multi-line)

-> Text

The aligned text

Processes multi-line text to align all '=' signs across lines. It adjusts the prefix length of each line to match the maximum prefix length. If a line does not contain '=', it will be left as-is.

>>> adjustText "key=value\na=b"
"key=value\na  =b"
>>> adjustText "x=y\nlong=var"
"x   =y\nlong=var"