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

Some changes/features #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Mudskipper875
Copy link

  1. Remove redundant arithmetic operations from the percentage function
$(( (elapsed*100)/duration ))
  1. Simplify defining the $fit_to_screen variable

    • Bash can only do integer arithmetic.
    • If (( duration < space_available )) is true, $(( duration / space_available )) will be zero.
    • So the value of fit_to_screen will be 0 + 1.
  2. Customization of the progress bar

    • The progress bar can be customized using the $BAR_FILL and $BAR_EMPTY variables.
# For example, setting a red progress bar:
export BAR_FILL='\e[1;31m▇\e[0m'
progress-bar 10

progress

  1. The escape sequence \r\e[K will return the cursor to the beginning of the line and erase all text up to the end of the line.

`100/100` and extra parentheses are redundant.
Bash can only do integer arithmetic.
So if `(( duration < space_available ))` is true,
`$(( duration / space_available ))` will be zero and the value of
`fit_to_screen` will be "0 + 1".
The prgress bar can be customized using the `BAR_FILL` and `BAR_EMPTY`
variables.
Add escape sequence to the `clean_line` function after carriage return.
This will even clear any text inadvertently typed in the terminal while
the progress bar is in use.
@llbit
Copy link

llbit commented Mar 28, 2024

The fit_to_screen variable is redundant. The number of characters that are part of the completed progress can be calculated with the expression (space_available * elapsed) / duration and if this is stored in a local variable, say midpoint, inside the loop that calls already_done() and remaining() they can be simplified to:

already_done() { for ((i=0; i<midpoint ; i=i+1 )); do printf ""; done }
remaining() { for (( i=midpoint ; i<space_available ; i=i+1 )); do printf " "; done }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants