Sha256: 03aae6d4a317560ba9707736cce4c43c9f7dd6de244dadcfc0f326d2a923bdfa

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

require "curses"

module Textbringer
  class Face
    attr_reader :name, :attributes

    @@face_table = {}
    @@next_color_pair = 1

    def self.[](name)
      @@face_table[name]
    end

    def self.define(name, **opts)
      if @@face_table.key?(name)
        @@face_table[name].update(**opts)
      else
        @@face_table[name] = new(name, **opts)
      end
    end

    def self.delete(name)
      @@face_table.delete(name)
    end

    def initialize(name, **opts)
      @name = name
      @color_pair = @@next_color_pair
      @@next_color_pair += 1
      update(**opts)
    end

    def update(foreground: -1, background: -1,
               bold: false, underline: false, reverse: false)
      @foreground = foreground
      @background = background
      @bold = bold
      @underline = underline
      @reverse = reverse
      Curses.init_pair(@color_pair,
                       Color[foreground], Color[background])
      @attributes = 0
      @attributes |= Curses.color_pair(@color_pair)
      @attributes |= Curses::A_BOLD if bold
      @attributes |= Curses::A_UNDERLINE if underline
      @attributes |= Curses::A_REVERSE if reverse
      self
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
textbringer-1.4.1 lib/textbringer/face.rb
textbringer-1.3.0 lib/textbringer/face.rb
textbringer-1.2.0 lib/textbringer/face.rb
textbringer-1.1.2 lib/textbringer/face.rb
textbringer-1.1.1 lib/textbringer/face.rb
textbringer-1.1.0 lib/textbringer/face.rb
textbringer-1.0.9 lib/textbringer/face.rb
textbringer-1.0.4 lib/textbringer/face.rb
textbringer-1.0.3 lib/textbringer/face.rb
textbringer-1.0.2 lib/textbringer/face.rb
textbringer-1.0.1 lib/textbringer/face.rb