Tried to wordwrap that thing but failed. Maybe you can do it directly in Argu?
let breakLine(text:string, pos:int, max:int) =
// Find last whitespace in line
let mutable i = max - 1
while i >= 0 && not (Char.IsWhiteSpace(text.[pos + i])) do
i <- i - 1
if i < 0 then
max // No whitespace found; break at maximum length
else
// Find start of whitespace
while i >= 0 && Char.IsWhiteSpace(text.[pos + i]) do
i <- i - 1
// Return length of text before whitespace
i + 1
let wordwrap (s:string,width:int,newDelimiter:string) =
let s = s.Replace("\r\n","\n").Replace("\r","\n")
let sb = new StringBuilder()
// Lucidity check
if width < 1 then s else
// Parse each line of text
let mutable pos = 0
let mutable next = 0
while pos < s.Length do
// Find end of line
let mutable eol = s.IndexOf( '\n', pos )
if eol = -1 then
next <- s.Length
eol <- s.Length
else
next <- eol + 1
// Copy this line of text, breaking into smaller lines as needed
if eol > pos then
while eol > pos do
let mutable len = eol - pos
if len > width then
len <- breakLine( s, pos, width)
sb.Append( s, pos, len ) |> ignore
sb.Append( newDelimiter ) |> ignore
// Trim whitespace following break
pos <- pos + len
while pos < eol && Char.IsWhiteSpace( s.[pos] ) do
pos <- pos + 1
else
sb.Append( newDelimiter ) |> ignore // Empty line
pos <- next
sb.ToString()