Skip to content

Commit

Permalink
Refactor variables, add text right align setting, add input reader
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjc826 committed May 13, 2024
1 parent 34b4baa commit c440ac6
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 57 deletions.
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external-sources=true
30 changes: 30 additions & 0 deletions examples/custom_input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
#
# ./custom_input.sh
#
# Reverses the given input word.
# A word is terminated with space.
#
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
pushd "$SCRIPT_DIR" || exit
. ../simple_curses.sh
WORD=""
main() {
window "ReverseInput" "white" "20%"
append "$WORD" "left"
endwin
}

update() {
local input_str=$2
local input=($2)
if [ -n "${input[0]}" ] && [ "${input_str: -1}" == " " ]
then
WORD=$(rev <<<"${input[0]}")
RETURN_VALUE=${input[*]:1}
fi
return 0
}

main_loop "$@" --enable-input
popd || exit
4 changes: 3 additions & 1 deletion examples/progress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# Shows animated progress bar.
# returns 255 when progress exceeds maxprogress
#
source $(dirname $0)/../simple_curses.sh
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
pushd "$SCRIPT_DIR" || exit
source ../simple_curses.sh
progress=0
maxprogress=97
main(){
Expand Down
18 changes: 11 additions & 7 deletions examples/wintest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

source $(dirname $0)/../simple_curses.sh
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
pushd "$SCRIPT_DIR" || exit
source ../simple_curses.sh
main(){
window "Test 1" "red" "33%"
append "First simple window"
Expand All @@ -9,7 +11,7 @@ main(){
endwin

window "Tree files" "green" "33%"
if [[ -x `which tree 2> /dev/null` ]]; then
if [[ -x $(which tree 2> /dev/null) ]]; then
append_command "tree -L 2 -C -A ./"
else
append "Please install tree command"
Expand All @@ -30,14 +32,14 @@ main(){

window "Test 4" "grey" "33%"
append "Example using command"
append "`date`"
append "$(date)"
append "I only ask for date"
endwin

window "Let's play with libcaca" "green" "33%"
command="img2txt $(dirname $0)/../tux.gif -y 12 -W 45 -d ordered2 -f utf8"
command="img2txt $(dirname "$0")/../tux.gif -y 12 -W 45 -d ordered2 -f utf8"
append "$command"
if [[ -x `which img2txt 2> /dev/null` ]]; then
if [[ -x $(which img2txt 2> /dev/null) ]]; then
append_command "$command"
else
append "You should install caca-utils"
Expand All @@ -48,7 +50,8 @@ main(){
move_up

window "Test 5" "red" "34%"
append "We can add some little windows... rememeber that very long lines are wrapped to fit window !" "left"
append "Left-aligned: We can add some little windows... rememeber that very long lines are wrapped to fit window !" "left"
append "Right-aligned: We can add some little windows... rememeber that very long lines are wrapped to fit window !" "right"
endwin

window "Tabbed values" "red" "34%"
Expand All @@ -64,7 +67,7 @@ main(){
col_right
window "Other window" "blue" "23%"
append "And this is\nanother little window"
append "`date`"
append "$(date)"
endwin

move_up
Expand All @@ -74,3 +77,4 @@ main(){
endwin
}
main_loop "$@"
popd || exit
Loading

0 comments on commit c440ac6

Please sign in to comment.