class Reline::KeyStroke

def expand(input)

def expand(input)
  matched_bytes = nil
  (1..input.size).each do |i|
    bytes = input.take(i)
    status = match_status(bytes)
    matched_bytes = bytes if status == MATCHED || status == MATCHING_MATCHED
    break if status == MATCHED || status == UNMATCHED
  end
  return [[], []] unless matched_bytes
  func = key_mapping.get(matched_bytes)
  s = matched_bytes.pack('c*').force_encoding(@encoding)
  if func.is_a?(Array)
    # Perform simple macro expansion for single byte key bindings.
    # Multibyte key bindings and recursive macro expansion are not supported yet.
    macro = func.pack('c*').force_encoding(@encoding)
    keys = macro.chars.map do |c|
      f = key_mapping.get(c.bytes)
      Reline::Key.new(c, f.is_a?(Symbol) ? f : :ed_insert, false)
    end
  elsif func
    keys = [Reline::Key.new(s, func, false)]
  else
    if s.valid_encoding? && s.size == 1
      keys = [Reline::Key.new(s, :ed_insert, false)]
    else
      keys = []
    end
  end
  [keys, input.drop(matched_bytes.size)]
end