Skip to content

Commit

Permalink
Re #149 Add underlining colours and styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Dec 29, 2023
1 parent 1474ab7 commit 2997589
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ansi-terminal-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes
=======

Version 1.1
--------------

* Add `Underlining` constructor to type `ConsoleLayer`.
* Add `CurlyUnderline`, `DottedUnderline`, and `DashedUnderline` constructors to
type `Underlining`.

Version 0.11.5
--------------

Expand Down
2 changes: 1 addition & 1 deletion ansi-terminal-types/ansi-terminal-types.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cabal-Version: 1.22
Name: ansi-terminal-types
Version: 0.11.5
Version: 1.1
Category: User Interfaces
Synopsis: Types and functions used to represent SGR aspects
Description: The \'ANSI\' standards refer to the visual style of
Expand Down
10 changes: 9 additions & 1 deletion ansi-terminal-types/src/System/Console/ANSI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ data ColorIntensity
data ConsoleLayer
= Foreground
| Background
| Underlining
-- ^ Not widely supported.
deriving (Bounded, Eq, Enum, Ix, Ord, Read, Show)

-- | ANSI blink speeds: values other than 'NoBlink' are not widely supported
Expand All @@ -70,8 +72,14 @@ data BlinkSpeed
-- | ANSI text underlining
data Underlining
= SingleUnderline
-- | Not widely supported. Not supported natively on Windows 10
| DoubleUnderline
-- ^ Not widely supported.
| CurlyUnderline
-- ^ Not widely supported.
| DottedUnderline
-- ^ Not widely supported.
| DashedUnderline
-- ^ Not widely supported.
| NoUnderline
deriving (Bounded, Eq, Enum, Ix, Ord, Read, Show)

Expand Down
6 changes: 6 additions & 0 deletions ansi-terminal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changes
=======

Version 1.1
-----------

* Add support for console layer `Underlining` and underlining styles
`CurlyUnderline`, `DottedUnderline` and `DashedUnderline`.

Version 1.0.1
-------------

Expand Down
4 changes: 2 additions & 2 deletions ansi-terminal/ansi-terminal.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cabal-Version: 1.22
Name: ansi-terminal
Version: 1.0.1
Version: 1.1
Category: User Interfaces
Synopsis: Simple ANSI terminal support
Description: ANSI terminal support for Haskell: allows cursor movement,
Expand Down Expand Up @@ -38,7 +38,7 @@ Library
Other-Modules: System.Console.ANSI.Internal

Build-Depends: base >= 4.8.0.0 && < 5
, ansi-terminal-types == 0.11.5
, ansi-terminal-types == 1.1
, colour >= 2.1.0
if os(windows)
Hs-Source-Dirs: win
Expand Down
1 change: 1 addition & 0 deletions ansi-terminal/src/System/Console/ANSI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ layerColor layer = do
void $ string $ case layer of
Foreground -> "10"
Background -> "11"
Underlining -> fail "reportLayerColor does not support underlining"
void $ string ";rgb:"
redHex <- hexadecimal -- A non-negative whole hexadecimal number
void $ char '/'
Expand Down
16 changes: 14 additions & 2 deletions ansi-terminal/src/System/Console/ANSI/Codes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ sgrToCode' sgr = case sgr of
SetUnderlining underlining -> case underlining of
SingleUnderline -> Right [4]
DoubleUnderline -> Right [21]
CurlyUnderline -> Left (4, [Just 3])
DottedUnderline -> Left (4, [Just 4])
DashedUnderline -> Left (4, [Just 5])
NoUnderline -> Right [24]
SetBlinkSpeed blink_speed -> case blink_speed of
SlowBlink -> Right [5]
Expand All @@ -202,15 +205,21 @@ sgrToCode' sgr = case sgr of
SetColor Foreground Vivid color -> Right [90 + colorToCode color]
SetColor Background Dull color -> Right [40 + colorToCode color]
SetColor Background Vivid color -> Right [100 + colorToCode color]
SetColor Underlining Dull color -> Left (58, [Just 5, Just $ colorToCode color])
SetColor Underlining Vivid color -> Left (58, [Just 5, Just $ 8 + colorToCode color])
SetPaletteColor Foreground index -> Right [38, 5, fromIntegral index]
SetPaletteColor Background index -> Right [48, 5, fromIntegral index]
SetPaletteColor Underlining index -> Left (58, [Just 5, Just $ fromIntegral index])
SetRGBColor Foreground color -> Right $ [38, 2] ++ toRGB color
SetRGBColor Background color -> Right $ [48, 2] ++ toRGB color
SetRGBColor Underlining color -> Left (58, [Just 2, Nothing] ++ toRGB' color)
SetDefaultColor Foreground -> Right [39]
SetDefaultColor Background -> Right [49]
SetDefaultColor Underlining -> Right [59]
where
toRGB color = let RGB r g b = toSRGB24 color
in map fromIntegral [r, g, b]
toRGB' = (map Just) . toRGB

cursorUpCode, cursorDownCode, cursorForwardCode, cursorBackwardCode ::
Int -- ^ Number of lines or characters to move
Expand Down Expand Up @@ -262,9 +271,11 @@ restoreCursorCode = "\ESC8"
reportCursorPositionCode :: String
reportCursorPositionCode = csi [] "6n"

-- | Code to emit the layer color into the console input stream, immediately
-- after being recognised on the output stream, as:
-- | Code to emit the foreground or backgrond layer color into the console input
-- stream, immediately after being recognised on the output stream, as:
--
-- @ESC ] \<Ps> ; rgb: \<red> ; \<green> ; \<blue> \<ST>@
--
-- where @\<Ps>@ is @10@ for 'Foreground' and @11@ for 'Background'; @\<red>@,
-- @\<green>@ and @\<blue>@ are the color channel values in hexadecimal (4, 8,
-- 12 and 16 bit values are possible, although 16 bit values are most common);
Expand All @@ -280,6 +291,7 @@ reportCursorPositionCode = csi [] "6n"
reportLayerColorCode :: ConsoleLayer -> String
reportLayerColorCode Foreground = osc "10" "?"
reportLayerColorCode Background = osc "11" "?"
reportLayerColorCode Underlining = [] -- Not supported.

clearFromCursorToScreenEndCode, clearFromCursorToScreenBeginningCode,
clearScreenCode :: String
Expand Down

0 comments on commit 2997589

Please sign in to comment.