max-niederman / ttyper

Terminal-based typing test.
MIT License
1.06k stars 78 forks source link

Feature Request: Pipe text into ttyper #74

Closed brian6932 closed 1 year ago

brian6932 commented 1 year ago

Would be nice if you could pipe text directly into ttyper, as opposed to having to make it a file first, could allow for some cool mixups, like requesting a random quote, and then typing that out through ttyper.

Example:

curl -sSL https://api.quotable.io/random | jq -r .content | ttyper

Side note, currently text doesn't seem to wrap to term size properly, that should be fixed before this would be added ofc image image

adrianncovaci commented 1 year ago

Is this available?

max-niederman commented 1 year ago

This is already supported. You just need to set the input file to /dev/stdin:

curl -sSL https://api.quotable.io/random | jq -r .content | ttyper /dev/stdin

Or, alternatively, you can use process substitution:

ttyper <(curl -sSL https://api.quotable.io/random | jq -r .content)

The reason the text isn't wrapping correctly is because ttyper splits files into "words" at newlines, not spaces and other whitespace. This is for a few reasons:

As an example of the second point, you can make the text wrap correctly (most of the time) by also piping through tr to replace spaces with newlines:

ttyper <(curl -sSL https://api.quotable.io/random | jq -r .content | tr " " "\n")
brian6932 commented 1 year ago

/dev/stdin is not a thing on Windows, this is not a natively supported feature, that is an OS feature, not a crossplatform feature