简体   繁体   English

Mono,C#控制台,腻子-箭头键变为空字符

[英]Mono, C# Console, Putty - Arrow Keys Becoming Null Characters

I'm creating a basic C# console application which runs on my debian server using Mono for compilation. 我正在创建一个基本的C#控制台应用程序,该应用程序使用Mono进行编译在我的debian服务器上运行。

I'm using PuTTY to communicate with the server & send commands to the app I'm creating. 我正在使用PuTTY与服务器通信并将命令发送到正在创建的应用程序。

The problem: 问题:
If I try to go to previous command, next command, move left/right in entered input => using arrow keys - nothing happens! 如果我尝试转到上一个命令,下一个命令,请使用箭头键在输入的输入=>中向左/向右移动-什么都不会发生!

When I investigated the problem, found out that every arrow key I press is send to input as a null character '\\0' (found out by iterating over every key in output of Console.Readline()). 当我研究问题时,发现我按下的每个箭头键都以空字符'\\ 0'的形式发送到输入(通过遍历Console.Readline()输出中的每个键来发现)。

And yes, it works fine on Windows (10)! 是的,它在Windows(10)上可以正常工作!

I ask you: 我问你:

Is it problem of PuTTY or it's settings ? 是腻子问题还是它的设置?
Is it problem related to Mono or my own code ? 是与Mono或我自己的代码有关的问题吗?
Do I just have to deal with it ? 我是否需要处理?

Cecilio is correct, ReadLine does not implement that functionality. Cecilio是正确的, ReadLine没有实现该功能。 What you are seeing on Windows is "Shell" integration. 您在Windows上看到的是“ Shell”集成。

StreamReader.ReadLine StreamReader.ReadLine

Reads a line of characters from the current stream and returns the data as a string. 从当前流中读取一行字符,并将数据作为字符串返回。

If you are looking for the same shell-style integration without using a readline lib you should look at the LineEditor class: 如果您在不使用readline lib的情况下寻找相同的shell样式集成,则应查看LineEditor类:

getline.cs: Partying like its 1988 getline.cs:像1988年一样参加派对

Note: the source links are out of date in the blog, so use Mono/Mono at Github. 注意:博客中的源链接已过期,因此请在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. 它支持常规光标编辑,类似Emacs的编辑命令,历史记录,历史记录中的增量搜索以及历史记录的加载和保存。

The ReadLine function does not implement the history/edit functionality you are expecting. ReadLine函数不能实现您期望的历史记录/编辑功能。 It just reads a string, nothing more. 它只读取一个字符串,仅此而已。 EDIT : But it does! 编辑 :但是可以!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM