class Object

Public Instance Methods

ask_program() click to toggle source
# File bin/mancurses, line 759
def ask_program
  p = @form.by_name["textpad"]; 
  prog = get_string("Program to man:")
  p.padrefresh
  return unless prog
  return if prog == ""
  file = `man #{prog} 2>&1`
  return unless file
  text = convert_man_to_ansi(file)
  p.formatted_text(text, :ansi)
  p.goto_start
end
convert_man_to_ansi(file) click to toggle source

Since we already have an ansi sequence parser, why not convert to that and use that.

man pages have some kind of sucky format probably related to sme ancient hardware. I notice two patterns:

  1. a character is followed by a ^H and then the same character repeated. Such a char is to be printed in one color. Oh it get it, LOL, ^H is a backspace so basically the printer is giogn back and printing that char again. So its printed two times, aka bold.

  2. The second is an underline folowed by BS and then any character, this goes in another

color and is obviously meant to be underlined text. NOW it get it, bird-brained me!

# File bin/mancurses, line 740
def convert_man_to_ansi file
  lines = file.split "\n"
  l = nil
  lines.each_with_index do |line, ix|
    # convert underlined words to yellow or one color, these are usually params
    line.gsub!(/((_[^ ])+)/,'\1')
    line.gsub!(/_/,'')
    # convert bold words to red or one color, these are usually headers and other words
    l= line.gsub(/(([^ ][^ ])+)/,'\1').gsub(/[^ ]/,'').gsub(//,'')
   # ==
    #line.gsub!(/((_[^ ])+)/,'_\1_')
    #line.gsub!(/_/,'')
    ### convert bold words to red or one color, these are usually headers and other words
    #l= line.gsub(/(([^ ][^ ])+)/,'*\1*').gsub(/[^ ]/,'').gsub(//,'')
   # ==
    lines[ix] = l
  end
  lines
end