如何编写命令行界面代码?

发布于 2024-12-03 10:42:03 字数 480 浏览 3 评论 0 原文

我是一名 GUI 开发人员。我使用过许多 GUI 框架,包括 WindowsForms、Flash、HTML、AppKit、UIKit。我可以说我知道如何编写 GUI 代码。

突然我对命令行界面产生了兴趣。就像 VI 或 Emacs 一样。因为我开始使用 GUI 编程,所以我对 CLI 没有任何经验或知识。当然,我使用了VI和unix shell,但我不知道如何实现它们。我想知道它。

对于 GUI,所有图形内容的最基本构造是最低级别的绘图方法。对于软件实现来说,它是基于CPU的绘图方法。对于硬件加速实现,它是基于 OpenGL 的方法。所有 GUI 的东西都是建立在它们之上的。 CLI 可以带来什么?如何在控制台上绘制文本并闪烁插入符号?

我只需要第一步。就像函数名称或库名称一样。例如,类似于 setPixel() 函数。任何帮助将不胜感激。

聚苯乙烯 我更喜欢通用Unix系统。主要是 POSIX。目前我使用的是Mac OS X。当然语言是C。

I'm a GUI developer. I have used many of GUI frameworks including WindowsForms, Flash, HTML, AppKit, UIKit. I can say I know how to code GUI.

Suddenly I got an interest about command-line-interface. Like VI or Emacs. Because I started programming with GUI, I don't have any experience or knowledge about CLI. Of course, I used VI, and unix shells, however I don't know how to implement them. And I want to know it.

For GUIs, most basic construct for all graphical stuff is lowest-level drawing method. For software implementations, it's CPU based drawing method. For hardware accelerated implementations, it's OpenGL based method. All GUI stuffs are built on top of them. What can I expect for CLI? How can I draw text on console and blink the caret?

I just need first step. Like a function name or library name. For example, something like setPixel() function. Any help will be appreciated.

P.S.
I prefer General Unix system. Primarily POSIX. And currently I'm using Mac OS X. Of course language is C.

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

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

发布评论

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

评论(4

蓬勃野心 2024-12-10 10:42:04

如果你想直接深入,请学习 ncurses 并不断打字。这是编写控制台 gfx 应用程序的方法。

如果您想学习基础知识,请ANSI 转义码。这就是 ncurses 如何与终端交互并发挥其魔力的机制。它本身很容易管理,并且是一个有趣的学习主题 - 您只需打印出转义序列,然后光标移动到屏幕上的特定点,或者您打印出的任何内容都以反相视频等方式打印。从这里开始,它是使用 256 个 ASCII 代码的上半部分等的粗略半图形。

If you want to dive head-on, learn ncurses and type away. This is THE way to write console gfx apps.

If you want to learn the basics, ANSI escape codes. This is the mechanics of how ncurses interfaces with the terminal doing its magics. It's quite manageable by itself and an interesting subject to learn - you just print out an escape sequence and the cursor moves to specific point on screen or whatever you print out is printed in inverse video and so on. And from there, it's crude semigraphics using upper half of 256 ASCII codes and so on.

蔚蓝源自深海 2024-12-10 10:42:04

查看 http://en.wikipedia.org/wiki/Readline 因为它会给你类似的东西命令行历史记录、制表符补全等...

还有 ncurse http://en.wikipedia.org/wiki/Ncurses 用于基于控制台的对话框屏幕。

Look into http://en.wikipedia.org/wiki/Readline because it gives you things like command line history, tab completion etc...

Also ncurse http://en.wikipedia.org/wiki/Ncurses for console based dialog screens.

随风而去 2024-12-10 10:42:04

您正在尝试哪种语言?适用于哪个操作系统?正如已经说过的,ncurses 对于类 UNIX 系统来说是一个很好的库,但是如果你在 ms windows 下,我想事情会变得有点不同。

另一件需要记住的事情是,根据您的操作系统,您可能必须学习并使用它。了解 termcap 条目或继承的 DOS 遗产。

对于 *nix,如果你想尝试像素之类的东西,你必须检查一些图形库。如果您需要的只是普通的终端界面,那么 ncurses 是起点(直到您想使用 termcap 和转义符手动完成这一切)。

有很多用于开发基于文本/终端的 UI 的框架,它们或多或少地提供了您需要的一切。但如果你想追踪从像素 (1,1) 到像素 (10, 24) 的线,我认为你应该关注图形库。 (*nix env 中的 OpenGL 可以通过 MESA 库轻松获得)。

在 win32 上,还有 DirectX,但它们确实很麻烦。

In which language are you experimenting ? For which os ? ncurses, as already stated, is a good lib for unix like systems, but if you're under ms windows, I guess things will get a little bit different.

Another thing to keep in mind is that depending on your OS, you may have to learn & understand termcap entries or inherited DOS legacy.

For *nix you have to check some graph library if you want to experiment with pixels and alikes. If it's just normal terminal interface you need, ncurses IS the starting point (until you want to do it all by hands with termcap and escapes).

There're plenty of frameworks for developing text/terminal based UI, more or less they give everything you need. But if you want to trace a line from pixel (1,1) to pixel (10, 24), I think you should focus on graphics libs. (OpenGL in *nix env is easily obtained via MESA library).

On win32, well, DirectX, but they're a reall hassle.

被翻牌 2024-12-10 10:42:04

C 有一个可以更好地操作终端的库:ncurses

C has a library for better manipulation of the terminal: ncurses

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