How to Write Graphics on Shell Script
Unix scripting is capable of displaying more than just text. When people in the computer industry think of Unix scripting, they typically consider it only a text-based processing language. The graphical capabilities are often ignored in favor of other packages built within the system or provided as additional features. In fact, Unix shell scripts provide one of the earliest known forms of graphical interfaces by using a special library known as the curses library.
Instructions
-
Using Curses
-
1
Consult the unix man pages or book on the curses library. Read the documentation and learn the standard commands provided on your Unix system appropriate to the curses library. The "man" (manual) pages of Unix are often a good starting point. To program simple graphics using shell scripts, you need to use the curses library provided by default on most Unix installations.
-
2
Identify the terminal type so the display can display the correct graphics. Establish the terminal type for the script. In order to display graphics using the curses library and the terminfo/termcap databases of graphical capabilities, you need to identify the terminal type, such as "vt100". The terminal type is often requested by Unix commands having access to the capabilities database.
-
-
3
Design the display on paper if possible, prior to coding any graphics. Plan the graphics for your application. Before any programming can take place, you must design how the screen will look and the appropriate terminal codes to output to achieve the task.
-
4
Write the application to output graphics and text using available Unix commands. An example for graphics output is the "tput" command, available as part of the standard library on almost all Unix systems. For example, within your script, you could write "tput smro," and this would bold any subsequently displayed text using the "echo" command.
-
1
Tips & Warnings
A typical Unix system uses a graphical capability database called terminfo or termcap.
Although high definition graphics can be displayed on a Unix operating system, they are generally provided using third-party packages or "add-ons" to the system such as X-Windows. The curses library works only for simple graphics using shell commands, and not complex graphics.
Learn as much as possible about the terminal the curses library will be used for. If you use several different ones, either write commands for each type or only use terminal capabilities common to all.
Learn the commands you will need thoroughly, and keep a list of them. A number of command can manipulate the curses library, not just tput. It will also help to have a list of terminal capability codes to hand for reference.
Remember to tidy up the display effects. Every time you use a graphical command, you need to reverse it before the application ends. For example, if the display of text has been made bold by the command "tput smso", you need to reverse this by using the command "tput sgr0" to place the display in a normal state; otherwise the bold text will continue to be displayed by subsequent commands after the program has ended!
References
Resources
- Photo Credit monitor with @ sign image by patrimonio designs from Fotolia.com document image by Marvin Gerste from Fotolia.com background series - screen image by helenos from Fotolia.com bowling score screen image by dwags from Fotolia.com