我正在 Haskell 中试验ansi-terminal,与 Linux 相比,Windows 上的行为似乎有问题。在 Linux 上,我得到一个蓝色的“@”,我可以用 wasd 键移动它(如预期的那样),并且可以通过按任何其他键退出。在 Windows 上,我只是得到一个不会移动的白色“@”,并且根本无法移动角色。
如何在 Windows 中复制 Linux 行为?
几点注意事项:
- Windows,我的意思是我在 wine 下编译和运行
- 阴谋集团 1.18.0.3
- ghc 7.6.3
- 通过'wine cabal install'安装了ansi-terminal
- 如果可能的话,我宁愿不必使用 ncurses (hscurses)
更新:最小的失败代码是:
import System.Console.ANSI
main :: IO ()
main = do
clearScreen
setCursorPosition 0 0
setSGR [SetColor Foreground Vivid Blue]
putStrLn "@"
setSGR [Reset]
在 Linux 上,这样做是“正确”的事情,即打印了一个蓝色的“@”。在酒下,我看不到任何变化。我希望这只是 wine 的一个特性,而不是 Windows,因为我没有 Windows 盒子来尝试这个。
我试过的(原始)代码:
module Main where
import Data.Monoid
import Control.Monad (unless)
import System.Console.ANSI
import System.IO
-- | thin wrapper around ansi-terminal's API ------------------------------
reset :: IO ()
reset = hSetSGR stdout [Reset]
bold :: [SGR]
bold = [SetConsoleIntensity BoldIntensity]
normal :: [SGR]
normal = [SetConsoleIntensity NormalIntensity]
background :: ColorIntensity -> Color -> [SGR]
background i c = [SetColor Background i c]
foreground :: ColorIntensity -> Color -> [SGR]
foreground i c = [SetColor Foreground i c]
swap :: [SGR]
swap = [SetSwapForegroundBackground True]
underline :: [SGR]
underline = [SetUnderlining SingleUnderline]
noUnderline :: [SGR]
noUnderline = [SetUnderlining NoUnderline]
-- Main -------------------------------------------------------------------
initTerminal :: IO ()
initTerminal = do
hSetEcho stdin False
mapM_ (`hSetBuffering` NoBuffering) [stdin, stdout]
hideCursor
hSetTitle stdout "Functional Wizardry: The Roguelike"
run :: Int -> Int -> IO ()
run x y = do
hClearScreen stdout
hSetCursorPosition stdout x y
setSGR $ bold <> foreground Vivid Blue
putStr "@"
(x', y') <- getInput
unless ((x', y') == (-1, -1)) $ run (x + x') (y + y')
getInput :: IO (Int, Int)
getInput = do
char <- getChar
case char of
'a' -> return (0, -1)
'd' -> return (0, 1)
'w' -> return (1, 0)
's' -> return (-1, 0)
_ -> do
hClearScreen stdout
hSetCursorPosition stdout 0 0
return (-1, -1)
main :: IO ()
main = do
initTerminal
run 0 0
reset