简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM