Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ breaking ] Make functions operate on DecoratedStrings instead of Strings #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/Text/ANSI.idr
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,29 @@ Show DecoratedString where
show dstr = escapeSGR dstr.sgr ++ dstr.str ++ escapeSGR [Reset]

export
colored : Color -> String -> DecoratedString
colored c = MkDString [SetForeground c]
fromString : String -> DecoratedString
fromString = MkDString []

export
background : Color -> String -> DecoratedString
background c = MkDString [SetBackground c]
addSGR : SGR -> DecoratedString -> DecoratedString
addSGR sgr (MkDString sgrs str) = MkDString (sgr :: sgrs) str

export
bolden : String -> DecoratedString
bolden = MkDString [SetStyle Bold]
colored : Color -> DecoratedString -> DecoratedString
colored c = addSGR $ SetForeground c

export
italicize : String -> DecoratedString
italicize = MkDString [SetStyle Italic]
background : Color -> DecoratedString -> DecoratedString
background c = addSGR $ SetBackground c

export
underline : String -> DecoratedString
underline = MkDString [SetStyle SingleUnderline]
bolden : DecoratedString -> DecoratedString
bolden = addSGR $ SetStyle Bold

export
italicize : DecoratedString -> DecoratedString
italicize = addSGR $ SetStyle Italic

export
underline : DecoratedString -> DecoratedString
underline = addSGR $ SetStyle SingleUnderline