Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions src/Text/ANSI/CSI.idr
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ scrollDown n = "\x1B[" ++ show n ++ "T"
export
scrollDown1 : String
scrollDown1 = scrollDown 1

||| Saves cursor position of the terminal (rewriting the old one, if present).
||| This is a non-standard, but widely supported command.
export
saveCursorPos : String
saveCursorPos = "\x1B[s"

||| Restore most recently saved cursor position.
||| This is a non-standard, but widely supported command.
export
restoreCursorPos : String
restoreCursorPos = "\x1B[u"

||| Shows or hides the cursor, depending on its argument
||| This is a non-standard, but widely supported command.
export
showCursor : Bool -> String
showCursor b = "\x1B[?25" ++ if b then "h" else "l"
16 changes: 16 additions & 0 deletions src/Text/ANSI/SGR.idr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ data Color
| BrightMagenta
| BrightCyan
| BrightWhite
| Color256 Bits8
| RGB Bits8 Bits8 Bits8

Cast Color String where
cast Black = "0"
Expand All @@ -40,24 +42,36 @@ Cast Color String where
cast BrightMagenta = "13"
cast BrightCyan = "14"
cast BrightWhite = "15"
cast (Color256 c) = show c
cast (RGB r g b) = "\{show r};\{show g};\{show b}"

public export
data Style
= Bold
| Faint
| NotBoldOrFaint
| Italic
| NotItalic
| SingleUnderline
| DoubleUnderline
| NoUnderline
| Striked
| NotStriked

public export %inline
Dimmed : Style
Dimmed = Faint

public export %inline
NormalIntensity : Style
NormalIntensity = NotBoldOrFaint

Cast Style String where
cast Bold = "1"
cast Faint = "2"
cast NotBoldOrFaint = "22"
cast Italic = "3"
cast NotItalic = "23"
cast SingleUnderline = "4"
cast DoubleUnderline = "21"
cast NoUnderline = "24"
Expand Down Expand Up @@ -88,6 +102,8 @@ escapeSGR xs = "\x1B[\{params}m"
where
toCode : SGR -> String
toCode Reset = "0"
toCode (SetForeground c@(RGB {})) = "38;2;" ++ cast c
toCode (SetBackground c@(RGB {})) = "48;2;" ++ cast c
toCode (SetForeground c) = "38;5;" ++ cast c
toCode (SetBackground c) = "48;5;" ++ cast c
toCode (SetStyle s) = cast s
Expand Down