diff --git a/README.md b/README.md index 48d2907..ee90882 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ You can then run the `anifetch` command **directly in your terminal**. Since pipx installs packages in an isolated environment, you won't have to worry about dependency conflicts or polluting your global python environment. `anifetch` will behave just like a native cli tool. You can upgrade your installation with `pipx upgrade anifetch` - --- ### 👨‍💻 Developer Installation (for contributors): via `pip` in a virtual environment @@ -137,6 +136,19 @@ If you set animation resolution really big it may not be able to keep up with th Currently only the `symbols` format of chafa is supported, formats like kitty, iterm etc. are not supported. If you try to tell chafa to use iterm, kitty etc. it will just override your format with `symbols` mode. +## Running Anifetch On Terminal Startup + +Add this to the bottom of your `.bashrc` or `.zshrc` + +```sh +# Only launch this program on direct terminal (tty) sessions +if [[ -t 1 ]] && [[ $- == *i* ]]; then + anifetch [FILENAME] [ARGS] +fi +``` + +also make sure PATH is available(for pipx installations) so it can find anifetch. + ## 🚧 What's Next - [x] Add music support @@ -161,7 +173,7 @@ Currently only the `symbols` format of chafa is supported, formats like kitty, i - [ ] Use threading when seperating video into frames and process them with chafa at the same time. This should speed up caching significantly. -- [X] Fix transparent video frame seperation. +- [x] Fix transparent video frame seperation. - [ ] Figure out a way to display animations faster. Either optimize the bash script or use Python/C. diff --git a/pyproject.toml b/pyproject.toml index 4392d1a..24798da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "anifetch" -version = "0.1.1" +version = "0.1.2" description = "Animated terminal fetch with video/audio support." authors = [{name = "Notenlish"}, {name = "Immelancholy"}, {name = "Gallophostrix", email = "gallophostrix@gmail.com"}] readme = "README.md" diff --git a/src/anifetch/anifetch-static-resize2.sh b/src/anifetch/anifetch-static-resize2.sh index 3c88fea..9d6996f 100644 --- a/src/anifetch/anifetch-static-resize2.sh +++ b/src/anifetch/anifetch-static-resize2.sh @@ -15,6 +15,7 @@ left=$3 right=$4 bottom=$5 template_actual_width=$6 +# last arg(optional) soundname=$7 num_lines=$((bottom - top)) @@ -32,17 +33,37 @@ tput civis # exit handler cleanup() { tput cnorm # Show cursor - if [ -t 0 ]; then - stty echo # Restore echo - stty icanon + # whats wrong with stty + if [ -c /dev/tty ]; then # Check if /dev/tty is a character device + stty echo < /dev/tty # Restore echo + stty icanon < /dev/tty # Restore canonical mode + else + # Fallback for if /dev/tty is not available or not a character device. + # This might still fail though + stty echo + stty icanon + fi + + # Kill ffplay if it's running + if [[ -n "$ffplay_pid" ]] && ps -p "$ffplay_pid" > /dev/null 2>&1; then + kill "$ffplay_pid" fi + tput sgr0 # Reset terminal attributes - tput cup $(tput lines) 0 # Move cursor to bottom + tput cup $(tput lines) 0 # Move cursor to bottom exit 0 } + trap cleanup SIGINT SIGTERM -stty -echo # won't allow ^C to be printed when SIGINT signal comes. + +# Apply stty commands, redirect stdin from /dev/tty +if [ -c /dev/tty ]; then +stty -echo < /dev/tty +stty -icanon < /dev/tty +else +stty -echo stty -icanon +fi # Process the template once and store in memory buffer process_template() { @@ -218,17 +239,32 @@ draw_static_template # Start audio if sound is provided if [ $# -eq 7 ]; then - ffplay -nodisp -autoexit -loop 0 -loglevel quiet "$soundname" & + ffplay -nodisp -autoexit -loop 0 -loglevel quiet "$soundname" & ffplay_pid=$! fi i=1 wanted_epoch=0 start_time=$(date +%s.%N) while true; do - for frame in $(ls "$FRAME_DIR" | sort -n); do + wanted_epoch=$(echo "$i/$framerate" | bc -l) + + # current time in seconds (with fractional part) + now=$(date +%s.%N) + + # Calculate how long to sleep to stay in sync + sleep_duration=$(echo "$wanted_epoch - ($now - $start_time)" | bc -l) + lock=true current_top=$top + + # if behind schedule + if (( $(echo "$sleep_duration < 0" | bc -l) )); then + i=$((i + 1)) + + continue # skip to the next frame. + fi + while IFS= read -r line; do tput cup "$current_top" "$left" echo -ne "$line" @@ -238,22 +274,13 @@ while true; do fi done < "$FRAME_DIR/$frame" lock=false - - wanted_epoch=$(echo "$i/$framerate" | bc -l) - - # current time in seconds (with fractional part) - now=$(date +%s.%N) - - # Calculate how long to sleep to stay in sync - sleep_duration=$(echo "$wanted_epoch - ($now - $start_time)" | bc -l) # Only sleep if ahead of schedule if (( $(echo "$sleep_duration > 0" | bc -l) )); then sleep "$sleep_duration" fi - - i=$((i + 1)) + i=$((i + 1)) process_resize_if_needed done sleep 0.005 diff --git a/src/anifetch/cli.py b/src/anifetch/cli.py index a19d484..1904ad7 100644 --- a/src/anifetch/cli.py +++ b/src/anifetch/cli.py @@ -90,7 +90,7 @@ def parse_args(): "-ff", "--fast-fetch", default=False, - help="Add this argument if you want to use fastfetch instead. Note than fastfetch will be run with '--logo none'.", + help="Add this argument if you want to use fastfetch instead of Neofetch.", action="store_true", ) parser.add_argument(