Sha256: 85583cddf4bc2dfd2bbddbb27543272292d7c5c6e03a24520b0725be061ba82f

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'twiddler/config'

module Twiddler
  module Lint
    def self.check(config)
      report = []
      Rule::registered.each do |rule|
        report << rule.new(config).check
      end
      report
    end

    class Rule
      class << self
        def register
          @@registered ||= []
          @@registered << self
        end

        def registered
          @@registered || []
        end
      end

      def initialize(config)
        @config = config
      end

      def check()
        return ""
      end
    end

    class MissingStrokes < Rule
      register
      def check()
        all_strokes = []
        @config.keytable.each do |key|
          all_strokes << [key.code, ""]
          all_strokes << [key.code, "shift"] if key.has_mod?("shift")
        end

        @config.keyboard.each do |chord|
          next unless chord.single?
          all_strokes.delete(@config.keytable.normalized(chord[0]))
        end

        if all_strokes.empty?
          return "Missing: all normal keystrokes accounted for"
        else
          return "Config lacks strokes: #{all_strokes.map{|str| @config.keytable[*str]}.inspect}"
        end
      end
      
    end


  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twiddler-utils-0.0.3 lib/twiddler/lint.rb