Fix kakmap.rb script for new normal.cc code

This commit is contained in:
kawas44 2017-08-26 23:49:36 +02:00
parent 519d466f49
commit f95ccef441

View File

@ -5,23 +5,35 @@
require 'markaby' require 'markaby'
# Relies on the cmds array assignment ending with }; # Relies on the keymap HashMap assignment ending with };
raw = ARGF.read.split( /cmds\[\] =\s+{\s*/m ).last.split( /^};$/ ).first raw = ARGF.read.split( /const\s+HashMap<Key,\s*NormalCmd>\s+keymap\s*{/ ).last.split( /^};$/ ).first
commands = {} commands = {}
# break code into lines
raw.split( /\n+/ ).each{ |line| 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 # match key mapping line
key = line.scan(/(?:^Key::(\w+)|(?<!\\)'\\?(.*?)(?<!\\)')/).flatten.compact.first /^\{\s*\{(?<mdky>[^}]+)\}\s*,\s*\{\s*"(?<dsc>[^"]+)"/.match(line) do |m|
des = line.scan(/(?<!\\)"(?<desc>.*?)(?<!\\)"/).flatten.first modAndKey = m['mdky']
des = m['dsc']
key = 'Space' if key == ' ' modAndKey.gsub!(/\s*\/\*[^*]+\*\/\s*/, '') # remove comment in key definition
commands[key] ||= {} # match key and modifier
commands[key][mod] = des /Key::(?<key>\w+)|(?<mod>alt|ctrl)\('\\?(?<key>.+?)'\)|'\\?(?<key>.+?)'$/.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 # 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 { puts Markaby::Builder.new {
table do html do
thead do head do
tr do title "Kakoune default keymap"
th "Key"
th "Description"
th "ALT + key"
th "CTRL + key"
end
end end
tbody do body do
for key, binding in commands table :style => "border-collapse: collapse" do
tr do thead do
th key tr do
td binding[:none] th "Key"
td binding[:alt] th "Description"
td binding[:ctrl] 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 end
end end