def text(x, y, text)
      Kernel.raise ArgumentError, 'missing text argument' if text.to_s.empty?
      if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
      # text already quoted
      elsif !text['\'']
        text = '\'' + text + '\''
      elsif !text['"']
        text = '"' + text + '"'
      elsif !(text['{'] || text['}'])
        text = '{' + text + '}'
      else
        # escape existing braces, surround with braces
        text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
      end
      primitive "text #{x},#{y} #{text}"
    end
def text(x, y, text)
      Kernel.raise ArgumentError, 'missing text argument' if text.to_s.empty?
      if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
      # text already quoted
      elsif !text['\'']
        text = '\'' + text + '\''
      elsif !text['"']
        text = '"' + text + '"'
      elsif !(text['{'] || text['}'])
        text = '{' + text + '}'
      else
        # escape existing braces, surround with braces
        text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
      end
      primitive "text #{x},#{y} #{text}"
    end
Draw text at position x,y. Add quotes to text that is not already quoted.