How Do You Clear The IRB Console?
On Mac OS X or Linux you can use Ctrl + L to clear the IRB screen.
Clear the terminal in rails server
In gnome terminal: Terminal -> Reset and Clear
.
I mapped it to CTRL+k.
⌘+K for OSX
Completely clear the console in RubyMine (or WebStorm or PhpStorm)
Right click and select Clear buffer
or just press Ctrl + K when the console is focused.
Deleting multiple lines of terminal output using ruby
Well, for simple things, if you can assume an ANSI-compatible terminal (usually a good bet), you can just directly output ANSI codes. For instance,
5.times do |item|
print "\r" + ("\e[A\e[K"*3) if item > 0
puts "#{item+1}\nHello!"
end
Where \r
moves the cursor to the start of the line, \e[A
moves the cursor up one line, and \e[K
clears from the cursor position to the end of the line. If you don't need anything further down the screen, you can also just send \e[J
once you have the cursor where you want; that clears all the way to the end of the screen.
For more sophisticated stuff, you could start by taking a look at the Highline gem.
Clear screen before any output to console
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.
Related Topics
How to Deal With the Sum of Rounded Percentage Not Being 100
Best Practices to Handle Routes For Sti Subclasses in Rails
Undefined Method 'Visit' When Using Rspec and Capybara in Rails
Parallel Assignment Operator in Ruby
How to Install MySQL2 Gem on Windows 7
How to Use Gem to Install Rails on Ubuntu
Gemfile.Lock Write Error, Permissions
Rescue in Rbuf_Fill': Timeout::Error (Timeout::Error)
Rails - Best-Practice: How to Create Dependent Has_One Relations
Nested Models and Parent Validation
How to Change the Default Path of View Files in a Rails 3 Controller
Really Cheap Command-Line Option Parsing in Ruby
Devise Custom Routes and Login Pages
Long Running Delayed_Job Jobs Stay Locked After a Restart on Heroku
Set Utf-8 as Default String Encoding in Heroku
Ruby 1.9.2 and Rails 3 Cannot Open Rails Console
Rails 2 to Rails 3:Using Link_To Instead of Link_To_Remote (Including Remote and Update)