aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards/nyquist/keymaps/hexwire/keymap_to_readme.rb
blob: 7285b008a4e69132aa234d7c9ddd9c2e59fa1191 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby

class KeymapConverter

  def initialize(filename)
    @filename = filename
    @mode = :search
  end

  def read_keymaps
    lines = IO.readlines(@filename)
    lines.each { |line| parse_line line[0..-2] }
  end

  def parse_line(line)
    case @mode
    when :search
      if line =~ /KC_KEYMAP/
        puts "### #{line}"
        puts "```"
        @mode = :parse
      end
    when :parse
      if line =~ /\)/
        @mode = :search
        puts "```\n\n"
      else 
        line = line[4..-1]
        line.sub!(/(,)^-/m, "|")
        line.sub!(/( {4})/, "    |")

        puts line
      end
    end
  end

end

converter = KeymapConverter.new('keymap.c')
converter.read_keymaps