use RL_PROMPT_ constants for places where a prompt is colorized (only)

git-svn-id: file:///home/svn/framework3/trunk@9039 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2010-04-07 23:37:49 +00:00
parent a502c2647d
commit 9a8d14a5ec
3 changed files with 27 additions and 22 deletions

View File

@ -45,30 +45,35 @@ module Color
# #
# Colorize if this shell supports it # Colorize if this shell supports it
# #
def colorize(*color) def colorize(*color)
supports_color?() ? ansi(*color) : '' supports_color?() ? ansi(*color) : ''
end end
def substitute_colors(msg) def substitute_colors(msg, in_prompt = nil)
str = msg.dup str = msg.dup
str.gsub!(/%cya/, colorize('cyan')) pre_color = post_color = ''
str.gsub!(/%red/, colorize('red')) if (in_prompt)
str.gsub!(/%grn/, colorize('green')) pre_color = "\x01" # RL_PROMPT_START_IGNORE
str.gsub!(/%blu/, colorize('blue')) post_color = "\x02" # RL_PROMPT_END_IGNORE
str.gsub!(/%yel/, colorize('yellow')) end
str.gsub!(/%whi/, colorize('white')) str.gsub!(/%cya/, pre_color+colorize('cyan')+post_color)
str.gsub!(/%mag/, colorize('magenta')) str.gsub!(/%red/, pre_color+colorize('red')+post_color)
str.gsub!(/%blk/, colorize('black')) str.gsub!(/%grn/, pre_color+colorize('green')+post_color)
str.gsub!(/%dred/, colorize('dark', 'red')) str.gsub!(/%blu/, pre_color+colorize('blue')+post_color)
str.gsub!(/%dgrn/, colorize('dark', 'green')) str.gsub!(/%yel/, pre_color+colorize('yellow')+post_color)
str.gsub!(/%dblu/, colorize('dark', 'blue')) str.gsub!(/%whi/, pre_color+colorize('white')+post_color)
str.gsub!(/%dyel/, colorize('dark', 'yellow')) str.gsub!(/%mag/, pre_color+colorize('magenta')+post_color)
str.gsub!(/%dcya/, colorize('dark', 'cyan')) str.gsub!(/%blk/, pre_color+colorize('black')+post_color)
str.gsub!(/%dwhi/, colorize('dark', 'white')) str.gsub!(/%dred/, pre_color+colorize('dark', 'red')+post_color)
str.gsub!(/%dmag/, colorize('dark', 'magenta')) str.gsub!(/%dgrn/, pre_color+colorize('dark', 'green')+post_color)
str.gsub!(/%und/, colorize('underline')) str.gsub!(/%dblu/, pre_color+colorize('dark', 'blue')+post_color)
str.gsub!(/%bld/, colorize('bold')) str.gsub!(/%dyel/, pre_color+colorize('dark', 'yellow')+post_color)
str.gsub!(/%clr/, colorize('clear')) str.gsub!(/%dcya/, pre_color+colorize('dark', 'cyan')+post_color)
str.gsub!(/%dwhi/, pre_color+colorize('dark', 'white')+post_color)
str.gsub!(/%dmag/, pre_color+colorize('dark', 'magenta')+post_color)
str.gsub!(/%und/, pre_color+colorize('underline')+post_color)
str.gsub!(/%bld/, pre_color+colorize('bold')+post_color)
str.gsub!(/%clr/, pre_color+colorize('clear')+post_color)
str str
end end

View File

@ -101,7 +101,7 @@ class Input
end end
def update_prompt(prompt) def update_prompt(prompt)
substitute_colors(prompt) substitute_colors(prompt, true)
end end
def reset_color def reset_color

View File

@ -42,7 +42,7 @@ class Output < Rex::Ui::Output
def update_prompt(prompt = nil) def update_prompt(prompt = nil)
return if prompt.nil? return if prompt.nil?
substitute_colors(prompt) substitute_colors(prompt, true)
end end
def print_error(msg = '') def print_error(msg = '')