Browse | Submit A New Snippet | Create A Package

 

Ruby text editor

Type:
Class
Category:
Other
License:
GNU General Public License
Language:
Ruby
 
Description:
Ruby Editor Program, a basic CLI text editor

Versions Of This Snippet::

icaro glauco
Snippet ID Download Version Date Posted Author Delete
6030.5.1.1x BETA2010-11-21 04:52icaro glauco
Changes since last version::
We made the following changes:
functions were improved, they were attributed to a better visual program and the code has been modified to form dynamic and efficient, and may have bugs in linux
5890.5.12010-03-15 06:26Michael Lenox
Changes since last version::
Mostly Aligned the comments, and code cleanup
5690.5.02010-01-13 10:52Michael Lenox
Changes since last version::
Using "system("clear") or system("cls")" to clear screen on Windows and Linux! No more flooding the screen with newlines.

5680.4.02010-01-12 06:09Michael Lenox
Changes since last version::
New Close function that closes the program
5650.3.12010-01-11 23:57Michael Lenox
Changes since last version::
Fixed problems with Rename and Delete functions. File to be Renamed-Deleted was not closed before "File.delete called.
5640.3.02010-01-11 02:46Michael Lenox
Changes since last version::
Rename and delete functions have been added! Some cleanup of the comments were done.
5620.2.12010-01-10 23:20Michael Lenox
Changes since last version::
Edited and fixed spelling errors in comments
5610.2.02010-01-10 22:31Michael Lenox
Changes since last version::
Edit function added. Also the program self restarts
5600.1.12010-01-10 11:19Michael Lenox
Changes since last version::
Added "file1.close" after file write and added coments
5590.1.02010-01-10 11:06Michael Lenox

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :0.5.1.1x BETA

require 'fileutils'
def ren c,v
    system("rename #{c} #{v}") or system("mv #{c} #{v}")
end
def rm b
    system("rm #{b}") or system("del #{b}")
    end
def exit
    system("exit")
end
mdSave = Proc.new do
system("md .Saves") or system("mkdir .Saves")
end
mdSave.call
 def cls
  system("clear") or system("cls")
end
  cls
  init=Proc.new do
  puts"                    |#####################################################|"
  puts"                    |########## Welcome to Ruby Editor! 5.2 ##############|"  
  puts"                    |#####################################################|"
  sleep 5
  edit
  end
def edit
    
  cls
  puts"|======================|".center (50)
  puts"|        #Main#        |".center (50)
  puts"|        [R]ead        |".center (50)
  puts"|        [W]rite       |".center (50)
  puts"|        Re[n]ame      |".center (50)
  puts"|        [D]elete      |".center (50)
  puts"|        [E]dit        |".center (50)
  puts"|  [C]lose the program |".center (50)
  puts"|======================|".center (50)
  print">>".center (20)
   answer = gets.chomp
while (answer.capitalize != 'C') 


 if answer == "r"   
  cls
  print"Enter file to read. "
   answer1 = gets.chomp  
 while (File.exist?(answer1) != true)
puts 'Please, write a valid file to read'
answer1=gets.chomp
end 
  file = File.open("#{answer1}", "r+")  
   read = file.readlines 
  cls                                                                                                                  
 puts read  
 file.close   
gets.chomp
 puts"\n" 
print"Press 'enter' to restart! "
 gets.chomp                                 
edit
elsif answer == "w"                                                                               
 cls
 puts "The archive will be saved in the folder .Saves , in the directory"
system("pwd")
sleep 3
puts "If so you want change the father directory, begin writing the drive"
sleep 3                                                                                                   
 puts"please, before write the archive put a name in the archive"
    puts "Save as?"
   save = gets.chomp      
cls                                                                    
    file1 = FileUtils.touch".Saves/#{save}" 
  file1 = File.new(".Saves/#{save}", "r+")                                                                                    
 print"In seconds you can write the archive #{save} , please type below, then press _END and enter.\n " 
 sleep 5
 cls
 y=''
 while y != "_END"
file1.puts "#{y=gets.chomp}"

end
   cls
  file1.close                                                                                                        
print"File #{save} saved, press 'enter' to restart! "
gets.chomp                                                                                               
edit                                                                                                            

elsif answer == "n"                     
   cls
   puts"Enter file to rename. "
   ren1=gets.chomp
   print"Now, the name to change\n       >>"
   ren2 = gets.chomp                                            
   ren ren1,ren2 
   cls
   print"File renamed, press enter to restart "
   answer = gets.chomp                                                                                         
edit                                                                                                           
 elsif answer == "d"                                                                                            
  cls
   print"Enter file to delete "
   del=''
     while (File.exist?(del) != true)
    del = gets.chomp    
end    
    rm del
cls
    print"'#{del} '"  "deleted, press enter to restart "
 gets.chomp                                                                                         
edit                                                                                                           
elsif answer == "e"                                                                                          
 cls
 print"Enter file to Edit. " 
 edit=''
  while (File.exist?(edit) != true) do
  edit = gets.chomp 
  end
  file4 = File.open("#{edit}", "r+")                                                                         
  cls
  file4.readlines  
  file4 = File.new("#{edit}", "r+")   
  puts"Edit file, then press _END and enter to save "
  y=''
 while y != "_END" do
  file4.puts "#{y=gets.chomp}"                                                                                 
end
  file4.close                                                                                                 
  cls
print"File saved, press 'enter' to restart! "
answer='' 
gets.chomp
edit                                                                                                        
elsif answer == "c" 
 cls
  print"Closing Ruby Editor..."
 sleep 3
 cls
 
 else
   print"Please enter a correct letter...\n    >> "
  sleep 3
    cls
  puts"|======================|".center (50)
  puts"|        #Main#        |".center (50)
  puts"|        [R]ead        |".center (50)
  puts"|        [W]rite       |".center (50)
  puts"|        Re[n]ame      |".center (50)
  puts"|        [D]elete      |".center (50)
  puts"|        [E]dit        |".center (50)
  puts"|  [C]lose the program |".center (50)
  puts"|======================|".center (50)
  print">>".center (20)
   answer = gets.chomp

  gets.chomp
edit
       end                                                                                                             
     end
 end
init.call
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..