如何制作命令行文本编辑器?

发布于 2024-07-16 10:33:09 字数 146 浏览 4 评论 0原文

我已经了解了几种编程语言,我想尝试制作一个命令行文本编辑器——在终端中运行的东西,比如 vim/emacs/nano,但它是纯文本(请不要使用图形用户界面)。 最好,我想在 python 中执行此操作。 我从哪说起呢? 是否有任何(python)库可以执行命令行应用程序?

I have gotten to know my way around a few programming languages, and I'd like to try my hand at making a command-line text editor -- something that runs in the terminal, like vim/emacs/nano, but is pure text (no guis, please). Preferably, I'd like to do this in python. Where do I start? Are there any (python) libraries to do command-line applications?

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

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

发布评论

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

评论(10

痴者 2024-07-23 10:33:09

尝试一下 python curses 模块,它是一个命令行图形操作库。

try python curses module , it is a command-line graphic operation library.

暗喜 2024-07-23 10:33:09

查看 Python 中的 Curses 编程这个 也是如此。

Take a look at Curses Programming in Python and this as well.

落叶缤纷 2024-07-23 10:33:09

如果您想编写 TUI(文本用户界面)而不必陷入诅咒,另一个选择是 Snack< /a>,它与 Newt 一起提供。

Another option if you want to write a TUI (Text User Interface) without having to descend to curses is Snack, which comes with Newt.

零崎曲识 2024-07-23 10:33:09

今天孩子们! 哎呀! 当我刚开始的时候,诅咒还没有被广泛使用!

我的第一个文本编辑器使用实际的机械电传打字机设备和实际的纸张(而不是带有滚动屏幕的哲学“TTY”设备!)

这仍然是一种很好的编辑方式。

使用cmd模块来实现一堆命令。 使用“ex”手册页获取有关您需要什么的提示。 不要阅读有关 vi 命令的内容; 避免阅读有关 vim 的内容。

请查看旧手册页中的“EX COMMANDS”部分。 例如,这里: http://www.manpagez.com/man/1/ex/

实现追加、添加、更改、删​​除、全局、插入、连接、列表、移动、打印、退出、替换和写入命令,您会很高兴的。

Kids today! Sheesh! When I was starting out, curses was not in widespread use!

My first text editors worked on actual mechanical Teletype devices with actual paper (not a philosophical "TTY" device with a scrolling screen!)

This still works nicely as a way to edit.

Use the cmd module to implement a bunch of commands. Use the 'ex' man page for hints as to what you need. Do not read about the vi commands; avoid reading about vim.

Look at older man pages for just the "EX COMMANDS" section. For example, here: http://www.manpagez.com/man/1/ex/.

Implement the append, add, change, delete, global, insert, join, list, move, print, quit, substitute and write commands and you'll be happy.

記憶穿過時間隧道 2024-07-23 10:33:09

Curses 类型库和资源将使您进入文本用户界面,并提供非常漂亮、相对易于使用的窗口、菜单、编辑器等。

然后您将需要研究 python 的代码突出显示模块。

这是一个处理文本界面局限性的有趣过程,沿着这条路你可以学到很多东西。 祝你好运!

-亚当

Curses type libraries and resources will get you into the textual user interfaces, and provide very nice, relatively easy to use windows, menus, editors, etc.

Then you'll want to look into code highlighting modules for python.

It's a fun process dealing with the limitations of textual interfaces, and you can learn a lot by going down this road. Good luck!

-Adam

一枫情书 2024-07-23 10:33:09

我会推荐优秀的 urwid 工具包(http://excess.org/article/ 2009/03/urwid-0984-released) - 它比直接诅咒更容易使用。

I would recommend the excellent urwid toolkit (http://excess.org/article/2009/03/urwid-0984-released) - it's much easier to use than straight curses.

说谎友 2024-07-23 10:33:09

那么,GUI 是什么意思? 如果您只想创建可以在控制台上使用的东西,请查看 Python 标准库中的 curses 模块,它允许您在控制台上模拟各种原始 GUI。

Well, what do you mean by a GUI? If you just want to create something that can be used on a console, look into the curses module in the Python standard library, which allows you to simulate a primitive GUI of sorts on a console.

琉璃繁缕 2024-07-23 10:33:09

不完全是对 Python 库的引用,但 Craig A. Finseth 的文本编辑技巧可能会你感兴趣。

Not quite a reference to a Python library, but The Craft of Text Editing by Craig A. Finseth might be of interest you.

撩人痒 2024-07-23 10:33:09

一个不太严肃的建议:行编辑器可以在没有诅咒的情况下实现。

当然,这些东西非常原始,工作起来也没有太多乐趣。但是它们可以用很少的代码来实现,并且让您有机会尝试各种方案来快速维护内存中的文件状态。

他们会让你接触到七十年代初期的程序员(当时他们有电传打字机和第一台玻璃电传打字机,但打孔卡有点过时了……)。

A not very serious suggestions: a line editor can be implemented without curses.

These things are pretty primitive, of course, and not a lot of fun to work in. But they can be implemented with very little code, and would give you a chance to fool around with various schemes for maintaining the file state in memory pretty quickly.

And they would put you in touch with the programmers of the early seventies (when they had teletypes and the first glass teletypes, but after punched cards were a bit passe...).

凉墨 2024-07-23 10:33:09

另一个没有诅咒的选项是 Python Slang

Newt 是一个基于俚语编写的库。

Another option without curses is Python Slang

Newt is a library written on top of Slang.

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