Mono、C# 控制台、Putty - 箭头键变为空字符
Mono, C# Console, Putty - Arrow Keys Becoming Null Characters
我正在创建一个基本的 C# 控制台应用程序,它在我的 debian 服务器上运行,使用 Mono 进行编译。
我正在使用 PuTTY 与服务器通信并将命令发送到我正在创建的应用程序。
问题:
如果我尝试转到上一个命令、下一个命令,在输入的输入中移动 left/right => 使用箭头键 - 没有任何反应!
当我调查问题时,发现我按下的每个箭头键都作为空字符“\0”发送到输入(通过遍历 Console.Readline() 输出中的每个键发现) .
是的,它在 Windows (10) 上运行良好!
我问你:
Is it problem of PuTTY or it's settings ?
Is it problem related to Mono or my own code ?
Do I just have to deal with it ?
ReadLine 函数没有实现您期望的 history/edit 功能。它只是读取一个字符串,仅此而已。 编辑:但确实如此!
Cecilio 是正确的,ReadLine
没有实现该功能。您在 Windows 上看到的是 "Shell" 集成。
Reads a line of characters from the current stream and returns the data as a string.
如果您正在寻找相同的 shell-style 集成而不使用 readline 库,您应该查看 LineEditor
class:
getline.cs: Partying like its 1988
注意:博客中的源链接已过时,因此请在 Github 上使用 Mono/Mono。
using Mono.Terminal;
LineEditor le = new LineEditor ("MyApp");
while ((s = le.Edit ("prompt> ", "")) != null)
Console.WriteLine ("You typed: " + s);
It supports the regular cursor editing, Emacs-like editing commands, history, incremental search in the history as well as history loading and saving.
我正在创建一个基本的 C# 控制台应用程序,它在我的 debian 服务器上运行,使用 Mono 进行编译。
我正在使用 PuTTY 与服务器通信并将命令发送到我正在创建的应用程序。
问题:
如果我尝试转到上一个命令、下一个命令,在输入的输入中移动 left/right => 使用箭头键 - 没有任何反应!
当我调查问题时,发现我按下的每个箭头键都作为空字符“\0”发送到输入(通过遍历 Console.Readline() 输出中的每个键发现) .
是的,它在 Windows (10) 上运行良好!
我问你:
Is it problem of PuTTY or it's settings ?
Is it problem related to Mono or my own code ?
Do I just have to deal with it ?
ReadLine 函数没有实现您期望的 history/edit 功能。它只是读取一个字符串,仅此而已。 编辑:但确实如此!
Cecilio 是正确的,ReadLine
没有实现该功能。您在 Windows 上看到的是 "Shell" 集成。
Reads a line of characters from the current stream and returns the data as a string.
如果您正在寻找相同的 shell-style 集成而不使用 readline 库,您应该查看 LineEditor
class:
getline.cs: Partying like its 1988
注意:博客中的源链接已过时,因此请在 Github 上使用 Mono/Mono。
using Mono.Terminal;
LineEditor le = new LineEditor ("MyApp");
while ((s = le.Edit ("prompt> ", "")) != null)
Console.WriteLine ("You typed: " + s);
It supports the regular cursor editing, Emacs-like editing commands, history, incremental search in the history as well as history loading and saving.