2013-04-28 49 views
0

我正在Linux(和konsole,如果这使得sifference),并希望对屏幕有一些基本的控制。我需要的是简单的,并不需要ncurses的全部力量,我真的需要三个简单的命令,“清除屏幕”,“去x和y”和“使用这种颜色”。红宝石终端输出没有诅咒?

任何人都可以提出建议吗?

+1

什么问题ncurses的?对于您正在查找的这三个命令而言,这非常明智 – 2013-04-28 18:40:20

回答

2

要控制屏幕,您需要发送(或打印)ANSI控制序列。 要清除屏幕序列是\e[2J,您可以根据您的需要,只需putsprintSTDOUT

一些实例方法在Ruby中:

def clear_screen 
    print "\e[2J" 
end 

def clear_line 
    print "\e[2K" 
end 

def reset_cursor 
    print "\e[H" 
end 

def position_cursor(y,x) 
    print "\e[#{y};#{x}H" 
end 

def red 
    print "\e[0;31m" 
end 

序列的表是在这里: http://ascii-table.com/ansi-escape-sequences.php

你可以看到颜色序列表中的位置: http://www.pixelbeat.org/docs/terminal_colours/

+0

另一个有用的博客文章让您开始: http://trainofthought.segfault.gr/2011/11/29/ruby-terminal-manipulation-without-ncurses/ – 2013-08-28 04:26:56