def key_tos ch # -- {{{
        x = $key_cache[ch]
        return x if x
        chr = case ch
              when 10,13 , KEY_ENTER
                "<CR>"
              when 9 
                "<TAB>"
              when 0 
                "<C-@>"
              when 27
                "<ESC>"
              when 31
                "<C-/>"
              when 1..30
                x= ch + 96
                "<C-#{x.chr}>"
              when 32 
                "<SPACE>"
              when 41
                "<M-CR>"
              when 33..126
                ch.chr
              when 127,263 
                "<BACKSPACE>"
              when 128..154
                x = ch - 128
                #"<M-C-#{x.chr}>"
                xx = key_tos(x).gsub(/[<>]/,"")
                "<M-#{xx}>"
              when 160..255
                x = ch - 128
                xx = key_tos(x).gsub(/[<>]/,"")
                "<M-#{xx}>"
              when 255
                "<M-BACKSPACE>"
              when 2727
                "<ESC-ESC>"
              else

                chs =  FFI::NCurses::keyname(ch) 
                # remove those ugly brackets around function keys
                if chs && chs[-1]==')'
                  chs = chs.gsub(/[()]/,'')
                end
                if chs
                  chs = chs.gsub("KEY_","")
                  "<#{chs}>"
                else
                  "UNKNOWN:#{ch}"
                end
              end
        $key_cache[ch] = chr
        return chr
      end
def key_tos ch # -- {{{
        x = $key_cache[ch]
        return x if x
        chr = case ch
              when 10,13 , KEY_ENTER
                "<CR>"
              when 9 
                "<TAB>"
              when 0 
                "<C-@>"
              when 27
                "<ESC>"
              when 31
                "<C-/>"
              when 1..30
                x= ch + 96
                "<C-#{x.chr}>"
              when 32 
                "<SPACE>"
              when 41
                "<M-CR>"
              when 33..126
                ch.chr
              when 127,263 
                "<BACKSPACE>"
              when 128..154
                x = ch - 128
                #"<M-C-#{x.chr}>"
                xx = key_tos(x).gsub(/[<>]/,"")
                "<M-#{xx}>"
              when 160..255
                x = ch - 128
                xx = key_tos(x).gsub(/[<>]/,"")
                "<M-#{xx}>"
              when 255
                "<M-BACKSPACE>"
              when 2727
                "<ESC-ESC>"
              else

                chs =  FFI::NCurses::keyname(ch) 
                # remove those ugly brackets around function keys
                if chs && chs[-1]==')'
                  chs = chs.gsub(/[()]/,'')
                end
                if chs
                  chs = chs.gsub("KEY_","")
                  "<#{chs}>"
                else
                  "UNKNOWN:#{ch}"
                end
              end
        $key_cache[ch] = chr
        return chr
      end
returns a string representation of a given int keycode
 @param [Integer] keycode read by window
    In some case, such as Meta/Alt codes, the window reads two ints, but still we are using the param
    as the value returned by ?\M-a.getbyte(0) and such, which is typically 128 + key
 @return [String] a string representation which is what is to be used when binding a key to an
     action or Proc. This is close to what vimrc recognizes such as <CR> <C-a> a-zA-z0-9 <SPACE>
     Hopefully it should be identical to what vim recognizes in the map command.
     If the key is not known to this program it returns "UNKNOWN:key" which means this program
     needs to take care of that combination. FIXME some numbers are missing in between.
 NOTE do we really need to cache everything ? Only the computed ones should be cached ?