2010-07-03 15 views
34

Vorrei sapere a come fare in Ruby quello che posso fare con system("clear") in C. ho scritto un programma comeCome posso cancellare il terminale in Ruby?

puts "amit" 
system("clear") 

voglio la console da cancellare dopo l'esecuzione di questo commnad, ma è non funziona.

+1

Cosa operativi sono in esecuzione Ruby on? – Zabba

+0

SCiTE non è un compilatore, è solo un editor di testo. –

risposta

2

È possibile utilizzare seguente creare un file rubino dire check.rb come follwing

puts "amit" 
#system "clear" 

ed eseguirlo da console [Salil @ localhost Desktop] $ check.rb

o/p

[[email protected] Desktop]$ ruby check.rb 
amit 
[[email protected] Desktop]$ 

ora modificare check.rb ed eseguirlo da console

puts "amit" 
system "clear" 

o/p

[[email protected] Desktop]$ 
6

Una leggera variazione funziona:

puts "Here's a very long string" 
sleep 1 
system ("cls") 

Marco.

+4

Ovviamente funziona solo su Windows. –

+0

sistema "clear" è quello che vuoi per quelli su un terminale * nix –

1

Se si è su un Mac è possibile cancellare la finestra del terminale con "Command + K".

13

Prova uno di questi due nel file ruby:

puts `clear` 

o

puts "\e[H\e[2J" 
+3

Si prega di utilizzare il secondo qui. L'idea di forking un processo solo per cancellare lo schermo mi fa male la testa. Vedi qui per maggiori informazioni: http://www.termsys.demon.co.uk/vtansi.htm Inoltre, controlla ncurses per un controllo più robusto. Ma la possibilità che tu possa trovare un terminale non ansi in questi giorni è praticamente nulla. –

13

Edit:. (Rileggendo la tua domanda mi rendo conto che questo non è che cosa siete dopo ho pensato che tu fossi riferendosi all'IRB. Lascerò questo qui e non lo cancellerò come ritengo possa essere informazioni molto utili)


In definitiva dipende dal sistema in cui ci si trova.

Ctrl + l (< - che è un caso inferiore L) azzera il terminale ( cmd + K su un MAC Credo)

questo funziona anche nel regolare terminale, o l'interprete python, o mysql, ecc.

ci sono una discreta quantità di altre scorciatoie con cui potresti voler familiarizzare.ho trovato this dopo una breve ricerca su Google:

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 

non menzionato in tale elenco è che

Alt-F moves the curosor one word forward 
Alt- B moves the cursor one word back 
47

Se si desidera qualcosa che è vagamente portatile si può provare:

system "clear" or system "cls" 

che proverò sia clear e cls

0

Un approccio portatile, stata compromessa ma spesso visivamente appagante che uso è quello che io chiamo "folli Putz puts":

counter=0 
until counter == 50 
puts " " 
counter += 1 
end 
+3

Dipende da quanto è grande il buffer dello schermo di someones ed è tutt'altro che efficiente, ma in ogni caso si può anche fare 50.times {puts ""} in breve – Riptyde4

+3

'print" \ n "* 50' –

13

Ecco un modo multipiattaforma per farlo:

Gem.win_platform? ? (system "cls") : (system "clear") 
3

Se si utilizza Mac OS quindi utilizzare:

system('clear') 
1

per gli utenti Windows:

Basta digitare la seguente funzione nella finestra IRB e siete pronti per partire:

definiscono questa funzione:

def cls 
    system('cls') 
end 

Dopo aver definito chiamata di questa funzione in qualsiasi momento.

3

Questo dovrebbe coprire Windows e terminali OSX/Linux.

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

Opere su UNIX:

sistema
system("clear") 
Problemi correlati