Simple Bash Curses - Digilinux English

SIMPLE BASH CURSES


Today we’re gonig to know a bash library, created by Metal3D, that makes you able to create interfaces very curses-like with the easiness of Bash.

The program is named as Bashsimplecurses and it can be downloaded in his Google Code page. Sadly, this library can’t replace the legendary  curses/ncurses yet, since it supports just the view of colorful windows in the screen (No menu or forum, but for them you can us Dialog). The script has been created entirely using the functions that bash offers us (just like echo)

However, let’s not ramble and see how it works.

After you download the tar.gz pack, unpack it and give (from root) the command make install. Then, copy the file simple_curses.sh in the folder where we’ll save our scripts.

At this point, let’s see how create the windows.

#!/bin/bash
# import the script
source $(dirname $0)/simple_curses.sh

#create the main function
main(){
   window "Title of the window"
   append "Content"
   endwin
}
main_loop

 

This script will create that:


 

To give some colors to our window, we’ll just need to specify, after the name of the window, the color that we want to use (ex. “red”). The colors are:

    red
    green
    blue
    grey

And, to specify the size of the window, we have to write the percentage after the color (or the title). (Ex “50”)

The controls are the followers:

    window "TITLE" "COLOR" WIDTH = To create a window with title, color and size
    append "TEXT" = To insert a line of text in the window
    append_tabbed "TEXTE" COLS SEP = To insert a table in the window
    append_file = To insert a file in the window
    append_command = It runs a command in the window
    addsep = It adds a separator

To create more windows in one script, we’ll need to repeat all the controls remembering that, with the control move_up, we’ll back up while with col_right we’ll bring the new window on the left. To understand:


#!/bin/bash

source $(dirname $0)/simple_curses.sh

main(){
    window "Test 1" "red" "33%"
    append "First window"
    endwin

    col_right
    move_up

    window "Test 2" "red" "33%"
    append "Line 1"
    append "Line 2"
    endwin

    window "Test 3" "red" "33%"
    append "Text, text and still text"
    endwin
    window "Test 4" "grey" "33%"
    append "Example of command"
    append "`date`"
    append "Here’s the time today"
    endwin
  
    col_right
    move_up
    window "Test 5" "red" "34%"
    append "Let’s add some little windows!"
    endwin

    window "Little" "green" "12%"
    append "Little window 1"
    endwin
    col_right
    window "Other window" "blue" "22%"
    append "Little window 2"
    endwin

}
main_loop



Easy, no?

BACK ARTICLES
BACK HOME

Translated by silviadv2


La nostra pagina su Twitter!