talis-fb / TReq

A CLI tool for effortless HTTP requests
GNU General Public License v3.0
55 stars 2 forks source link

Check if process is piped and exclude decoration of output. #37

Open talis-fb opened 8 months ago

talis-fb commented 8 months ago

When user execute TReq in a not TTY enviroment. Redirecting or piping output, like this...

treq url.com > file.txt # redirecting to
treq url.com | grep search-term

The TReq should check this and make the output the basic request output.

This check can be made by this function in Crossterm: https://docs.rs/crossterm/latest/crossterm/tty/trait.IsTty.html

Additional Considerations:

Use the same command options of using --body flag. Make the check of tty in beginning. If it's true, set like user pass the command with this flag. It is the same behavior.

It's also important does not ignore another flags like --header. So, this verification should be the last priority possible in all validation.