Sha256: 8668a8a4d63c2cb9d8b6ffc9d0d7a514b59c7efc5fdfe21c4486d909ca1840d5

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require 'curses'
require_relative 'color'
require_relative '../git'

module GitCrecord
  module UI
    module StatusBar
      def self.refresh(main_win)
        write_left(main_win)
        fill_to_eol
        write_right(main_win)
        win.refresh
      end

      def self.write_left(_main_win)
        win.setpos(0, 0)
        win.addstr(" #{branch}")
      end

      def self.write_right(main_win)
        str = " #{reverse ? '[reverse]' : ''} #{main_win.highlight_position} "
        win.setpos(0, [0, win.maxx - str.size].max)
        win.addstr(str)
      end

      def self.fill_to_eol
        fill_width = win.maxx - win.curx
        win.addstr(' ' * fill_width) if fill_width.positive?
      end

      def self.win
        @win ||= Curses::Window.new(1, Curses.cols, 0, 0).tap do |win|
          win.attrset(Color.status_bar | Curses::A_BOLD)
        end
      end

      def self.branch
        @branch = Git.branch
      end

      def self.reverse
        @reverse
      end

      def self.reverse=(reverse)
        @reverse = reverse
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-crecord-1.2.0 lib/git_crecord/ui/status_bar.rb