Sha256: 1c67a8f687f311e0f47d6883215107d1bcc8fd87353b94a0d20be8c5f85e4997

Contents?: true

Size: 1.14 KB

Versions: 36

Compression:

Stored size: 1.14 KB

Contents

require 'plist'

module Ruco
  class TMTheme
    attr_accessor :background, :foreground, :styles

    # TODO maybe later...
    #attr_accessor :name, :uuid, :comment, :line_highlight

    # not supported in Curses ...
    #attr_accessor :invisibles, :caret, :selection

    def initialize(file)
      raw = Plist.parse_xml(file)
      raise "Theme not found in #{file}" unless raw
      rules = raw['settings']
      @styles = {}

      # set global styles
      global = rules.shift['settings']
      self.background = global['background']
      self.foreground = global['foreground']

      # set scope styles
      rules.each do |rules|
        style = [
          rules['settings']['foreground'],
          rules['settings']['background'],
        ]

        next if style == [nil, nil] # some weird themes have rules without colors...
        next unless scope = rules['scope'] # some weird themes have rules without scopes...

        scope.split(/, ?/).map(&:strip).each do |scope|
          @styles[scope] = style unless nested_scope?(scope)
        end
      end
    end

    private

    def nested_scope?(scope)
      scope.include?(' ')
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ruco-0.4.0 lib/ruco/tm_theme.rb
ruco-0.3.0 lib/ruco/tm_theme.rb
ruco-0.2.23 lib/ruco/tm_theme.rb
ruco-0.2.22 lib/ruco/tm_theme.rb
ruco-0.2.21 lib/ruco/tm_theme.rb
ruco-0.2.20 lib/ruco/tm_theme.rb
ruco-0.2.19 lib/ruco/tm_theme.rb
ruco-0.2.18 lib/ruco/tm_theme.rb
ruco-0.2.17 lib/ruco/tm_theme.rb
ruco-0.2.16 lib/ruco/tm_theme.rb
ruco-0.2.15 lib/ruco/tm_theme.rb
ruco-0.2.14 lib/ruco/tm_theme.rb
ruco-0.2.13 lib/ruco/tm_theme.rb
ruco-0.2.12 lib/ruco/tm_theme.rb
ruco-0.2.11 lib/ruco/tm_theme.rb
ruco-0.2.10 lib/ruco/tm_theme.rb
ruco-0.2.9 lib/ruco/tm_theme.rb
ruco-0.2.8 lib/ruco/tm_theme.rb
ruco-0.2.7 lib/ruco/tm_theme.rb
ruco-0.2.6 lib/ruco/tm_theme.rb