如何在不失去 Windows 支持的情况下将ansi-wl-pprint与haskeline一起使用?
ansi-wl-pprint 有两种输出 a 的方法SimpleDoc
:
(\doc -> displayS doc "") :: SimpleDoc -> String
displayIO stdout :: SimpleDoc -> IO ()
但是,文档警告说displayS
在 Windows 上不起作用(cmd.exe
不实现 ANSI 转义序列?)。
displayIO
不使用 haskeline 的打印功能,但是:
outputStr :: MonadIO m => String -> InputT m ()
outputStrLn :: MonadIO m => String -> InputT m ()
getExternalPrint :: MonadException m => InputT m (String -> IO ())
我现在能看到的最接近解决方案的是:
outputPretty :: (MonadException m, MonadIO m, Pretty p) => p -> InputT m ()
outputPretty p = getExternalPrint >>= doPrint
where doc = renderPretty 0.4 80 $ pretty p
doPrint print = liftIO . print $ displayS doc ""
但是,如果displayS
在 Windows 上不起作用,我宁愿不使用它。