有没有类似于 GNU readline 的 .Net 库?

发布于 2024-08-16 19:41:22 字数 148 浏览 4 评论 0原文

我正在考虑用 C# 编写一个控制台应用程序,我想合并历史记录、完成和命令行编辑功能,例如 GNU readline(但不一定那么广泛!)

是否有现有的 .net 库提供这种类型的功能功能?我想一种选择是使用互操作服务来调用 GNU readline。但有原生选项吗?

I'm considering writing a console application in C# and I want to incorporate history, completion and command line editing features something like GNU readline (but not necessarily as extensive as that!)

Is there an existing library for .net which provides this type of functionality? I guess one option would be to use interop services to call GNU readline. But is there a native option?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

隔纱相望 2024-08-23 19:41:22

您可能需要查看 Miguel de Icaza 的 getline.cs (链接在博客文章中已损坏,现在可以找到代码 这里)。根据您实际需要的 readline 功能,它可能足以满足您的目的。

好处是,它全部包含在一个(因此是 getline.cs)文件中,并获得 MIT X11 许可。

使用它非常简单。

如果您想尝试一下,只需下载文件并编译它:

C:\> csc.exe /d:DEMO getline.cs 
C:\> getline.exe
shell>

#ifdef DEMO 部分还显示了基本的 REPL:

var le = new LineEditor("whatever");
string s;

while ((s = le.Edit("my prompt> ", "")) != null)
{
    // User input from command line / prompt now in "s".
}

You may want to checkout Miguel de Icaza's getline.cs (the link in the blog post is broken, the code can now be found here). Depending on what features of readline you actually need, it might be enough for your purposes.

The nice thing is, that it is all contained in a single (hence getline.cs) file and MIT X11 licensed.

Using it is pretty easy.

If you want to give it try, just download the file and compile it:

C:\> csc.exe /d:DEMO getline.cs 
C:\> getline.exe
shell>

The #ifdef DEMO part also shows the basic REPL:

var le = new LineEditor("whatever");
string s;

while ((s = le.Edit("my prompt> ", "")) != null)
{
    // User input from command line / prompt now in "s".
}
情感失落者 2024-08-23 19:41:22

老问题,但仍然相关,因为它出现在谷歌搜索结果中。提及以下内容是有道理的:

https://github.com/tonerdo/readline 是一个很好的选择如今的选择。引用其自述文件:

ReadLine 是一个类似 GNU Readline 的库,用纯 C# 构建。它可以作为内置 Console.ReadLine() 的替代品,并带来一些从 Unix shell 获得的终端优点,例如命令历史导航和选项卡自动完成。

它是跨平台的,可以在支持 .NET 的任何地方运行,面向 netstandard1.3 意味着它可以与 .NET Core 以及完整的 .NET Framework 一起使用。

许可

该项目已获得 MIT 许可

Old question, but still relevant since it appears in Google search results. It makes sense to mention the following:

https://github.com/tonerdo/readline is a good option nowadays. Quoting its README:

ReadLine is a GNU Readline like library built in pure C#. It can serve as a drop in replacement for the inbuilt Console.ReadLine() and brings along with it some of the terminal goodness you get from unix shells, like command history navigation and tab auto completion.

It is cross platform and runs anywhere .NET is supported, targeting netstandard1.3 means that it can be used with .NET Core as well as the full .NET Framework.

License

The project is licensed under the MIT license

水波映月 2024-08-23 19:41:22

我唯一知道的是 Mono-Readline

它为 GNU Readline 库提供了一个 .NET 接口 - 虽然它有点原始,只有 0.0.1 版本,而且我只见过它在 Mono 运行时运行。

你也应该小心授权……据我所知,任何链接 GNU Readline 库的东西都需要在 GPL 下发布。

The only thing I know of is Mono-Readline.

It provides a .NET interface to the GNU Readline library - it's a bit raw though, only version 0.0.1, and I've only ever seen it run on the Mono runtime.

You should be careful with licensing too ... AFAIK anything that links the GNU Readline libraries is required to be released under the GPL.

酒废 2024-08-23 19:41:22

旨在模拟 RedLine 大部分功能的项目是 Deveel ReadLine,但是我不得不说它没有维护。上次我使用它时,它在 .NET 和 Mono 上都运行得很好,尽管在取消自动折叠的行时存在一个小错误。

a project that aims to emulate most of the functions of RedLine is Deveel ReadLine, but I have to say that it isn't maintained. Last time I used it it worked very well on both .NET and Mono, although there's a small bug when canceling a line that was automatically folded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文