<commit_before>require "spinning_cursor/cursor"
require "spinning_cursor/parser"

module SpinningCursor
  extend self

  #
  # Sends passed block to Parser, and starts cursor thread
  # It will execute the action block and kill the cursor
  # thread if an action block is passed.
  #
  def start(&block)
    stop if @curs and @curs.alive?

    @parsed = Parser.new(block)
    @cursor = Cursor.new(@parsed.banner nil)
    @curs   = Thread.new { @cursor.spin(@parsed.type(nil), @parsed.delay(nil)) }
    @start  = @finish = @elapsed = nil

    if @parsed.action
    # The action
    begin
      do_exec_time do
        @parsed.originator.instance_eval &@parsed.action
      end
    rescue Exception => e
      set_message "#{e.message}\n#{e.backtrace.join("\n")}"
    ensure
      return stop
    end

    else
      # record start time
      do_exec_time
    end
  end

  #
  # Kills the cursor thread and prints the finished message
  # Returns execution time
  #
  def stop
    begin
      @curs.kill
      # Wait for the cursor to die -- can cause problems otherwise
      sleep(0.1) while @curs.alive?
      # Set cursor to nil so set_banner method only works
      # when cursor is actually running.
      @cursor = nil
      reset_line
      puts (@parsed.message nil)
      # Set parsed to nil so set_message method only works
      # when cursor is actually running.
      @parsed = nil

      # Return execution time
      get_exec_time
    rescue NameError
      raise CursorNotRunning.new "Can't stop, no cursor running."
    end
  end

  #
  # Determines whether the cursor thread is still running
  #
  def alive?
    if @curs
      @curs.alive?
    end
  end

  #<commit_msg>Add redundant code just for preparing for next commit<commit_after>require "spinning_cursor/cursor"
require "spinning_cursor/parser"

module SpinningCursor
  extend self

  #
  # Sends passed block to Parser, and starts cursor thread
  # It will execute the action block and kill the cursor
  # thread if an action block is passed.
  #
  def start(&block)
    stop if @curs and @curs.alive?

    @parsed = Parser.new(block)
    @cursor = Cursor.new(@parsed.banner nil)
    @curs   = Thread.new { @cursor.spin(@parsed.type(nil), @parsed.delay(nil)) }
    @start  = @finish = @elapsed = nil

    if @parsed.action
    # The action
    begin
      do_exec_time do
        @parsed.originator.instance_eval &@parsed.action
      end
    rescue Exception => e
      set_message "#{e.message}\n#{e.backtrace.join("\n")}"
    ensure
      return stop
    end

    else
      # record start time
      do_exec_time
    end
  end

  #
  # Kills the cursor thread and prints the finished message
  # Returns execution time
  #
  def stop
    begin
      @curs.kill
      # Wait for the cursor to die -- can cause problems otherwise
      sleep(0.1) while @curs.alive?
      # Set cursor to nil so set_banner method only works
      # when cursor is actually running.
      @cursor = nil
      reset_line
      puts (@parsed.message nil)
      # Set parsed to nil so set_message method only works
      # when cursor is actually running.
      @parsed = nil

      # Return execution time
      get_exec_time
    rescue NameError
      raise CursorNotRunning.new "Can't stop, no cursor running."
    end
  end

  #
  # Determines whether the cursor thread is still running
  #
  def alive?
    if @curs and @curs.alive?
      @curs.alive?
    end
  end

  #
{'fraction_non_alphanumeric': 0.07835712205068453, 'fraction_numerical': 0.0011651616661811825, 'mean_word_length': 2.4203187250996017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '774263', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1047, 'n_words': 360}