Sha256: ddee9dd7fad00e69cde641ca249b8f8e0d36170ee99e5c0e7af33741717aaa5a

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

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

16 entries across 16 versions & 1 rubygems

Version Path
textbringer-1.0.0 lib/textbringer/face.rb
textbringer-0.3.2 lib/textbringer/face.rb
textbringer-0.3.1 lib/textbringer/face.rb
textbringer-0.3.0 lib/textbringer/face.rb
textbringer-0.2.9 lib/textbringer/face.rb
textbringer-0.2.8 lib/textbringer/face.rb
textbringer-0.2.7 lib/textbringer/face.rb
textbringer-0.2.6 lib/textbringer/face.rb
textbringer-0.2.4 lib/textbringer/face.rb
textbringer-0.2.5 lib/textbringer/face.rb
textbringer-0.2.3 lib/textbringer/face.rb
textbringer-0.2.2 lib/textbringer/face.rb
textbringer-0.2.1 lib/textbringer/face.rb
textbringer-0.2.0 lib/textbringer/face.rb
textbringer-0.1.9 lib/textbringer/face.rb
textbringer-0.1.8 lib/textbringer/face.rb