- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在试验 ansi-terminal在 Haskell 中,与 Linux 相比,Windows 上的行为似乎有问题。在 Linux 上,我得到一个蓝色的“@”,我可以用 wasd 键移动它(如预期的那样),并且可以通过按任何其他键退出。在 Windows 上,我只是得到一个不动的白色“@”,根本无法移动角色。
如何在 Windows 中复制 Linux 行为?
一些注意事项:
更新:最小的失败代码是:
import System.Console.ANSI
main :: IO ()
main = do
clearScreen
setCursorPosition 0 0
setSGR [SetColor Foreground Vivid Blue]
putStrLn "@"
setSGR [Reset]
在 Linux 上,这样做是“正确”的,因为打印了一个蓝色的“@”。在 wine 下,我看不到任何变化。我希望这只是 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
最佳答案
您的 Windows 控制台是否支持 ANSI? ANSI 终端中的字符颜色和光标定位是通过流式传输特定的 ESC 序列(及时回溯到 VT-100 DEC 终端,有些可能更早)来完成的。这需要将控制台作为流媒体设备公开。上次我尝试使用 xterm 支持的 ANSI 代码时,它在 Windows 上不起作用,我不得不编写一个 native 库来公开对 Windows 控制台 API 的访问。这是因为我能找到的 API 将 Windows 控制台暴露为不透明的 API,没有流式传输行为。
警告:我在 Java 中尝试过,但除非 Haskell ansi-terminal
库执行一些特定于平台的魔法而不是普通的 ANSI ESC 序列,否则它会以同样的方式失败。
尝试从一开始就运行 20 20
- 您是在 20,20 处得到 @
,还是仍然是 0,0?如果它仍然是 0,0,那肯定是 Windows 控制台支持 ANSI 的问题。我不知道是否可以将其配置为支持 ANSI。
关于linux - 反终端 : unexpected behavior on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22797392/
我目前正在对一个 mmorpg 的二进制网络协议(protocol)进行逆向工程。我正在用 java 实现该协议(protocol)。 对于每个数据包类型,我将创建一个表示二进制数据的类。 例如,聊天
我正在尝试围绕现有类编写半透明包装器,我希望它能够模仿其他类的序列化。 例如,给定以下类: class Foo { [JsonConverter(CustomConverter)] s
是否有使用 Jackson 序列化和反序列化枚举集的简单方法? private enum Type { YES, NO } @JacksonXmlProperty(localName = "t
我很想知道当我们反序列化一个对象时会发生什么。 例如,如果我的类对象由许多其他对象组成,对象创建过程如何在反序列化过程中发生 最佳答案 对象是用默认的初始化字段创建的,然后用从串行流中获取的属性值填充
我正在尝试序列化和反序列化(使用 QDataStream 但这与这里无关)一个 enum class变量: enum class Type : char { Trivial, Comp
我不确定这到底有什么问题...它不会为我编译,我将它从 c 翻译成 C++(或尝试)...是的,我是初学者。谢谢! #include #include using namespace std; i
我遇到的问题与此处描述的问题非常相似:Combining type and field serializers case class(id: Option[UUID], otherValue:Stri
我们知道base中的apply()可以对数组的边距应用一个函数,边距应该是行或列。我想将边距扩大到“对角线” 和“反对角线”。结构看起来像 diagApply <- function(x, FUN,
我找到了 JSON serialization and deserialization to objects in Flutter 的例子但是如何使用像这样的人员列表来做到这一点: [ {
我有一个相当大的terms聚合结果,这些结果被加载到下拉列表中以提供filter功能。 可以说,我的下拉列表中有4000多种动物。我的另一个下拉列表有4种动物颜色。 例, animal --> ["d
我需要将 C# (.NET Framework 4.5.2) 中的一个类与 XML 序列化(反序列化),该类具有 string 的字典属性。键和 string[]数组值。我正在使用 Serializa
[已解决]应用给定的解决方案,效果很好! 程序的目的:在用户打开和关闭程序时保存/重新加载以前的数据。 我曾经用一个对象(obj)成功(反)序列化,现在我有两个不同类的不同对象。 我试图通过查看其他帖
问题 假设我有一个代表某事或其他的枚举: public enum ResultState { Found, Deleted, NotFound } 在我的序列化 json 中,
是否有取消 JSON 字符串的功能?我猜它不会内置到 JQuery 中,但它可以通过编写一个操纵字符串的脚本来实现吗?我在下面遇到了这个问题。 我正在使用 NYTimes API,但它不支持 JSON
对于这个问题,假设当对象完全写入流并成功读出时,或者当对象部分写入流并且读回对象时发生异常时,序列化/反序列化是原子的。假设写操作可能无法成功完成,例如因为停电了。 在Serializable的描述中
有谁知道时序检查是否仍在检测虚拟环境?我尝试使用 rdtsc 指令来获取 cpu 周期并比较真实 linux 机器和在 virtualbox 上运行的 linux 之间的结果。但结果似乎不稳定。有时,
我正在对一个(外部给定的)XML 文件进行操作,该文件具有以下形式的元素 10 20 30 40 50 60 70 80 我知道如何将属性作为属性处理(通过使用 [XmlAttri
我有一个通用的序列化器和反序列化器,用于通过网络连接发送的消息: public static async Task SerializeObject(Object obj) {
我正在考虑将当前基于 WCF 的应用程序迁移到 protobuf-net.Grpc。这似乎是可行的,但是我无法在不包含所有具有 [ProtoInclude] 属性的派生类的情况下使(DTO 类)基类的
我正在尝试将一些数据保存到文件中,但文件保存到的目录不正确。 using (StreamWriter sw = new StreamWriter(dir + "\\temp" + x + ".txt"
我是一名优秀的程序员,十分优秀!