ansi-terminal 0.11.4 → 0.11.5
raw patch · 14 files changed
+97/−291 lines, 14 filesdep +ansi-terminal-typesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: ansi-terminal-types
Dependency ranges changed: base
API changes (from Hackage documentation)
- System.Console.ANSI.Types: Background :: ConsoleLayer
- System.Console.ANSI.Types: Black :: Color
- System.Console.ANSI.Types: Blue :: Color
- System.Console.ANSI.Types: BoldIntensity :: ConsoleIntensity
- System.Console.ANSI.Types: Cyan :: Color
- System.Console.ANSI.Types: DoubleUnderline :: Underlining
- System.Console.ANSI.Types: Dull :: ColorIntensity
- System.Console.ANSI.Types: FaintIntensity :: ConsoleIntensity
- System.Console.ANSI.Types: Foreground :: ConsoleLayer
- System.Console.ANSI.Types: Green :: Color
- System.Console.ANSI.Types: Magenta :: Color
- System.Console.ANSI.Types: NoBlink :: BlinkSpeed
- System.Console.ANSI.Types: NoUnderline :: Underlining
- System.Console.ANSI.Types: NormalIntensity :: ConsoleIntensity
- System.Console.ANSI.Types: RapidBlink :: BlinkSpeed
- System.Console.ANSI.Types: Red :: Color
- System.Console.ANSI.Types: Reset :: SGR
- System.Console.ANSI.Types: SetBlinkSpeed :: !BlinkSpeed -> SGR
- System.Console.ANSI.Types: SetColor :: !ConsoleLayer -> !ColorIntensity -> !Color -> SGR
- System.Console.ANSI.Types: SetConsoleIntensity :: !ConsoleIntensity -> SGR
- System.Console.ANSI.Types: SetDefaultColor :: !ConsoleLayer -> SGR
- System.Console.ANSI.Types: SetItalicized :: !Bool -> SGR
- System.Console.ANSI.Types: SetPaletteColor :: !ConsoleLayer -> !Word8 -> SGR
- System.Console.ANSI.Types: SetRGBColor :: !ConsoleLayer -> !Colour Float -> SGR
- System.Console.ANSI.Types: SetSwapForegroundBackground :: !Bool -> SGR
- System.Console.ANSI.Types: SetUnderlining :: !Underlining -> SGR
- System.Console.ANSI.Types: SetVisible :: !Bool -> SGR
- System.Console.ANSI.Types: SingleUnderline :: Underlining
- System.Console.ANSI.Types: SlowBlink :: BlinkSpeed
- System.Console.ANSI.Types: Vivid :: ColorIntensity
- System.Console.ANSI.Types: White :: Color
- System.Console.ANSI.Types: Yellow :: Color
- System.Console.ANSI.Types: data BlinkSpeed
- System.Console.ANSI.Types: data Color
- System.Console.ANSI.Types: data ColorIntensity
- System.Console.ANSI.Types: data ConsoleIntensity
- System.Console.ANSI.Types: data ConsoleLayer
- System.Console.ANSI.Types: data SGR
- System.Console.ANSI.Types: data Underlining
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.SGR
- System.Console.ANSI.Types: instance GHC.Classes.Eq System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Classes.Ord System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Enum.Bounded System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Enum.Enum System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Ix.Ix System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.SGR
- System.Console.ANSI.Types: instance GHC.Read.Read System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.BlinkSpeed
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.Color
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.ColorIntensity
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.ConsoleIntensity
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.ConsoleLayer
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.SGR
- System.Console.ANSI.Types: instance GHC.Show.Show System.Console.ANSI.Types.Underlining
- System.Console.ANSI.Types: xterm24LevelGray :: Int -> Word8
- System.Console.ANSI.Types: xterm6LevelRGB :: Int -> Int -> Int -> Word8
- System.Console.ANSI.Types: xtermSystem :: ColorIntensity -> Color -> Word8
Files
- CHANGELOG.md +8/−0
- README.md +1/−1
- ansi-terminal.cabal +9/−5
- src/System/Console/ANSI/Types.hs +0/−188
- src/System/Console/ANSI/Unix.hs +8/−16
- src/System/Console/ANSI/Windows/Detect.hs +13/−17
- src/System/Console/ANSI/Windows/Emulator.hs +14/−14
- src/System/Console/ANSI/Windows/Foreign.hs +10/−13
- src/System/Win32/Compat.hs +6/−6
- src/includes/Common-Include-Emulator.hs +0/−4
- src/includes/Common-Include-Enabled.hs +0/−4
- src/includes/Common-Include.hs +9/−14
- src/includes/Common-Safe-Haskell.hs +0/−4
- src/includes/Exports-Include.hs +19/−5
CHANGELOG.md view
@@ -1,6 +1,14 @@ Changes ======= +Version 0.11.5 +-------------- + +* Module `System.Console.ANSI.Types` spun out to new dependency package + `ansi-terminal-types-0.11.5`. +* Drop support for GHC versions before GHC 7.10.1 (released March 2015). +* Improvements to Haddock documentation. + Version 0.11.4 --------------
README.md view
@@ -62,7 +62,7 @@ ------- A full example is-[available](https://github.com/UnkindPartition/ansi-terminal/blob/master/app/Example.hs),+[available](https://github.com/UnkindPartition/ansi-terminal/blob/master/ansi-terminal/app/Example.hs), but for a taste of how the library works try the following code: ``` haskell
ansi-terminal.cabal view
@@ -1,6 +1,6 @@+Cabal-Version: 1.22 Name: ansi-terminal -Version: 0.11.4 -Cabal-Version: >= 1.10 +Version: 0.11.5 Category: User Interfaces Synopsis: Simple ANSI terminal support, with Windows compatibility Description: ANSI terminal support for Haskell: allows cursor movement, @@ -37,12 +37,16 @@ Library Hs-Source-Dirs: src Exposed-Modules: System.Console.ANSI - System.Console.ANSI.Types System.Console.ANSI.Codes + -- We re-export all of ansi-terminal-types to aid compatibility for + -- downstream users. + Reexported-Modules: System.Console.ANSI.Types + Include-Dirs: src/includes - Build-Depends: base >= 4.3.0.0 && < 5 + Build-Depends: base >= 4.8.0.0 && < 5 + , ansi-terminal-types ==0.11.5 , colour >=2.1.0 if os(windows) Build-Depends: containers >= 0.5.0.0 @@ -73,7 +77,7 @@ Executable ansi-terminal-example Hs-Source-Dirs: app Main-Is: Example.hs - Build-Depends: base >= 4.3.0.0 && < 5 + Build-Depends: base >= 4.8.0.0 && < 5 , ansi-terminal , colour Ghc-Options: -Wall
− src/System/Console/ANSI/Types.hs
@@ -1,188 +0,0 @@-#include "Common-Safe-Haskell.hs" - -{-| The \'ANSI\' standards refer to the visual style of displaying characters as -their \'graphic rendition\'. The style includes the color of a character or its -background, the intensity (bold, normal or faint) of a character, or whether the -character is italic or underlined (single or double), blinking (slowly or -rapidly) or visible or not. The \'ANSI\' codes to establish the graphic -rendition for subsequent text are referred to as SELECT GRAPHIC RENDITION (SGR). - -This module exports types and functions used to represent SGR aspects. See also -'System.Console.ANSI.setSGR' and related functions. --} -module System.Console.ANSI.Types - ( - -- * Types used to represent SGR aspects - SGR (..) - , ConsoleLayer (..) - , Color (..) - , ColorIntensity (..) - , ConsoleIntensity (..) - , Underlining (..) - , BlinkSpeed (..) - -- * Constructors of xterm 256-color palette indices - , xterm6LevelRGB - , xterm24LevelGray - , xtermSystem - ) where - -import Data.Ix (Ix) -import Data.Word (Word8) - -import Data.Colour (Colour) - --- | ANSI's eight standard colors. They come in two intensities, which are --- controlled by 'ColorIntensity'. Many terminals allow the colors of the --- standard palette to be customised, so that, for example, --- @setSGR [ SetColor Foreground Vivid Green ]@ may not result in bright green --- characters. -data Color = Black - | Red - | Green - | Yellow - | Blue - | Magenta - | Cyan - | White - deriving (Eq, Ord, Bounded, Enum, Show, Read, Ix) - --- | ANSI's standard colors come in two intensities -data ColorIntensity = Dull - | Vivid - deriving (Eq, Ord, Bounded, Enum, Show, Read, Ix) - --- | ANSI colors can be set on two different layers -data ConsoleLayer = Foreground - | Background - deriving (Eq, Ord, Bounded, Enum, Show, Read, Ix) - --- | ANSI blink speeds: values other than 'NoBlink' are not widely supported -data BlinkSpeed = SlowBlink -- ^ Less than 150 blinks per minute - | RapidBlink -- ^ More than 150 blinks per minute - | NoBlink - deriving (Eq, Ord, Bounded, Enum, Show, Read, Ix) - --- | ANSI text underlining -data Underlining - = SingleUnderline - -- | Not widely supported. Not supported natively on Windows 10 - | DoubleUnderline - | NoUnderline - deriving (Eq, Ord, Bounded ,Enum, Show, Read, Ix) - --- | ANSI general console intensity: usually treated as setting the font style --- (e.g. 'BoldIntensity' causes text to be bold) -data ConsoleIntensity - = BoldIntensity - -- | Not widely supported: sometimes treated as concealing text. Not supported - -- natively on Windows 10 - | FaintIntensity - | NormalIntensity - deriving (Eq, Ord, Bounded, Enum, Show, Read, Ix) - --- | ANSI Select Graphic Rendition (SGR) command --- --- In respect of colors, there are three alternative commands: --- --- (1) the \'ANSI\' standards allow for eight standard colors (with two --- intensities). Windows and many other terminals (including xterm) allow the --- user to redefine the standard colors (so, for example 'Vivid' 'Green' may not --- correspond to bright green; --- --- (2) an extension of the standard that allows true colors (24 bit color depth) --- in RGB space. This is usually the best alternative for more colors; and --- --- (3) another extension that allows a palette of 256 colors, each color --- specified by an index. Xterm provides a protocol for a palette of 256 colors --- that many other terminals, including Windows 10, follow. Some terminals --- (including xterm) allow the user to redefine some or all of the palette --- colors. -data SGR - -- | Default rendition, cancels the effect of any preceding occurrence of SGR - -- (implementation-defined) - = Reset - -- | Set the character intensity. Partially supported natively on Windows 10 - | SetConsoleIntensity !ConsoleIntensity - -- | Set italicized. Not widely supported: sometimes treated as swapping - -- foreground and background. Not supported natively on Windows 10 - | SetItalicized !Bool - -- | Set or clear underlining. Partially supported natively on Windows 10 - | SetUnderlining !Underlining - -- | Set or clear character blinking. Not supported natively on Windows 10 - | SetBlinkSpeed !BlinkSpeed - -- | Set revealed or concealed. Not widely supported. Not supported natively - -- on Windows 10 - | SetVisible !Bool - -- | Set negative or positive image. Supported natively on Windows 10 - | SetSwapForegroundBackground !Bool - -- | Set a color from the standard palette of 16 colors (8 colors by 2 - -- color intensities). Many terminals allow the palette colors to be - -- customised - | SetColor !ConsoleLayer !ColorIntensity !Color - -- | Set a true color (24 bit color depth). Supported natively on Windows 10 - -- from the Creators Update (April 2017) - -- - -- @since 0.7 - | SetRGBColor !ConsoleLayer !(Colour Float) - -- | Set a color from a palette of 256 colors using a numerical index - -- (0-based). Supported natively on Windows 10 from the Creators Update (April - -- 2017) but not on legacy Windows native terminals. See 'xtermSystem', - -- 'xterm6LevelRGB' and 'xterm24LevelGray' to construct indices based on - -- xterm's standard protocol for a 256-color palette. - -- - -- @since 0.9 - | SetPaletteColor !ConsoleLayer !Word8 - -- | Set a color to the default (implementation-defined) - -- - -- @since 0.10 - | SetDefaultColor !ConsoleLayer - deriving (Eq, Show, Read) - --- | Given xterm's standard protocol for a 256-color palette, returns the index --- to that part of the palette which is a 6 level (6x6x6) color cube of 216 RGB --- colors. Throws an error if any of the red, green or blue channels is outside --- the range 0 to 5. An example of use is: --- --- >>> setSGR [ SetPaletteColor $ xterm6LevelRGB 5 2 0 ] -- Dark Orange --- --- @since 0.9 -xterm6LevelRGB :: Int -> Int -> Int -> Word8 -xterm6LevelRGB r g b - -- RGB colors are represented by index: - -- 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5) - | r >= 0 && r < 6 && g >= 0 && g < 6 && b >= 0 && b < 6 - = fromIntegral $ 16 + 36 * r + 6 * g + b - | otherwise - = error $ show r ++ " " ++ show g ++ " " ++ show b ++ " (r g b) is " ++ - "outside of a 6 level (6x6x6) color cube." - --- | Given xterm's standard protocol for a 256-color palette, returns the index --- to that part of the palette which is a spectrum of 24 grays, from dark --- gray (0) to near white (23) (black and white are themselves excluded). Throws --- an error if the gray is outside of the range 0 to 23. An example of use is: --- --- >>> setSGR [ SetPaletteColor $ xterm24LevelGray 12 ] -- Gray50 --- --- @since 0.9 -xterm24LevelGray :: Int -> Word8 -xterm24LevelGray y - -- Grayscale colors are represented by index: - -- 232 + g (0 ≤ g ≤ 23) - | y >= 0 && y < 24 = fromIntegral $ 232 + y - | otherwise - = error $ show y ++ " (gray) is outside of the range 0 to 23." - --- | Given xterm's standard protocol for a 256-color palette, returns the index --- to that part of the palette which corresponds to the \'ANSI\' standards' 16 --- standard, or \'system\', colors (eight colors in two intensities). An example --- of use is: --- --- >>> setSGR [ SetPaletteColor $ xtermSystem Vivid Green ] --- --- @since 0.9 -xtermSystem :: ColorIntensity -> Color -> Word8 -xtermSystem intensity color - | intensity == Dull = index - | otherwise = index + 8 - where - index = fromIntegral $ fromEnum color
src/System/Console/ANSI/Unix.hs view
@@ -11,9 +11,7 @@ import Control.Exception.Base (bracket) import Control.Monad (when) -#if MIN_VERSION_base(4,8,0) import Data.List (uncons) -#endif import Data.Maybe (fromMaybe, mapMaybe) import System.IO (BufferMode (..), Handle, hGetBuffering, hGetEcho, hIsTerminalDevice, hIsWritable, hPutStr, hReady, hSetBuffering, hSetEcho, @@ -113,12 +111,6 @@ fromMaybe "" <$> timeout 500000 (getStart startChars "") -- 500 milliseconds where endChars' = mapMaybe uncons endChars -#if !MIN_VERSION_base(4,8,0) - where - uncons :: [a] -> Maybe (a, [a]) - uncons [] = Nothing - uncons (x:xs) = Just (x, xs) -#endif -- The list is built in reverse order, in order to avoid O(n^2) complexity. -- So, getReport yields the reversed built list. @@ -129,7 +121,7 @@ c <- getChar if c == h then getStart hs (c:r) -- Try to get the rest of the start characters - else return $ reverse (c:r) -- If the first character(s) are not the + else pure $ reverse (c:r) -- If the first character(s) are not the -- expected start then give up. This provides -- a modicom of protection against unexpected -- data in the input stream. @@ -142,7 +134,7 @@ Just es -> getEnd es (c:r) -- Try to get the rest of the end characters. getEnd :: String -> String -> IO String - getEnd "" r = return $ reverse r + getEnd "" r = pure $ reverse r getEnd (e:es) r = do c <- getChar if c /= e @@ -171,9 +163,9 @@ -- operating system getReportedCursorPosition case readP_to_S cursorPosition input of - [] -> return Nothing - [((row, col),_)] -> return $ Just (row, col) - (_:_) -> return Nothing + [] -> pure Nothing + [((row, col),_)] -> pure $ Just (row, col) + (_:_) -> pure Nothing clearStdin = do isReady <- hReady stdin when isReady $ do @@ -197,9 +189,9 @@ -- operating system getReportedLayerColor layer case readP_to_S (layerColor layer) input of - [] -> return Nothing - [(col, _)] -> return $ Just col - (_:_) -> return Nothing + [] -> pure Nothing + [(col, _)] -> pure $ Just col + (_:_) -> pure Nothing where clearStdin = do isReady <- hReady stdin
src/System/Console/ANSI/Windows/Detect.hs view
@@ -9,10 +9,6 @@ , detectHandleSupportsANSI ) where -#if !MIN_VERSION_base(4,8,0) -import Control.Applicative ((<$>)) -#endif - import Control.Exception (SomeException(..), throwIO, try) import Data.Bits ((.&.), (.|.)) #ifdef MIN_VERSION_mintty @@ -62,32 +58,32 @@ terminal <- handleToTerminal h case terminal of NativeANSIIncapable -> Emulated <$> consoleDefaultState h - _ -> return Native) + _ -> pure Native) where consoleDefaultState h = do info <- getConsoleScreenBufferInfo h let attributes = csbi_attributes info fgAttributes = attributes .&. fOREGROUND_INTENSE_WHITE bgAttributes = attributes .&. bACKGROUND_INTENSE_WHITE - return ConsoleDefaultState + pure ConsoleDefaultState { defaultForegroundAttributes = fgAttributes , defaultBackgroundAttributes = bgAttributes } -- | This function tests that the handle is writable. If what is attached to the --- handle is not recognised as a known terminal, it returns @return Nothing@. +-- handle is not recognised as a known terminal, it returns @pure Nothing@. detectHandleSupportsANSI :: Handle -> IO (Maybe Bool) detectHandleSupportsANSI handle = do isWritable <- hIsWritable handle if isWritable then withHandleToHANDLE handle $ withHANDLE - (return $ Just False) -- Invalid handle or no handle + (pure $ Just False) -- Invalid handle or no handle (\h -> do terminal <- handleToTerminal h case terminal of - NativeANSIIncapable -> return (Just False) - UnknownTerminal -> return Nothing -- Not sure! - _ -> return (Just True)) - else return (Just False) -- Not an output handle + NativeANSIIncapable -> pure (Just False) + UnknownTerminal -> pure Nothing -- Not sure! + _ -> pure (Just True)) + else pure (Just False) -- Not an output handle -- | This function assumes that the Windows handle is writable. handleToTerminal :: HANDLE -> IO Terminal @@ -97,17 +93,17 @@ Left _ -> do -- No ConHost mode isMinTTY <- isMinTTYHandle h if isMinTTY - then return Mintty -- 'mintty' terminal emulator - else return UnknownTerminal -- Not sure! + then pure Mintty -- 'mintty' terminal emulator + else pure UnknownTerminal -- Not sure! Right mode -> if mode .&. eNABLE_VIRTUAL_TERMINAL_PROCESSING /= 0 - then return NativeANSIEnabled -- VT processing already enabled + then pure NativeANSIEnabled -- VT processing already enabled else do let mode' = mode .|. eNABLE_VIRTUAL_TERMINAL_PROCESSING trySetMode <- try (setConsoleMode h mode') :: IO (Either SomeException ()) case trySetMode of - Left _ -> return NativeANSIIncapable -- Can't enable VT processing - Right () -> return NativeANSIEnabled -- VT processing enabled + Left _ -> pure NativeANSIIncapable -- Can't enable VT processing + Right () -> pure NativeANSIEnabled -- VT processing enabled -- | This function applies another to the Windows handle, if the handle is -- valid. If it is invalid, the specified default action is returned.
src/System/Console/ANSI/Windows/Emulator.hs view
@@ -23,7 +23,7 @@ import Data.Colour (Colour) import Data.Colour.Names (black, blue, cyan, green, grey, lime, magenta, maroon, navy, olive, purple, red, silver, teal, white, yellow) -import Data.Colour.SRGB (RGB (..), toSRGB) +import Data.Colour.SRGB (toSRGB) #ifdef MIN_VERSION_mintty import System.Console.MinTTY (isMinTTYHandle) #else @@ -236,8 +236,8 @@ = emulatorFallback (Unix.hScrollPageDown h n) $ withHandle h $ \handle -> hScrollPage cds handle n -hUseAlternateScreenBuffer _ = return () -hUseNormalScreenBuffer _ = return () +hUseAlternateScreenBuffer _ = pure () +hUseNormalScreenBuffer _ = pure () {-# INLINE applyANSIColorToAttribute #-} applyANSIColorToAttribute :: WORD -> WORD -> WORD -> Color -> WORD -> WORD @@ -382,7 +382,7 @@ = emulatorFallback (Unix.hRestoreCursor h) $ withHandle h $ \handle -> do m <- readIORef cursorPositionRef let result = Map.lookup handle m - maybe (return ()) (setConsoleCursorPosition handle) result + maybe (pure ()) (setConsoleCursorPosition handle) result hReportCursorPosition h = emulatorFallback (Unix.hReportCursorPosition h) $ withHandle h $ @@ -395,7 +395,7 @@ hIn <- getStdHandle sTD_INPUT_HANDLE _ <- writeConsoleInput hIn $ keyPresses $ "\ESC[" ++ show y ++ ";" ++ show x ++ "R" - return () + pure () hReportLayerColor h layer = emulatorFallback (Unix.hReportLayerColor h layer) $ withHandle h $ @@ -416,7 +416,7 @@ report = printf "\ESC]%s;rgb:%04x/%04x/%04x\ESC\\" oscCode r g b hIn <- getStdHandle sTD_INPUT_HANDLE _ <- writeConsoleInput hIn $ keyPresses report - return () + pure () keyPress :: Char -> [INPUT_RECORD] keyPress c = [keyDown, keyUp] @@ -471,12 +471,12 @@ supportsANSI <- detectHandleSupportsANSI handle -- Without reference to the -- environment case supportsANSI of - Just isSupported -> return (Just isSupported) + Just isSupported -> pure (Just isSupported) Nothing -> do -- Not sure, based on the handle alone notDumb <- isNotDumb -- Test the environment if notDumb - then return Nothing -- Still not sure! - else return (Just False) -- A dumb terminal + then pure Nothing -- Still not sure! + else pure (Just False) -- A dumb terminal -- Borrowed from an HSpec patch by Simon Hengel -- (https://github.com/hspec/hspec/commit/d932f03317e0e2bd08c85b23903fb8616ae642bd) @@ -501,10 +501,10 @@ action hdl = do n <- getNumberOfConsoleInputEvents hdl if n == 0 - then return "" + then pure "" else do es <- readConsoleInput hdl n - return $ stringFromInputEvents es + pure $ stringFromInputEvents es stringFromInputEvents = cWcharsToChars . wCharsFromInputEvents wCharsFromInputEvents = mapMaybe wCharFromInputEvent wCharFromInputEvent e = if isKeyEvent && isKeyDown @@ -540,9 +540,9 @@ -- operating system input <- get case readP_to_S parse input of - [] -> return Nothing - [(value,_)] -> return $ Just value - (_:_) -> return Nothing + [] -> pure Nothing + [(value,_)] -> pure $ Just value + (_:_) -> pure Nothing where flush hdl = do n <- getNumberOfConsoleInputEvents hdl
src/System/Console/ANSI/Windows/Foreign.hs view
@@ -54,9 +54,6 @@ ConsoleException (..) ) where -#if !MIN_VERSION_base(4,8,0) -import Control.Applicative ((<$>), (<*>)) -#endif import Control.Exception (Exception, throw) import Data.Bits ((.|.), shiftL) import Data.Char (chr, ord) @@ -103,12 +100,12 @@ peekAndOffset :: Storable a => Ptr a -> IO (a, Ptr b) peekAndOffset ptr = do item <- peek ptr - return (item, ptr `plusPtr` sizeOf item) + pure (item, ptr `plusPtr` sizeOf item) pokeAndOffset :: Storable a => Ptr a -> a -> IO (Ptr b) pokeAndOffset ptr item = do poke ptr item - return (ptr `plusPtr` sizeOf item) + pure (ptr `plusPtr` sizeOf item) data COORD = COORD { coord_x :: SHORT @@ -125,7 +122,7 @@ let ptr' = castPtr ptr :: Ptr SHORT x <- peekElemOff ptr' 0 y <- peekElemOff ptr' 1 - return (COORD x y) + pure (COORD x y) poke ptr (COORD x y) = do let ptr' = castPtr ptr :: Ptr SHORT pokeElemOff ptr' 0 x @@ -156,7 +153,7 @@ let ptr' = castPtr ptr :: Ptr COORD tl <- peekElemOff ptr' 0 br <- peekElemOff ptr' 1 - return (SMALL_RECT tl br) + pure (SMALL_RECT tl br) poke ptr (SMALL_RECT tl br) = do let ptr' = castPtr ptr :: Ptr COORD pokeElemOff ptr' 0 tl @@ -173,7 +170,7 @@ peek ptr = do (size, ptr') <- peekAndOffset (castPtr ptr) visible <- peek ptr' - return (CONSOLE_CURSOR_INFO size visible) + pure (CONSOLE_CURSOR_INFO size visible) poke ptr (CONSOLE_CURSOR_INFO size visible) = do ptr' <- pokeAndOffset (castPtr ptr) size poke ptr' visible @@ -198,7 +195,7 @@ (attributes, ptr3) <- peekAndOffset ptr2 (window, ptr4) <- peekAndOffset ptr3 maximum_window_size <- peek ptr4 - return (CONSOLE_SCREEN_BUFFER_INFO + pure (CONSOLE_SCREEN_BUFFER_INFO size cursor_position attributes window maximum_window_size) poke ptr (CONSOLE_SCREEN_BUFFER_INFO size cursor_position attributes window maximum_window_size) @@ -247,7 +244,7 @@ (popup_attributes, ptr6) <- peekAndOffset ptr5 (fullscreen_supported, ptr7) <- peekAndOffset ptr6 color_table <- peekArray 16 ptr7 - return (CONSOLE_SCREEN_BUFFER_INFOEX + pure (CONSOLE_SCREEN_BUFFER_INFOEX size cursor_position attributes window maximum_window_size popup_attributes fullscreen_supported color_table) poke ptr (CONSOLE_SCREEN_BUFFER_INFOEX @@ -282,7 +279,7 @@ peek ptr = do (char, ptr') <- peekAndOffset (castPtr ptr) attributes <- peek ptr' - return (CHAR_INFO char attributes) + pure (CHAR_INFO char attributes) poke ptr (CHAR_INFO char attributes) = do ptr' <- pokeAndOffset (castPtr ptr) char poke ptr' attributes @@ -407,7 +404,7 @@ if not succeeded then getLastError >>= throw . ConsoleException -- TODO: Check if last error -- is zero for some instructable reason (?) - else return () + else pure () getConsoleScreenBufferInfo :: HANDLE -> IO CONSOLE_SCREEN_BUFFER_INFO getConsoleScreenBufferInfo handle @@ -683,7 +680,7 @@ -> InputFocusEvent <$> (`peekByteOff` 4) ptr _ -> error $ "peek (INPUT_RECORD): Unknown event type " ++ show evType - return $ INPUT_RECORD evType event + pure $ INPUT_RECORD evType event poke ptr val = do (`pokeByteOff` 0) ptr $ inputEventType val case inputEvent val of
src/System/Win32/Compat.hs view
@@ -1,11 +1,11 @@ #include "Common-Safe-Haskell.hs" {-# OPTIONS_HADDOCK hide #-} -{-| The Win32 library ships with GHC. Win32-2.1 first shipped with GHC 6.6 -(released October 2006). Win32-2.5.4.1 first shipped with GHC 8.2.1 (released -July 2017), replacing Win32-2.3.1.1. +{-| The Win32 library ships with GHC. Win32-2.3.1.0 first shipped with +GHC 7.10.1 (released March 2015). Win32-2.5.4.1 first shipped with GHC 8.2.1 +(released July 2017), replacing Win32-2.3.1.1. -The ansi-terminal library makes use of functionality in Win32-2.1 and other +The ansi-terminal library makes use of functionality in Win32-2.3.1.0 and other functionality first added to Win32-2.5.0.0 or Win32-2.5.1.0 (from ansi-terminal itself). @@ -118,8 +118,8 @@ handle_ToHANDLE (Handle__{haDevice = dev}) = case ( cast dev :: Maybe (Io NativeHandle) , cast dev :: Maybe (Io ConsoleHandle)) of - (Just hwnd, Nothing) -> return $ toHANDLE hwnd - (Nothing, Just hwnd) -> return $ toHANDLE hwnd + (Just hwnd, Nothing) -> pure $ toHANDLE hwnd + (Nothing, Just hwnd) -> pure $ toHANDLE hwnd _ -> throwErr "not a known HANDLE" throwErr msg = ioException $ IOError (Just haskell_handle)
src/includes/Common-Include-Emulator.hs view
@@ -47,16 +47,12 @@ clearFromCursorToLineBeginning def = hClearFromCursorToLineBeginning def stdout clearLine def = hClearLine def stdout --- | Scroll the displayed information up or down the terminal: not widely --- supported hScrollPageUp, hScrollPageDown :: ConsoleDefaultState -- ^ The default console state -> Handle -> Int -- ^ Number of lines to scroll by -> IO () --- | Scroll the displayed information up or down the terminal: not widely --- supported scrollPageUp, scrollPageDown :: ConsoleDefaultState -- ^ The default console state -> Int -- ^ Number of lines to scroll by
src/includes/Common-Include-Enabled.hs view
@@ -40,15 +40,11 @@ clearFromCursorToLineBeginning = hClearFromCursorToLineBeginning stdout clearLine = hClearLine stdout --- Scroll the displayed information up or down the terminal: not widely --- supported hScrollPageUp, hScrollPageDown :: Handle -> Int -- Number of lines to scroll by -> IO () --- | Scroll the displayed information up or down the terminal: not widely --- supported scrollPageUp, scrollPageDown :: Int -- ^ Number of lines to scroll by -> IO ()
src/includes/Common-Include.hs view
@@ -4,11 +4,6 @@ -- of the corresponding more general functions, including the related Haddock -- documentation. -#if !MIN_VERSION_base(4,8,0) -import Control.Applicative ((<*>)) -import Data.Functor ((<$>)) -#endif - import Control.Monad (void) import Data.Char (digitToInt, isDigit, isHexDigit) import Data.Word (Word16) @@ -256,7 +251,7 @@ -- means \'support without emulation\'.) -- -- If the handle is not writable (that is, it cannot manage output - see --- 'hIsWritable'), then @return (Just False)@ is returned. +-- 'hIsWritable'), then @pure (Just False)@ is returned. -- -- On Unix-like operating systems, with one exception, the function is -- consistent with 'hSupportsANSI'. The exception is if the handle is not @@ -264,13 +259,13 @@ -- -- On Windows, what is returned will depend on what the handle is connected to -- and the version of the operating system. If the handle is identified as --- connected to a \'mintty\' terminal, @return (Just True)@ is +-- connected to a \'mintty\' terminal, @pure (Just True)@ is -- returned. If it is identified as connected to a native terminal, then, on -- Windows 10, the processing of \'ANSI\' control characters will be enabled and --- @return (Just True)@ returned; and, on versions of Windows before Windows 10, --- @return (Just False)@ is returned. Otherwise, if a @TERM@ environment --- variable is set to @dumb@, @return (Just False)@ is returned. In all other --- cases of a writable handle, @return Nothing@ is returned; this indicates that +-- @pure (Just True)@ returned; and, on versions of Windows before Windows 10, +-- @pure (Just False)@ is returned. Otherwise, if a @TERM@ environment +-- variable is set to @dumb@, @pure (Just False)@ is returned. In all other +-- cases of a writable handle, @pure Nothing@ is returned; this indicates that -- the heuristics cannot assist - the handle may be connected to a file or -- to another type of terminal. -- @@ -299,7 +294,7 @@ void $ char ';' col <- decimal -- A non-negative whole decimal number void $ char 'R' - return (read row, read col) + pure (read row, read col) where digit = satisfy isDigit decimal = many1 digit @@ -485,7 +480,7 @@ r = fromIntegral $ m * hexToInt redHex g = fromIntegral $ m * hexToInt greenHex b = fromIntegral $ m * hexToInt blueHex - in return $ RGB r g b + in pure $ RGB r g b else fail "Color format not recognised" where hexDigit = satisfy isHexDigit @@ -544,4 +539,4 @@ hRestoreCursor h hFlush h -- ensure the restore cursor position code is sent to the -- operating system - return $ fmap (\(r, c) -> (r + 1, c + 1)) mPos + pure $ fmap (\(r, c) -> (r + 1, c + 1)) mPos
src/includes/Common-Safe-Haskell.hs view
@@ -1,5 +1,1 @@-#if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE Safe #-} -#elif __GLASGOW_HASKELL__ >= 702 -{-# LANGUAGE Trustworthy #-} -#endif
src/includes/Exports-Include.hs view
@@ -46,6 +46,12 @@ , setCursorPositionCode -- * Saving, restoring and reporting cursor position + -- | These code sequences are not part of the ECMA-48 standard; they are + -- popular, but non-portable extensions. On Unix-like operating systems, + -- they correspond to @rc@ and @sc@ capabilities in the @terminfo@ database. + -- + -- Cursor positions are relative to the viewport, not to its content. + -- , saveCursor , restoreCursor , reportCursorPosition @@ -94,8 +100,12 @@ , scrollPageDownCode -- * Using screen buffers - -- | On Windows, if emulation is required, switching between alternate and - -- normal screen buffers is not emulated. + -- | These code sequences are not part of the ECMA-48 standard; they are + -- popular, but non-portable extensions. On Unix-like operating systems, + -- they correspond to the @smcup@ and @rmcup@ capabilities in the @terminfo@ + -- database. Windows Terminal supports them. On Windows, if emulation is + -- required, switching between alternate and normal screen buffers is not + -- emulated. , useAlternateScreenBuffer , useNormalScreenBuffer -- ** \'h...\' variants @@ -116,6 +126,9 @@ , setSGRCode -- * Cursor visibilty changes + -- | These code sequences are not part of the ECMA-48 standard; they are + -- popular, but non-portable extensions. In practice, many terminals support + -- them. , hideCursor , showCursor -- ** \'h...\' variants @@ -126,9 +139,10 @@ , showCursorCode -- * Hyperlinks - -- | Some, but not all, terminals support hyperlinks - that is, clickable - -- text that points to a URI. On Windows, if emulation is required, - -- hyperlinks are not emulated. + -- | These code sequences are not part of the ECMA-48 standard or an Xterm + -- extension. However, in practice, many terminals support them, including + -- Windows Terminal. On Windows, if emulation is required, hyperlinks are + -- not emulated. , hyperlink , hyperlinkWithId , hyperlinkWithParams