diff --git a/contrib/kakmap.rb b/contrib/kakmap.rb index 33b61639..42d1ac64 100755 --- a/contrib/kakmap.rb +++ b/contrib/kakmap.rb @@ -5,23 +5,35 @@ require 'markaby' -# Relies on the cmds array assignment ending with }; -raw = ARGF.read.split( /cmds\[\] =\s+{\s*/m ).last.split( /^};$/ ).first +# Relies on the keymap HashMap assignment ending with }; +raw = ARGF.read.split( /const\s+HashMap\s+keymap\s*{/ ).last.split( /^};$/ ).first commands = {} -# break code into lines raw.split( /\n+/ ).each{ |line| - line.gsub!( /(^\s*{\s*|\s*},?\*$)/, '' ) # discard wrapping for array elements + # skip empty or comment line + line = line.strip + if line.empty? or /^\/\// =~ line + next + end - mod = (line.scan( /^alt|^ctrl/ ).first || 'none').to_sym - key = line.scan(/(?:^Key::(\w+)|(?.*?)(?[^}]+)\}\s*,\s*\{\s*"(?[^"]+)"/.match(line) do |m| + modAndKey = m['mdky'] + des = m['dsc'] - key = 'Space' if key == ' ' + modAndKey.gsub!(/\s*\/\*[^*]+\*\/\s*/, '') # remove comment in key definition - commands[key] ||= {} - commands[key][mod] = des + # match key and modifier + /Key::(?\w+)|(?alt|ctrl)\('\\?(?.+?)'\)|'\\?(?.+?)'$/.match(modAndKey) do |sm| + key = sm['key'] + mod = (sm['mod'] || 'none').to_sym + + key = 'Space' if key == ' ' + commands[key] ||= {} + commands[key][mod] = des + end + end } # sort, showing single characters first, symbols next and spelled out keys last @@ -37,22 +49,29 @@ commands = commands.sort_by{ |key, _| } puts Markaby::Builder.new { - table do - thead do - tr do - th "Key" - th "Description" - th "ALT + key" - th "CTRL + key" - end + html do + head do + title "Kakoune default keymap" end - tbody do - for key, binding in commands - tr do - th key - td binding[:none] - td binding[:alt] - td binding[:ctrl] + body do + table :style => "border-collapse: collapse" do + thead do + tr do + th "Key" + th "Description" + th "ALT + key" + th "CTRL + key" + end + end + tbody do + for key, binding in commands + tr :style => "border-bottom: 1px solid #fbfbfb" do + th key + td binding[:none] + td binding[:alt] + td binding[:ctrl] + end + end end end end