fancyline
fancyline copied to clipboard
Alternative screen use
Hi,
This would be helpful to me so I tried implementing it, seems to work (I'm using iTerm2 and tried it with Terminal too). I put an example into the final sample, not sure if it's the right place or whether it would need some extra comments or a bit in the readme… Let me know your thoughts.
Regards, iain
Now that's a cool feature I didn't know about!
I only learnt about it yesterday from reading this code. Seemed like a nice thing to try as I'm trying to wangle Fancyline into running a TUI. The codes are listed in this helpful gist with some others that may come in handy.
I think a yielding method would be good, ala Tty#in_alternate_screen. The method then calls the switch_to method, yields, and upon return switches back again in an rescue-else block.
I woke up and found myself thinking the same (great minds:). Not sure what I'd be rescuing though as I think most terminals (from my research yesterday) will support this or have a setting to ignore. I'm going to track down a test that's better than me manually checking.
Something like this?
def in_alternate_screen(&block)
switch_to_alternate_screen
rescue # something
else
yield
ensure
switch_from_alternate_screen
end
I tried it (also with the switch back in the rescue) but they both failed to switch back. An ensure works:
def in_alternate_screen(&block)
switch_to_alternate_screen
yield
ensure
switch_from_alternate_screen
end
Let me know if this is along the lines you were thinking.
I also wonder about adding a convenience wrapper in Fancyline to hide the tty part from the consumer. I'm not sure they should care that the tty is handling the screens, e.g.
fancy.tty.in_alternate_screen do
could become
fancy.in_alternate_screen do
It's not much but keeping the consumer of the library at the top level of the API is nice. Just an idea.
An ensure works
Ah sorry, that's what I meant 👍 in the gist you linked it says
Note: While these modes may be supported by the most terminals, some may not work in multiplexers like tmux.
Could you check what happens in screen and tmux? Do they notify us that the operation failed somehow?
tmux is a big one for me, I don't use a terminal without it. @yb66 let me know if I can assist you somehow.
Also, I added a CI style check, to give you some feedback if the coding style is inconsistent. A crystal tool format
commit hook is probably the way to go.
Sorry to leave this hanging, had an urgent matter come up and was constantly thinking “tomorrow, tomorrow...” but tomorrow never arrived!
I’ve some free time coming up so I’ll get to this asap.
Regards, iain
Hey, don't worry about it, you'll get to it when you get to it 😄 I'm just happy people wanna help out!