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

Add optional pv viewer to limit transfer speed #10

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ brew install coreutils

#### Optional
* [fd](https://github.com/sharkdp/fd) a modern `find` replacement, it will use this preferentially if it's installed otherwise fallback to `find`
* [pv](https://www.ivarch.com/programs/pv.shtml) a pipe viewer with which we can
limit the output speed, to emulate the feel of the slower output.

Set `ANSI_MOTD_RATE_LIMIT_OUTPUT` to eg `8k` to limit data rate to 8192 bps.

### Install using your favourite plugin manager or not

Expand Down
8 changes: 7 additions & 1 deletion zsh-ansimotd.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ function ansi_art_random_file {
function ansi_art_random {
ansi_filename="$(ansi_art_random_file)"

# optional use pv to limit rate we output
viewer=(cat)
if (( $+commands[pv] )); then
op marked this conversation as resolved.
Show resolved Hide resolved
viewer=(pv --quiet --rate-limit ${ANSI_MOTD_RATE_LIMIT_OUTPUT:-1T})
fi

if [ -n "$ansi_filename" ]; then
# turn off automatic margins (a.k.a. line wrapping) if we've been told too
# this is so it'll still render something usable even if the terminal is too narrow
if [ -n "$ANSI_MOTD_DISABLE_LINE_WRAPPING" ]; then print -n '\e[?7l'; fi;

# convert from the original character set (Code page 437)
# see https://en.wikipedia.org/wiki/Code_page_437
iconv -f 437 < $ansi_filename
iconv -f 437 < $ansi_filename | ${viewer}

# restore automatic margins if we've been told too
if [ -n "$ANSI_MOTD_DISABLE_LINE_WRAPPING" ]; then print -n '\e[?7h'; fi;
Expand Down