<commit_before>module Twterm
  module Tab
    module Base
      include Curses

      attr_accessor :title

      def initialize
        @window = stdscr.subwin(stdscr.maxy - 5, stdscr.maxx - 30, 3, 0)
      end

      def refresh
        return if @refreshing || closed? || TabManager.instance.current_tab.object_id != object_id

        @refreshing = true
        Thread.new do
          update
          @refreshing = false
        end
      end

      def close
        @window.close
      end

      def respond_to_key(_)
        fail NotImplementedError, 'respond_to_key method must be implemented'
      end

      def ==(other)
        self.equal?(other)
      end

      private

      def update
        fail NotImplementedError, 'update method must be implemented'
      end
    end
  end
end<commit_msg>Refactor Tab::Base<commit_after>module Twterm
  module Tab
    module Base
      include Curses

      attr_accessor :title

      def ==(other)
        self.equal?(other)
      end

      def close
        @window.close
      end

      def initialize
        @window = stdscr.subwin(stdscr.maxy - 5, stdscr.maxx - 30, 3, 0)
      end

      def refresh
        return unless refreshable?

        Thread.new do
          refresh_mutex.synchronize { update }
        end
      end

      def respond_to_key(_)
        fail NotImplementedError, 'respond_to_key method must be implemented'
      end

      private

      def refresh_mutex
        @refresh_mutex ||= Mutex.new
      end

      def refreshable?
        !(
          refresh_mutex.locked? ||
            closed? ||
            TabManager.instance.current_tab.object_id != object_id
        )
      end

      def update
        fail NotImplementedError, 'update method must be implemented'
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.062360801781737196, 'fraction_numerical': 0.005567928730512249, 'mean_word_length': 1.7227272727272727, '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': '5404313', 'n_tokens_mistral': 535, 'n_tokens_neox': 506, 'n_words': 144}