-- | This module handles the complexities of writing information to the-- terminal, including modifying text in place.moduleTest.HUnit.Terminal(terminalAppearance)whereimportData.Char(isPrint)-- | Simplifies the input string by interpreting @\\r@ and @\\b@ characters-- specially so that the result string has the same final (or /terminal/,-- pun intended) appearance as would the input string when written to a-- terminal that overwrites character positions following carriage-- returns and backspaces.terminalAppearance::String->StringterminalAppearancestr=taid""""str-- | The helper function @ta@ takes an accumulating @ShowS@-style function-- that holds /committed/ lines of text, a (reversed) list of characters-- on the current line /before/ the cursor, a (normal) list of characters-- on the current line /after/ the cursor, and the remaining input.ta::([Char]->t)-- ^ An accumulating @ShowS@-style function-- that holds /committed/ lines of text->[Char]-- ^ A (reversed) list of characters-- on the current line /before/ the cursor->[Char]-- ^ A (normal) list of characters-- on the current line /after/ the cursor->[Char]-- ^ The remaining input->ttafbsas('\n':cs)=ta(\t->f(reversebs++as++'\n':t))""""cstafbsas('\r':cs)=taf""(reversebs++as)cstaf(b:bs)as('\b':cs)=tafbs(b:as)csta_""_('\b':_)=error"'\\b' at beginning of line"tafbsas(c:cs)|not(isPrintc)=error"invalid nonprinting character"|nullas=taf(c:bs)""cs|otherwise=taf(c:bs)(tailas)cstafbsas""=f(reversebs++as)