简体   繁体   English

我该如何编写命令行界面?

[英]How can I code command line interface?

I'm a GUI developer. 我是一名GUI开发人员。 I have used many of GUI frameworks including WindowsForms, Flash, HTML, AppKit, UIKit. 我使用了许多GUI框架,包括WindowsForms,Flash,HTML,AppKit,UIKit。 I can say I know how to code GUI. 我可以说我知道如何编写GUI。

Suddenly I got an interest about command-line-interface. 突然间,我对命令行界面感兴趣。 Like VI or Emacs. 像VI或Emacs。 Because I started programming with GUI, I don't have any experience or knowledge about CLI. 因为我开始使用GUI编程,所以我没有任何关于CLI的经验或知识。 Of course, I used VI, and unix shells, however I don't know how to implement them. 当然,我使用了VI和unix shell,但是我不知道如何实现它们。 And I want to know it. 我想知道它。

For GUIs, most basic construct for all graphical stuff is lowest-level drawing method. 对于GUI,所有图形内容的大多数基本构造都是最低级别的绘图方法。 For software implementations, it's CPU based drawing method. 对于软件实现,它是基于CPU的绘图方法。 For hardware accelerated implementations, it's OpenGL based method. 对于硬件加速实现,它是基于OpenGL的方法。 All GUI stuffs are built on top of them. 所有GUI内容都建立在它们之上。 What can I expect for CLI? 我对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. 例如,像setPixel()函数。 Any help will be appreciated. 任何帮助将不胜感激。

PS I prefer General Unix system. PS我更喜欢通用Unix系统。 Primarily POSIX. 主要是POSIX。 And currently I'm using Mac OS X. Of course language is C. 目前我正在使用Mac OS X.当然语言是C.

If you want to dive head-on, learn ncurses and type away. 如果你想直接潜水,学习ncurses并打字。 This is THE way to write console gfx apps. 这是编写控制台gfx应用程序的方法。

If you want to learn the basics, ANSI escape codes . 如果您想学习基础知识, ANSI转义码 This is the mechanics of how ncurses interfaces with the terminal doing its magics. 这是ncurses如何与终端进行魔法交互的机制。 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. 从那里开始,使用256个ASCII代码的上半部分是原始的semigraphics,依此类推。

Look into http://en.wikipedia.org/wiki/Readline because it gives you things like command line history, tab completion etc... 请查看http://en.wikipedia.org/wiki/Readline,因为它可以为您提供命令行历史记录,制表符完成等功能。

Also ncurse http://en.wikipedia.org/wiki/Ncurses for console based dialog screens. 还可以为基于控制台的对话框屏幕添加http://en.wikipedia.org/wiki/Ncurses

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. 正如已经说过的那样,ncurses对于像unix这样的系统来说是一个很好的库,但是如果你在ms窗口下,我想事情会有所不同。

Another thing to keep in mind is that depending on your OS, you may have to learn & understand termcap entries or inherited DOS legacy. 另外要记住的是,根据您的操作系统,您可能需要学习和理解termcap条目或继承的DOS遗留问题。

For *nix you have to check some graph library if you want to experiment with pixels and alikes. 对于* nix,如果要尝试像素和类似物,则必须检查一些图形库。 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). 如果它只是你需要的普通终端接口,ncurses IS就是起点(直到你想用termcap和escapes完成所有这一切)。

There're plenty of frameworks for developing text/terminal based UI, more or less they give everything you need. 有很多框架可用于开发基于文本/终端的UI,或多或少地提供您需要的一切。 But if you want to trace a line from pixel (1,1) to pixel (10, 24), I think you should focus on graphics libs. 但是如果你想跟踪一条从像素(1,1)到像素(10,24)的线,我认为你应该专注于图形库。 (OpenGL in *nix env is easily obtained via MESA library). (* nix env中的OpenGL很容易通过MESA库获得)。

On win32, well, DirectX, but they're a reall hassle. 在win32,好吧,DirectX,但他们是一个痛苦的麻烦。

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

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

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