Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I code command line interface?

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.

like image 401
eonil Avatar asked Aug 02 '26 14:08

eonil


2 Answers

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.

like image 58
SF. Avatar answered Aug 04 '26 04:08

SF.


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.

like image 31
sashang Avatar answered Aug 04 '26 04:08

sashang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!