Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Quick Ansi Library
Index -> Programming, Ruby -> Ruby Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DtY




PostPosted: Sun May 24, 2009 7:33 pm   Post subject: Quick Ansi Library

Ruby:
#!/usr/bin/ruby

def ansi_clear
    #Clears the screen, and moves cursor to top left
    printf "\e[2J"
    ansi_locate 1, 1
end

def ansi_locate(row,col)
    #Moves to cursor to specified row and column
    printf "\e[%d;%dH", row, col
end

def ansi_hidecursor(h=true)
    #Hides cursor if h, or else shows it again
    if h
        printf "\e[?25l"
    else
        printf "\e[?25h"
    end
end

def ansi_setmode(modes)
    #Sets dispaly modes. Modes is a string of ; seperated modes.
    #List of modes over here: https://secure.wikimedia.org/wikipedia/en/wiki/ANSI_escape_code#Codes
    printf "\e[%sm", modes
end


Save file as ansi.rb somewhere in your ruby path, then require 'ansi' to use it.
You can do whatever you want with this. I really don't care, didn't take very long. Go ahead and use it without crediting me.

[edit] Screenshots:
ansi_locate:
Posted Image, might have been reduced in size. Click Image to view fullscreen.
ansi_setmode:
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: