使用文本编辑器的Ruby控制台应用 [英] Ruby console application using text editor?

查看:167
本文介绍了使用文本编辑器的Ruby控制台应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Ruby构建一个控制台应用程序。我想要做的事情之一是编辑文本文件。这让我觉得最合理的做法是启动用户设置的默认编辑器 - nano,vi,emacs ...让用户决定。我想传递它将被创建/编辑的文件的名称。



我已经研究了各种方法,包括像这样的反引号:

  response =`nano * nameoffile *`

我也尝试过使用POpen4 Ruby gem,它也没有做任何事情。



我怀疑这些方法是严格适用于即时返回结果的常见非壳型应用程序,像nano这样的编辑器需要不同的技术?您的反馈非常感谢!



干杯,

Aaron。

interactive_editor ,他们这样做。


I'm building a console application in Ruby. One of the things I'd like it to do is edit text files. It strikes me that the most reasonable course of action would be to launch whatever default editor the user has set up -- nano, vi, emacs... let the user decide. I'd like to pass it the name of the file that will be created/edited.

I've investigated various methods, including the backticks like so:

response = `nano *nameoffile*`

And I've also tried using the POpen4 Ruby gem, which also doesn't seem to do anything.

I suspect these methods are strictly for common, non-shell-type applications that immediately return a result, and editors like nano require a different technique? Your feedback is much appreciated!

Cheers,

Aaron.

解决方案

You might want to take a look at interactive_editor, they do something like that.

这篇关于使用文本编辑器的Ruby控制台应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆