From: simonmar@microsoft.com Date: Thu, 1 Jun 2006 11:54:23 +0000 (+0000) Subject: Win32: set up the console code pages X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=a91bf796d200a3b950ea30ea7a9f04ee497f39ae Win32: set up the console code pages This may help with entering non-ASCII characters at the GHCi prompt, but as usual with Unicode there's no simple solution that just works. See commentary in InteractiveUI.hs for more details. --- diff --git a/compiler/Makefile b/compiler/Makefile index b26b348..94a9c85 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -487,7 +487,12 @@ SRC_HC_OPTS += \ SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR) # We need System.Posix (or Posix when ghc < 6.2) -ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32" +ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32" +ifeq "$(bootstrapped)" "YES" +SRC_HC_OPTS += -package Win32 +PKG_DEPENDS += Win32 +endif +else ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO" SRC_HC_OPTS += -package posix else diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index c09aab5..b147bbd 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -67,6 +67,7 @@ import System.Posix #endif #else import GHC.ConsoleHandler ( flushConsole ) +import System.Win32 ( setConsoleCP, setConsoleOutputCP ) #endif #ifdef USE_READLINE @@ -374,6 +375,9 @@ runGHCi paths maybe_expr = do | otherwise -> io (ioError err) Right () -> return () #endif + -- initialise the console if necessary + io setUpConsole + -- enter the interactive loop interactiveLoop is_tty show_prompt Just expr -> do @@ -1529,7 +1533,7 @@ revertCAFs = do foreign import ccall "revertCAFs" rts_revertCAFs :: IO () -- Make it "safe", just in case --- ----------------------------------------------------------------------------- +-- ---------------------------------------------------------------------------- -- Utils expandPath :: String -> GHCi String @@ -1540,3 +1544,27 @@ expandPath path = return (tilde ++ '/':d) other -> return other + +-- ---------------------------------------------------------------------------- +-- Windows console setup + +setUpConsole :: IO () +setUpConsole = do +#ifdef mingw32_HOST_OS + -- On Windows we need to set a known code page, otherwise the characters + -- we read from the console will be be in some strange encoding, and + -- similarly for characters we write to the console. + -- + -- At the moment, GHCi pretends all input is Latin-1. In the + -- future we should support UTF-8, but for now we set the code pages + -- to Latin-1. + -- + -- It seems you have to set the font in the console window to + -- a Unicode font in order for output to work properly, + -- otherwise non-ASCII characters are mapped wrongly. sigh. + -- (see MSDN for SetConsoleOutputCP()). + -- + setConsoleCP 28591 -- ISO Latin-1 + setConsoleOutputCP 28591 -- ISO Latin-1 +#endif + return () diff --git a/libraries/Makefile b/libraries/Makefile index 6c3e6c6..cc4ee0f 100644 --- a/libraries/Makefile +++ b/libraries/Makefile @@ -14,6 +14,9 @@ SUBDIRS = base haskell98 template-haskell ifeq "$(GhcLibsWithUnix)" "YES" SUBDIRS += unix endif +ifeq "$(Windows)" "YES" +SUBDIRS += $(wildcard Win32) +endif SUBDIRS += Cabal @@ -28,9 +31,6 @@ SUBDIRS += $(wildcard HUnit) SUBDIRS += $(wildcard mtl) SUBDIRS += $(wildcard fgl) SUBDIRS += $(wildcard X11) -ifeq "$(Windows)" "YES" -SUBDIRS += $(wildcard Win32) -endif SUBDIRS += $(wildcard time) SUBDIRS += $(wildcard HGL) SUBDIRS += $(wildcard OpenGL)