Skip to content

Instantly share code, notes, and snippets.

@hasufell
Last active May 27, 2021 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasufell/4a64672bedd4b3e9be4a43d1c896189e to your computer and use it in GitHub Desktop.
Save hasufell/4a64672bedd4b3e9be4a43d1c896189e to your computer and use it in GitHub Desktop.
-- 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