Last active
May 27, 2021 13:56
-
-
Save hasufell/4a64672bedd4b3e9be4a43d1c896189e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://docs.rs/ansi_term/0.12.1/x86_64-pc-windows-msvc/src/ansi_term/windows.rs.html#10-61 | |
enableAnsiSupport :: IO (Either String Bool) | |
enableAnsiSupport = handleIO (pure . Left . displayException) $ do | |
h <- createFile "CONOUT$" (gENERIC_WRITE .|. gENERIC_READ) fILE_SHARE_WRITE Nothing oPEN_EXISTING 0 Nothing | |
when (h == iNVALID_HANDLE_VALUE ) $ fail "invalid handle value" | |
m <- getConsoleMode h | |
if ((m .&. eNABLE_VIRTUAL_TERMINAL_PROCESSING) == 0) | |
then setConsoleMode h (m .|. eNABLE_VIRTUAL_TERMINAL_PROCESSING) >> pure (Right True) | |
else pure (Right False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment