Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metal3d/bashsimplecurses: A simple curses library made in bash to draw terminal interfaces #853

Open
1 task
ShellLM opened this issue Aug 1, 2024 · 1 comment
Labels
shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets

Comments

@ShellLM
Copy link
Collaborator

ShellLM commented Aug 1, 2024

metal3d/bashsimplecurses: A simple curses library made in bash to draw terminal interfaces

Snippet

Bash Simple Curses

Bash Simple Curses gives you some basic functions to quickly create windows on your terminal. 

An example is given: bashbar. Bashbar is a monitoring bar that you can integrate into tiling window managers.

The (unfinished) goal of Bash Simple Curses is to create windows. It is only intended to create colored windows and display information into. But, with a little tips, you can also make it interactive.

To use this library, you have to import simple_curses.sh into your bash script, like so:

#!/bin/bash

# import library, please check path
#source /usr/lib/simple_curses.sh
source /usr/local/lib/simple_curses.sh

# You must create a "main" function:
main () {
    # Your code here, here we add some windows and text
    window "title" "color" 
    append "Text..."
    endwin
}

# Then, execute the loop every second ( -t 1 => 1s)
main_loop -t 1
That's all.

Example

#!/bin/bash
source simple_curses.sh

main(){
    # create a window
    window "Example" "blue" "50%"
        append "Hello world"
        addsep
        append "The date command"
        append_command "date"
    endwin

    # move on the next column
    col_right

    # and create another window
    window "Example 2" "red" "50%" 
        append "Hello world"
        addsep
        append "The date command"
        append_command "date"
    endwin
}
main_loop

README

Install

There are several possibilities to use the library. We recommend to copy simple_curses.sh inside your project and to "source" it.

But, if you want to make it available for the entire system, or for local user, you can use the make install command:

# install inside the system
# in /usr/local/lib
sudo make install

# for local user, no need to use sudo, but change the PREFIX
make install PREFIX=~/.local/lib

Suggested labels

None

@ShellLM ShellLM added shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets labels Aug 1, 2024
@ShellLM
Copy link
Collaborator Author

ShellLM commented Aug 1, 2024

Related content

#60 similarity score: 0.85
#771 similarity score: 0.84
#743 similarity score: 0.84
#395 similarity score: 0.83
#62 similarity score: 0.83
#741 similarity score: 0.83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets
Projects
None yet
Development

No branches or pull requests

1 participant