The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Add Color To The End Of Cargo Watch Tests In Rust

TODO: Pull subtitle into page object

The Script

cargo-report
#!/bin/bash

tput clear
for i in $( seq 1 $(tput lines))
do
  echo ""
done

cargo test -q -- --nocapture

if [[ $? -eq 0 ]]
then 
  tput setaf 28
else
  tput setaf 124
fi

export BAR=$(($(tput cols) * 2))
for i in $( seq 1 $BAR); do printf '%s' '█'; done
tput sgr0

The Launcher

This is the command to run to start watching for changes and running the script when something happens. You can run it from the command line. I drop it into its own script to make it easier to launch via tab completion.

start-tests
cargo watch -q -s "./cargo-report"

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Add Color To The End Of Cargo Watch Tests In Rust

I couldn't figure out how to get a nice color splash
at the end of cargo watch test directly. Here's how
I'm doing it with a shell script that I call 
from cargo watch.

-- h3

The Script

-- code
-- shell
-- title: cargo-report 

#!/bin/bash

tput clear
for i in $( seq 1 $(tput lines))
do
  echo ""
done

cargo test -q -- --nocapture

if [[ $? -eq 0 ]]
then 
  tput setaf 28
else
  tput setaf 124
fi

export BAR=$(($(tput cols) * 2))
for i in $( seq 1 $BAR); do printf '%s' '█'; done
tput sgr0


-- h3

The Launcher

This is the command to run to start watching for
changes and running the script when something 
happens. You can run it from the command line. 
I drop it into its own script to make it easier 
to launch via tab completion. 

-- code
-- shell
-- title: start-tests

cargo watch -q -s "./cargo-report"


-- todo 

[] discusse pre-cognative visualization

[] note about how this uses `tput` on a mac to get the number of
columns. not sure about its availablity on other platforms

[] note about part that clears the screen. tbd on if I stick 
with that or not, but I like removing the prior runs so I'm 
not seeing that status. Could also put some type of ascii
art there so it's not just blank for shorter runs

[] I spent two hours figuring out how to put this together. 
Totally worth it.

[] I tried doing stuff with the ANSI escape codes. It was
working but I like `tput` better

[] Another thing that's nice about the spaces is when you 
scroll up it's easy to find the start of each run so you 
don't accidentally look at errors from a prior run. 

-- ref
-- url: https://ss64.com/osx/tput.html

-- ref
-- url: https://www.unix.com/man-page/osx/1/tput/

-- ref
-- url: https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux

-- ref
-- url: https://en.wikipedia.org/wiki/ANSI_escape_code



-- categories
-- Rust 

-- metadata
-- date: 2023-07-07 11:38:21
-- id: 2sfzu3u2
-- site: aws
-- type: post
-- status: scratch