Merge remote-tracking branch 'kawas44/fix-kakmap-script'

This commit is contained in:
Maxime Coste 2017-08-29 07:58:33 +07:00
commit a06dbfac7d

View File

@ -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<Key,\s*NormalCmd>\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+)|(?<!\\)'\\?(.*?)(?<!\\)')/).flatten.compact.first
des = line.scan(/(?<!\\)"(?<desc>.*?)(?<!\\)"/).flatten.first
# match key mapping line
/^\{\s*\{(?<mdky>[^}]+)\}\s*,\s*\{\s*"(?<dsc>[^"]+)"/.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::(?<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
@ -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