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' 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']
modAndKey.gsub!(/\s*\/\*[^*]+\*\/\s*/, '') # remove comment in key definition
# 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 == ' ' key = 'Space' if key == ' '
commands[key] ||= {} commands[key] ||= {}
commands[key][mod] = des 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,7 +49,12 @@ commands = commands.sort_by{ |key, _|
} }
puts Markaby::Builder.new { puts Markaby::Builder.new {
table do html do
head do
title "Kakoune default keymap"
end
body do
table :style => "border-collapse: collapse" do
thead do thead do
tr do tr do
th "Key" th "Key"
@ -48,7 +65,7 @@ puts Markaby::Builder.new {
end end
tbody do tbody do
for key, binding in commands for key, binding in commands
tr do tr :style => "border-bottom: 1px solid #fbfbfb" do
th key th key
td binding[:none] td binding[:none]
td binding[:alt] td binding[:alt]
@ -57,5 +74,7 @@ puts Markaby::Builder.new {
end end
end end
end end
end
end
} }