I use HighLine gem for UI. I want to clear the screen before output any data. Which method should I use? Patch some Ruby methods like puts? Patch HighLine? Change my app in some way? At the moment it has Dialog class with various methods which call HighLine functions for interacting with user. Or maybe HighLine has a built-in method to do that?
Asked
Active
Viewed 286 times
0
-
`puts "\e[2J"`. – Aleksei Matiushkin Nov 23 '16 at 09:36
-
My question is not about clear-screen method itself. It is about where should I put this code and how to do it right way. But thanks for the hint. – Michael Nov 23 '16 at 10:58
-
“where should I put this code”—where you need the screen to be cleared. – Aleksei Matiushkin Nov 23 '16 at 11:02
-
It should be cleared before any output as I said. – Michael Nov 23 '16 at 11:20
-
1Really? `puts 'Q.: Please enter a number'; puts '>'` ⇐ do you really want the screen to be cleared _twice_ (one in between of puts?) Any output is chunked, according to some business rules, and you are the only person who understands these business rules. – Aleksei Matiushkin Nov 23 '16 at 11:46
1 Answers
1
Well, the requirements are not clear and I won’t recommend this way, but the stated problem might be solved with:
$stdout.singleton_class.prepend(Module.new do
def write(string)
super("\e[2J" << string)
end
end)
I think, this answer is not suitable for the OP, but it perfectly answers the exact question asked.
Aleksei Matiushkin
- 119,336
- 10
- 100
- 160
-
Yes, you are quite right. It is exactly what I ask for and it is not what I want absolutely. I should manually clear screen in right places of **my app** according to business logic. – Michael Nov 23 '16 at 16:47