💾 Archived View for gemini.ctrl-c.club › ~de_alchmst › b-logs › ruby › ptts › 040:TUI.gmi captured on 2024-08-25 at 03:53:51. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-08-18)

-=-=-=-=-=-=-

TUI

I didn't touch ptts for some time now, mostly because I really didn't felt like messing with the instructions and pages again. Still recovering from the last part. I do still want ptts to be project I finish one day however, (this b-log is good motivation) so I decided to start working on some other part. Since there isn't that many parts and I don't feel like learning pdf right now, I decided to try the TUI.

So first, why not just pipe it into less? Well, I have plans for footnotes that will require my own interface. I also decided to not use ncurses, but make my own TUI with ANSI escape sequences. I don't know how well would ncurses work with escape sequences in text and it feels like a bit of a overkill for my needs. Rolling my own sounds like more fun anyways. I did use

term reader

to read input tho, so I guess no longer dependency-free.

What can my TUI do?

Ok, some of these I want to talk a bit more about

scroll

currently can scroll as far under text as you want, but I kinda like that. At least you can keep yor text centered even at the end and if you manage to scroll a bit too far, end will still bring you right at the end.

detecting if redirected

unless STDOUT.tty?
   Data.output_mode = :stdout
end

not messing up the terminal

So you know how when you close vim or man or mc or whatever, it just returnsr back to your terminal as if nothing happened? It does actually opens alternative terminal buffer (also didn't know terminals have this) and works here until closed. It's all done using escape sequences. This is also possibly why it vim does not do this in tty. (mc still does tho...)

# open new buffer (and go to top left corner)
print "\x1b[?1049h\x1b[H"

# go back to original buffer
print "\x1b[?1049l"

search

Searches are done in regex and can't span accross multiple lines. Your search always starts from beginning of file and they loop. I prefer this over normal search in less. you also don't see the results highlighted since I was lazy, but your cursor moves to the current word. I must once again express my appriciation for having regex built right into the language and not just as some (possibly third party) library. I still think globals and for loops would be nice tho.

Guess I'll have to do instructions next anyways so that's a thing...

----------------------------

previous: caught-up

next: more-instructions

b-logs

home

ctrl-c.club