-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
536 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/term/term.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Joseph Werle | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
BIN ?= term | ||
PREFIX ?= /usr/local | ||
|
||
install: | ||
cp term.sh $(PREFIX)/bin/$(BIN) | ||
|
||
uninstall: | ||
rm -f $(PREFIX)/bin/$(BIN) | ||
|
||
example.sh: | ||
./example.sh | ||
|
||
.PHONY: example.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
term.sh | ||
======= | ||
|
||
Terminal fun written in bash inspired by clibs/term | ||
|
||
## install | ||
|
||
```sh | ||
$ make install | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
$ . term.sh | ||
``` | ||
|
||
## usage | ||
|
||
``` | ||
usage: term [-hV] <command> [args] | ||
``` | ||
|
||
## example | ||
|
||
```sh | ||
$ { term color green; } && { term underline; } && { echo heyaaaa; } | ||
heyaaaa | ||
``` | ||
|
||
## api | ||
|
||
``` | ||
commands: | ||
write <code> Write a terminal escape code | ||
cursor <op> Perform operation to cursor | ||
color <color> Set terminal color by name (See colors) | ||
background <color> Set terminal background by name (See colors) | ||
move <x> <y> Move to (x, y) | ||
transition <x> <y> Transition to (x, y) | ||
clear <section> Clear terminal section by name (See sections) | ||
reset Reset the terminal escape code sequence | ||
bright Write bright escape code | ||
dim Write dim escape code | ||
underline Write underline escape code | ||
blink Write blink escape code | ||
reverse Write reverse escape code | ||
hidden Write hidden escape code | ||
colors: | ||
black $ term color black | ||
red $ term color red | ||
green $ term color green | ||
yellow $ term color yellow | ||
blue $ term color blue | ||
magenta $ term color magenta | ||
cyan $ term color cyan | ||
white $ term color white | ||
gray|grey $ term color gray | ||
sections: | ||
start Start of line | ||
end End of line | ||
up Upper section | ||
down Lower section | ||
line Current line | ||
screen Entire screen | ||
``` | ||
|
||
## histogram | ||
|
||
See `example.sh` | ||
|
||
``` | ||
. | ||
. | ||
. | ||
. | ||
. | ||
█ | ||
. █ | ||
█ | ||
. █ | ||
█ █ | ||
. █ █ | ||
█ █ | ||
█ █ | ||
. █ █ █ █ █ █ █ █ █ █ █ | ||
``` | ||
|
||
## license | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
|
||
## include | ||
. term.sh | ||
|
||
## data | ||
declare -a data=( 0 2 3 1 3 3 3 8 2 12 4 2 4 3 ) | ||
|
||
## clean up everything | ||
cleanup () { | ||
## clear | ||
term clear screen | ||
## bring back cursor | ||
term cursor show | ||
return 0 | ||
} | ||
|
||
## on SIGINT signal | ||
onsigint () { | ||
cleanup | ||
exit 1 | ||
} | ||
|
||
## clear screen | ||
term clear screen | ||
|
||
## position to top left | ||
term move 0 0 | ||
|
||
## clear line | ||
term clear line | ||
|
||
## hide cursor | ||
term cursor hide | ||
|
||
## catch sigint | ||
trap "onsigint" SIGINT | ||
|
||
|
||
## main loop | ||
{ | ||
let pad=3 | ||
let n=0 | ||
let w=($(tput cols)) | ||
let h=($(tput lines)) | ||
let x=0 | ||
let y=0 | ||
let len="${#data[@]}" | ||
|
||
term clear screen | ||
|
||
term move ${pad} 1 | ||
|
||
## y axis | ||
for (( n = 0; n < (h - pad - 1); n += 2 )); do | ||
term transition 0 2 | ||
term color gray | ||
printf "." | ||
done | ||
|
||
y=( ${h} - 2 ) | ||
term move ${pad} ${y} | ||
|
||
## x axis | ||
for (( n = 0; n < (w - pad * 3); n += 6)); do | ||
term color gray | ||
printf "." | ||
term transition 6 0 | ||
done | ||
|
||
x=0 | ||
for (( i = 0; i < len; ++i )); do | ||
let n="${data[$i]}" | ||
while (( n-- )); do | ||
if (( n < 0 )); then | ||
break | ||
fi | ||
let a=( ${x} * 6 + ${pad} ) | ||
let b=( ${h} - ${n} + ${pad} ) | ||
#echo $a $b | ||
term move ${a} ${b} | ||
term reset | ||
printf "█" | ||
done | ||
(( x++ )) | ||
sleep .5 | ||
done | ||
|
||
h=( ${h} - 1) | ||
term move ${w} ${h} | ||
} | ||
|
||
## clean up terminal | ||
cleanup | ||
|
||
## exit | ||
exit $? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "term", | ||
"version": "0.0.1", | ||
"description": "Terminal utility functions", | ||
"scripts": [ "term.sh" ], | ||
"install": "make install" | ||
} |
Oops, something went wrong.