-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fails with marquee text #10
Comments
Probably because stw doesn't support control sequences (color, cursor position, etc).
Your best bet is to output complete text per frame I guess.
|
Here is a simple example: #!/bin/bash
set -eu
pad=" "
text="${pad}Very long text should scroll like <marquee> did.${pad}"
pad_size="${#pad}"
text_size="${#text}"
i=1
while [ $(( i + pad_size )) -le $text_size ]
do
printf "${text:i:pad_size}"
printf '\n\004\n'
i=$(( i + 1 ))
sleep 0.1
done Save file as marquee.sh, make it executable and run with Notice the usage of https://github.com/sineemore/stw/blob/master/config.h#L26 Also, watch out for CPU usage, |
Here is a marquee helper example in Go, you can compile it with package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"time"
)
const stwFlushFrame = "\n\004\n"
func main() {
width := flag.Int("w", 20, "output width")
sleep := flag.Duration("s", 100*time.Millisecond, "amount of sleep after each output")
flag.Parse()
pad := strings.Repeat(" ", *width)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
text := pad + scanner.Text() + pad
for i := 0; i <= len(text)-len(pad); i += 1 {
fmt.Print(text[i : i+*width])
fmt.Print(stwFlushFrame)
if *sleep != 0 {
time.Sleep(*sleep)
}
}
}
} Try it with stw -t -F'monospace:size=54' -bblack -flime sh -c 'seq 1 10 | ./marquee-helper -w 20 -s 10ms' It runs at 100 FPS with near 0 CPU usage. At least on my machine -.- |
@sineemore Thank you for your help. Both of them works well, but as you stated |
IIUC, you need something like this: #!/bin/sh
set -eu
# params
marquee_helper=~/x/stw-samples/marquee-helper # path to marquee-helper Go binary
width=100 # marquee width
sleep=100ms # animation speed
update_period=$(( 60 * 60 * 1 )) # update rss text every 1 hour
rssline() {
curl -s https://news.yahoo.com/rss/ \
| sed 's/</\n/g' \
| grep "title>" \
| sed -e '/^\// d' -e 's/title>/---------- /g' -e '1,3d' \
| tr '\n' ' '
}
unixtime() {
date +%s
}
text="$(rssline)"
last="$(unixtime)"
while :
do
echo loop >&2
now="$(unixtime)"
if [ $(( last + update_period )) -lt "$now" ]
then
text="$(rssline)"
last="$now"
echo update >&2
fi
printf '%s' "$text" | "$marquee_helper" -w "$width" -s "$sleep"
done Set valid params in the script and run with
|
@sineemore I am grateful for all your help. You spent time for me. It works well. |
@sineemore in |
Btw, while I've tested RSS script I've found, that clicks won't restart shell script immediately when it is a long running process. Fixed it in master. Clicking stw window is a hack to immediately restart subcommand (for example to get latest RSS content in your case). I use clicks to skip waiting another minute and update |
@sineemore I tested your latest push. Thanks, it works well. output2.mp4 |
Since I was not able to fix flickering issue with
|
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html Check Guideline 10 at the bottom of the page. |
@sineemore Thank you for the info. |
First of all, I congratulate you on your project. It works great except with
marquee
text.I have below script which scrolls
rss
news feeds from right to left in terminal. But unfortunately it fails.I couldn't wrap my head around it.
The text was updated successfully, but these errors were encountered: