lemnos / tt

A terminal based typing test.
MIT License
747 stars 49 forks source link

[Feature Request] Add support for code snippets #11

Open leandwo opened 3 years ago

leandwo commented 3 years ago

I'd to practice typing code as well. Not sure how easy this would be to add though...

lemnos commented 3 years ago

I'm not sure a dedicated feature for this makes sense. What do you imagine the implementation would like? It is already possible to use tt with code (or indeed any arbitrary text). For code you would probably want to use the -raw flag and feed in small chunks at a time. E.G head -n 20 code.c|tt -noskip -raw. It shouldn't be too hard to write a small script to chunk the file automatically. tt is designed to be composable like most other unix tools.

rustyedge commented 1 year ago

@lemnos I am using tt for code as you described above. Works great. The only problem is that TAB inserts nothing and I have to press SPACE way too many times. Is there a way to have TAB insert 4 spaces?

jmonroynieto commented 1 year ago

I agree with this. I forked this, and it is working. Raw mode now captures tabs, but they are rendered as spaces. https://github.com/jmonroynieto/tt_withTab/commit/e080d33a9cb72e625cda9857f3e20d6a7ee3cae9

//TODO: render as multiple characters such as ›··, ▸··, or ⍿··. Possibly accomplished by special handling of redraw. Now that typer.go::Start() knows about raw mode, this could be accomplished. //TODO: Handle the cursor correctly when masking tabs in raw mode. //TODO: Create a special instance of reflow for raw mode where four spaces make a tab character. tt.go@L404

I'll put in a PR when it is complete. Anyone interested in push access, let me know.

jmonroynieto commented 1 year ago

Also, for those interested, I wrote a simple tool to capture quote/code snippets interactively. See quoteadder.

Would the owners be willing to merge this as a command to tt?

jmonroynieto commented 1 year ago

The suggested solution only changes 4 spaces to tabs, other amounts are unchanged. This is a bit bothersome for go code that has been formatted since some instances like struct definition can have odd spacing to make it visually clean.

Making it "squish" sequential spaces after changing groups of 4 to tabs would be trivial and perhaps more useful, let me know.