<commit_before>module Ruco
  class Editor
    module Colors
      RECOLORING_TIMEOUT = 30 # seconds
      INSTANT_RECOLORING_RANGE = 1 # recolor x lines around the current one
      DEFAULT_THEME = 'spec/fixtures/test.tmTheme'

      def style_map
        map = super

        # add colors to style map
        colorize(map, styled_lines[@window.visible_lines])
        if @selection
          # add selection a second time so it stays on top
          @window.add_selection_styles(map, @selection)
        end<commit_msg>skip coloring if syntax parsing takes too long -- weird syntax or long file<commit_after>require 'timeout'

module Ruco
  class Editor
    module Colors
      RECOLORING_TIMEOUT = 30 # seconds
      INSTANT_RECOLORING_RANGE = 1 # recolor x lines around the current one
      DEFAULT_THEME = 'spec/fixtures/test.tmTheme'
      STYLING_TIMEOUT = 4

      def style_map
        map = super
        return map unless $ruco_colors

        # add colors to style map, disable colors if syntax-parsing takes too long
        begin
          styles = Timeout.timeout(STYLING_TIMEOUT) do
            styled_lines[@window.visible_lines]
          end
        rescue Timeout::Error
          # this takes too long, just go on without styles
          STDERR.puts "Styling takes too long, go on without me!"
          $ruco_colors = false
          return map
        end

        colorize(map, styles)

        if @selection
          # add selection a second time so it stays on top
          @window.add_selection_styles(map, @selection)
        end
{'fraction_non_alphanumeric': 0.05313700384122919, 'fraction_numerical': 0.004481434058898848, 'mean_word_length': 2.2427385892116183, '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': '2327978', 'n_tokens_mistral': 440, 'n_tokens_neox': 426, 'n_words': 149}