Skip to content

Commit

Permalink
CAD-2120: fix Windows encoding in terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Shevchenko committed Oct 23, 2020
1 parent c150a05 commit 2d626ef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/cardano-rt-view.hs
@@ -1,3 +1,10 @@
{-# LANGUAGE CPP #-}

#if defined(mingw32_HOST_OS)
import System.IO (hSetEncoding, stdout, stderr, utf8)
import System.Win32.Console (setConsoleCP)
#endif

import Options.Applicative (ParserInfo, (<**>), customExecParser, fullDesc, header,
helper, info, prefs, showHelpOnEmpty)

Expand All @@ -6,6 +13,13 @@ import Cardano.RTView.CLI (RTViewParams, parseRTViewParams)

main :: IO ()
main = do
#if defined(mingw32_HOST_OS)
-- Unfortunately, the terminal in Windows 10 isn't UTF8-ready by default.
-- Set encoding and code page explicitly.
hSetEncoding stdout utf8
hSetEncoding stderr utf8
setConsoleCP 65001
#endif
rtViewParams <- customExecParser (prefs showHelpOnEmpty) rtViewInfo
runCardanoRTView rtViewParams
where
Expand Down
2 changes: 2 additions & 0 deletions cardano-rt-view.cabal
Expand Up @@ -75,6 +75,8 @@ executable cardano-rt-view
build-depends: base >=4.12 && <5
, cardano-rt-view
, optparse-applicative
if os(windows)
build-depends: Win32

default-language: Haskell2010

Expand Down
5 changes: 2 additions & 3 deletions src/Cardano/RTView.hs
Expand Up @@ -27,9 +27,8 @@ import Cardano.RTView.WebServer (launchWebServer)
-- | Run the service.
runCardanoRTView :: RTViewParams -> IO ()
runCardanoRTView params' = do
TIO.putStrLn "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
TIO.putStrLn " RTView: real-time watching for Cardano nodes "
TIO.putStrLn "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
TIO.putStrLn "RTView: real-time watching for Cardano nodes"
TIO.putStrLn ""

(config, params, acceptors) <- prepareConfigAndParams params'

Expand Down

0 comments on commit 2d626ef

Please sign in to comment.