<commit_before>require 'canis'

module Canis

  #
  # A vim-like application status bar that can display time and various other statuses
  #  at the bottom, typically above the dock (3rd line from last).
  #
  class ListFooter
    attr_accessor :config

    def initialize config={}, &block
      @config = config
      instance_eval &block if block_given?
    end
    #
    # command that returns a string that populates the status line (left aligned)
    # @see :right
    # e.g. 
    #   @l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }  
    #
    def command *args, &blk
      @command_text = blk
      @command_args = args
    end
    alias :left :command

    # 
    # Procudure for text to be right aligned in statusline
    def command_right *args, &blk
      @right_text = blk
      @right_args = args
    end
    def text(comp)
      @command_text.call(comp, @args) 
    end

    # NOTE: I have not put a check of repaint_required, so this will print on each key-stroke OR
    #   rather whenever form.repaint is called.
    def print comp
      row = comp.row + comp.height - 1
      col = comp.col + 2
      @color_pair ||= get_color($datacolor, @color, @bgcolor) 
      len = comp.width - col
      g = comp.window

      # first print dashes through
      g.printstring row, col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE

      # now call the block to get current values
      if @text
        ftext = @text.call(comp, @args) 
      else
        #ftext = " %-20s | %s" % [Time.now, status] # should we print a default value just in case user doesn't
        ftext = "Dummy"
      end

      if @right_text
        len = comp.width
        ftext = @right_text.call(self, @right_args) 
        c = len - ftext.length
        g.printstring @row, c, ftext, @color_pair, Ncurses::A_REVERSE
      end
    end

    
  end # class
end # module<commit_msg>added right aligned part<commit_after>require 'canis'

module Canis

  #
  # A vim-like application status bar that can display time and various other statuses
  #  at the bottom, typically above the dock (3rd line from last).
  #
  class ListFooter
    attr_accessor :config
    attr_accessor :color_pair
    attr_accessor :attrib

    def initialize config={}, &block
      @config = config
      @color_pair = get_color($datacolor, config[:color], config[:bgcolor]) 
      @attrib = config[:attrib]
      instance_eval &block if block_given?
    end
    #
    # command that returns a string that populates the status line (left aligned)
    # @see :right
    # e.g. 
    #   @l.command { "%-20s [DB: %-s | %-s ]" % [ Time.now, $current_db || "None", $current_table || "----"] }  
    #
    def command *args, &blk
      @command_text = blk
      @command_args = args
    end
    alias :left :command

    # 
    # Procudure for text to be right aligned in statusline
    def command_right *args, &blk
      @right_text = blk
      @right_args = args
    end
    def text(comp)
      @command_text.call(comp, @command_args) 
    end
    def right_text(comp)
      @right_text.call(comp, @right_args) 
    end

    # supply a default print function. The user program need not call this. It may be overridden
    def print comp
      config = @config
      row = comp.row + comp.height - 1
      col = comp.col + 2
      len = comp.width - col 
      g = comp.form.window
      # we check just in case user nullifies it deliberately, since he may have changed config values
      @color_pair ||= get_color($datacolor, config[:color], config[:bgcolor]) 
      @attrib ||= config[:attrib] || Ncurses::A_REVERSE
      

      # first print dashes through
      #g.printstring row, col, "%s" % "-" * len, @color_pair, Ncurses::A_REVERSE

      # now call the block to get current values for footer text on left
      ftext = nil
      if @command_text
        ftext = text(comp) 
      else
        if !@right_text
          # user has not specified right or left, so we use a default on left
          ftext = "#{comp.current_index} of #{comp.size}   "
        end
      end
      g.printstring(row, col, ftext, @color_pair, @attrib) if ftext

      # user has specified text for right, print it
      if @right_text
        len = comp.width
        ftext = right_text(comp)
        c = len - ftext.length - 2
        g.printstring row, c, ftext, @color_pair, @attrib
      end
    end

    
  end # class
end # module
{'fraction_non_alphanumeric': 0.09885160999774825, 'fraction_numerical': 0.0029272686331907227, 'mean_word_length': 2.268579838116262, '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': '6870788', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1400, 'n_words': 474}