Michael Michael - 15 days ago 4
Ruby Question

Clear screen before any output to console

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?

Answer

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.