class Reline::ANSI

def self.getc_with_bracketed_paste

def self.getc_with_bracketed_paste
  buffer = String.new(encoding: Encoding::ASCII_8BIT)
  buffer << inner_getc
  while START_BRACKETED_PASTE.start_with?(buffer) or END_BRACKETED_PASTE.start_with?(buffer) do
    if START_BRACKETED_PASTE == buffer
      @@in_bracketed_paste_mode = true
      return inner_getc
    elsif END_BRACKETED_PASTE == buffer
      @@in_bracketed_paste_mode = false
      ungetc(-1)
      return inner_getc
    end
    begin
      succ_c = nil
      Timeout.timeout(Reline.core.config.keyseq_timeout * 100) {
        succ_c = inner_getc
      }
    rescue Timeout::Error
      break
    else
      buffer << succ_c
    end
  end
  buffer.bytes.reverse_each do |ch|
    ungetc ch
  end
  inner_getc
end