Comments (15)
Hi
No that isn't possible because the wget process bar would class/overwrite the spinner. The spinner is there for times where there isn't any visible progress just to let the end users know it is still working.
You could do something like:
start_spinner "File downloading please wait..."
wget -q
stop_spinner
This would silence the process bar from wget and replace it with the spinner.
from bash-spinner.
Ah ok, I see what you're trying to do, give me a little time to try a few things out, I have a couple of idea
from bash-spinner.
Thanks! No, go ahead.
from bash-spinner.
Would it be possible to do something like:
start_spinner "$(cat log | tail -1)"
long_process > log
stop_spinner
Unless you think that would be very diffficult to implement, I could give it a try and open a pull request if I get it working.
I'm not very experienced with bash though, so I won't bother trying too hard if you think it's too difficult. Would be a great feature though, what do you think?
from bash-spinner.
Because of what start_spinner does, it expects a string and then simply outputs this to the screen, before displaying the spinner.
Trying to make this a dynamically updating 'thing' would definitely not be a simple tasks and kind of breaks what this was designed to do.
If you want to give me an idea of what you want to do I might be able to come up with something or even a new tool to do what you are needing.
from bash-spinner.
Say I have a long running process that logs to a file. I start the spinner before running the command and stop it after. While the command is running, I want the spinner message to be dynamic, and in this case to be the value of last line of the log.
start_spinner 'cat log | tail -1'
echo 1 >> log
sleep 1
echo 2 >> log
sleep 1
echo 3 >> log
sleep 1
stop_spinner
I almost made it work with a small modification to draw spinner:
function draw_spinner()
{
# shellcheck disable=SC1003
local -a marks=( '/' '-' '\' '|' )
local i=0
delay=${SPINNER_DELAY:-0.25}
while :; do
message=$(eval "$1")
printf '%s\r' "${marks[i++ % ${#marks[@]}]} $message"
sleep "${delay}"
done
}
... But there's still a few issues:
from bash-spinner.
I have released a new version (v0.1.1) which seems to do what it is you are looking for, I pretty much used your solution, but made a new function so people can use static or dynamic messages. Let me know if this helps.
Dynamic Demo:
source spinner.sh
start_spinner_eval 'cat log | tail -1'
for i in {1..10}; do
echo "Iteration number ${i}" >> log
sleep 1
done
stop_spinner
from bash-spinner.
Nice! I used it to make this wget spinner function (not pretty, but it works)
function spinner_wget()
{
url=$1
start_spinner_eval "[ -f out ] && tail -1 out | sed 's/\.//g' | sed 's/%.*/%/' | sed 's/ //' | sed 's/ \+/ /' "
wget -q --show-progress "$url" 2>&1 | tee >(awk '{print}' > out) > /dev/null
stop_spinner
rm out
}
Perhaps a bit silly, but there it is.
from bash-spinner.
Thats actually a really nice example - do you mind if I use it as an advanced example of the README ?
from bash-spinner.
Hold up, seems like spinner_wget corrupts the downloaded file. I'll have to test it a bit more.
from bash-spinner.
Not sure how it would impact the file. All the spinner does is print to the screen, so the wget -q shouldn't be impacted. I will do some testing later this week though
from bash-spinner.
Yikes, my earlier function was way overkill. Not sure if file was corrupted from spinner_wget or not (maybe due to the process substitution?). Anyway, this is much cleaner, both implementation and output wise:
function spinner_wget()
{
url=$1
start_spinner_eval "[ -f wget_log ] && cat wget_log | sed 's/\r/\n/g'| tail -1"
wget -o wget_log --progress=bar:force "$url"
stop_spinner
rm wget_log
}
Yeah, who would've guessed that there's a lot of valuable information in the manual, such as that wget already has progress logging implemented...
from bash-spinner.
Oh nice work, process substitution can def cause issues, the spinner doesnt touch the actual command you're running, but it does print to stdout so that could have got messed up.
from bash-spinner.
For reference, I made this function to print the output of docker load inside the spinner...
function spinner_docker_load() {
local tar=$1
# Some commands, like docker load, only output if they think stdout is a terminal, so we must call faketty before those commands to allow logging
# https://stackoverflow.com/a/20401674/14756965
function faketty() {
script -qfc "$(printf "%q " "$@")" /dev/null
}
function evalfunc() {
if [ -f load_log ]
then
cat load_log `# See http://www.cse.psu.edu/~kxc104/class/cmpen472/16s/hw/hw8/vt100ansi.htm`\
| sed "s/\x1B//g" `# Remove ESC`\
| sed 's/\[[12][ABK]/\n/g' `# Remove [1A, [2K and [1B`\
| sed "s/\r//g" `# Remove carriage return`\
| tail -1
fi
}
start_spinner_eval "evalfunc"
faketty docker load -i $tar >load_log
stop_spinner
rm load_log
}
from bash-spinner.
^ NB for using above with argbash/m4: matejak/argbash#150
from bash-spinner.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bash-spinner.