How can I clear the terminal in Ruby?

前端 未结 15 1671
心在旅途
心在旅途 2020-11-30 06:14

I would like to know to how to do in Ruby what I can do with system(\"clear\") in C. I wrote a program like

puts \"amit\"
system(\"clear\")


        
相关标签:
15条回答
  • 2020-11-30 07:09

    If you use Pry, It's very simple Just .clear

    0 讨论(0)
  • 2020-11-30 07:10

    This should cover windows and OSX/Linux terminals.

    def method_name
       puts "amit"
       if RUBY_PLATFORM =~ /win32|win64|\.NET|windows|cygwin|mingw32/i
          system('cls')
        else
          system('clear')
       end
    end
    method_name
    
    0 讨论(0)
  • 2020-11-30 07:11

    Edit: (rereading your question I realize this is not what you are after. I thought you were referring to the IRB. I will leave this here and not delete it as I feel it is can be very useful information)


    Ultimately it depends what system you are on.

    ctrl+l (<- that is a lower case L) will clear the terminal ( cmd+K on a mac I believe)

    this also works in the regular terminal, or the python interprator, or mysql, etc

    there are a fair amount of other shortcuts you may like to familiarize yourself with. i found this after a quick google search:

    CTRL-l - Clears the screen and places the command prompt at the top of the page.
    CTRL-r - Starts a search against the command history. Start by typing in what you want to search by then press CTRL-r to see the matches.
    CTRL-c - Kills the current running foreground program.
    CTRL-z - Stop/sleep the current running foreground program.
    CTRL-s - Stops the output to the screen.
    CTRL-q - Allows output to the screen.
    CTRL-a - Moves the cursor the start of the line
    CTRL-e - Moves the cursor to the end of the line
    CTRL-f - Moves the cursor 1 character forward
    CTRL-b - Moves the cursor 1 character backward
    

    not mentioned on that list is that

    Alt-F moves the curosor one word forward
    Alt- B moves the cursor one word back
    
    0 讨论(0)
提交回复
热议问题