<commit_before>class Painter
  require 'canvas'
  def initialize
    @canvas = Canvas.instance
    @brush = Brush.new('.', 0, 0)
    at_exit { canvas.close }
  end

  COMMAND_KEYS = [
    Canvas::KEY_UP,
    Canvas::KEY_DOWN,
    Canvas::KEY_LEFT,
    Canvas::KEY_RIGHT,
    9, # tab key character code
    27, # esc key character code
    'p'
  ]

  def paint
    canvas.paint(brush.x_pos, brush.y_pos, brush.stroke)
    loop do
      accept_input
    end
  end

  private

  attr_reader :canvas, :brush

  def accept_input
    char = canvas.accept_input
    if COMMAND_KEYS.include?(char)
      system_commands(char)
    else
      brush.stroke = char
    end
    if brush.lifted
      canvas.move(brush.x_pos, brush.y_pos)
    else<commit_msg>Split method into parts<commit_after>class Painter
  require 'canvas'
  def initialize
    @canvas = Canvas.instance
    @brush = Brush.new('.', 0, 0)
    at_exit { canvas.close }
  end

  COMMAND_KEYS = [
    Canvas::KEY_UP,
    Canvas::KEY_DOWN,
    Canvas::KEY_LEFT,
    Canvas::KEY_RIGHT,
    9, # tab key character code
    27, # esc key character code
    'p'
  ]

  def paint
    canvas.paint(brush.x_pos, brush.y_pos, brush.stroke)
    loop do
      follow_commands
    end
  end

  private

  attr_reader :canvas, :brush

  def follow_commands
    char = canvas.accept_input
    if COMMAND_KEYS.include?(char)
      system_commands(char)
    else
      brush.stroke = char
    end
    move_brush
  end

  def move_brush
    if brush.lifted
      canvas.move(brush.x_pos, brush.y_pos)
    else
{'fraction_non_alphanumeric': 0.09049773755656108, 'fraction_numerical': 0.006464124111182934, 'mean_word_length': 2.5261958997722096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7073267', 'n_tokens_mistral': 573, 'n_tokens_neox': 531, 'n_words': 128}