<commit_before>require 'twterm/event/screen/refresh'
require 'twterm/event/screen/resize'
require 'twterm/key_mapper'
require 'twterm/subscriber'

module Twterm
  class Screen
    include Subscriber

    def initialize(app, client)
      @app, @client = app, client

      @screen = Curses.init_screen
      Curses.noecho
      Curses.raw
      Curses.curs_set(0)
      Curses.stdscr.keypad(true)
      Curses.start_color
      Curses.use_default_colors
      Curses.mousemask(Curses::BUTTON1_CLICKED)

      subscribe(Event::Screen::Refresh) { refresh }
      subscribe(Event::Screen::Resize, :resize)
    end

    def respond_to_key(key)
      k = KeyMapper.instance

      case key
      when k[:status, :compose]
        app.tweetbox.compose
        return
      when k[:app, :quit], 3
        app.quit
      when k[:app, :cheatsheet]
        tab = Tab::KeyAssignmentsCheatsheet.new(app, client)
        app.tab_manager.add_and_show tab
      else
        return false
      end

      true
    end

    def wait
      @thread = Thread.new do
        loop { scan }
      end
      @thread.join
    end

    private

    attr_reader :app, :client

    # @param [Integer, String] key
    def handle_keyboard_event(key)
      return if app.tab_manager.current_tab.respond_to_key(key)
      return if app.tab_manager.respond_to_key(key)
      respond_to_key(key)
    end

    # @param [Curses::MouseEvent] e
    def handle_mouse_event(e)
      x = e.x
      y = e.y

      case e.bstate
      when Curses::BUTTON1_CLICKED
        return app.tab_manager.handle_left_click(x, y) if app.tab_manager.enclose?(x, y)
      end
    end<commit_msg>Enable to explore tabs by mouse scrolling<commit_after>require 'twterm/event/screen/refresh'
require 'twterm/event/screen/resize'
require 'twterm/key_mapper'
require 'twterm/subscriber'

module Twterm
  class Screen
    include Subscriber

    def initialize(app, client)
      @app, @client = app, client

      @screen = Curses.init_screen
      Curses.noecho
      Curses.raw
      Curses.curs_set(0)
      Curses.stdscr.keypad(true)
      Curses.start_color
      Curses.use_default_colors
      Curses.mousemask(Curses::BUTTON1_CLICKED | 65536 | 2097152)

      subscribe(Event::Screen::Refresh) { refresh }
      subscribe(Event::Screen::Resize, :resize)
    end

    def respond_to_key(key)
      k = KeyMapper.instance

      case key
      when k[:status, :compose]
        app.tweetbox.compose
        return
      when k[:app, :quit], 3
        app.quit
      when k[:app, :cheatsheet]
        tab = Tab::KeyAssignmentsCheatsheet.new(app, client)
        app.tab_manager.add_and_show tab
      else
        return false
      end

      true
    end

    def wait
      @thread = Thread.new do
        loop { scan }
      end
      @thread.join
    end

    private

    attr_reader :app, :client

    # @param [Integer, String] key
    def handle_keyboard_event(key)
      return if app.tab_manager.current_tab.respond_to_key(key)
      return if app.tab_manager.respond_to_key(key)
      respond_to_key(key)
    end

    # @param [Curses::MouseEvent] e
    def handle_mouse_event(e)
      x = e.x
      y = e.y

      case e.bstate
      when Curses::BUTTON1_CLICKED
        return app.tab_manager.handle_left_click(x, y) if app.tab_manager.enclose?(x, y)
      when 65536
        scroll_direction = app.preferences[:control, :scroll_direction]

        case scroll_direction
        when 'natural'
          return app.tab_manager.handle_scroll_up(x, y) if app.tab_manager.enclose?(x, y)
        when 'traditional'
          return app.tab_manager.handle_scroll_down(x, y) if app.tab_manager.enclose?(x, y)
        end
      when 2097152
        scroll_direction = app.preferences[:control, :scroll_direction]

        case scroll_direction
        when 'natural'
          return app.tab_manager.handle_scroll_down(x, y) if app.tab_manager.enclose?(x, y)
        when 'traditional'
          return app.tab_manager.handle_scroll_up(x, y) if app.tab_manager.enclose?(x, y)
        end
      end
    end
{'fraction_non_alphanumeric': 0.08974358974358974, 'fraction_numerical': 0.007889546351084813, 'mean_word_length': 2.4410517387616624, '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': '6096099', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1344, 'n_words': 283}