charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
2.98k stars 50 forks source link

chore: better control over script usage #87

Open debdutdeb opened 3 months ago

debdutdeb commented 3 months ago

this is needed for when we want to write image to a pipe or socket and I can't just name it blabla.png.

this should fall back on using extension like before if format isn't specified.

treats the format also the same way it did before with extension. logic isn't touched.

what it adds -

  1. able to send output to stdout if not a tty (as already was), or by intention freeze main.go -o -
  2. specify format of the image when can't specify in destination, e.g. stdout writing
debdutdeb commented 3 months ago

since I touched some of the writing logic (logic is the same, unless I made a mistake), added respective tests to check behavior is consistent.

Only outlier is -o - change. That I mostly did to make it easy to test. I'm ok to remove that if it goes against charm's pr guidelines (mixing changes) which I may have missed.

edit: The pr name choice may have defeated me. I don't know a better name, suggestions are welcome

maaslalani commented 2 months ago

I'm perhaps leaning towards outputting the file contents if stdout is not a tty.

maaslalani commented 2 months ago

This could mean you could easily do stuff like:

freeze main.go | pbcopy