diff options
| author | kawas44 <kawas44@gmail.com> | 2017-08-26 23:49:36 +0200 |
|---|---|---|
| committer | kawas44 <kawas44@gmail.com> | 2017-08-28 21:54:42 +0200 |
| commit | f95ccef4411878d56fba498d9d83fa35e62575c2 (patch) | |
| tree | f7c4c4bbbb2217ecedf5f3775e5a983e7c6ff212 /contrib | |
| parent | 519d466f49f3b4db73689a8bc4d911617e947667 (diff) | |
Fix kakmap.rb script for new normal.cc code
Diffstat (limited to 'contrib')
| -rwxr-xr-x | contrib/kakmap.rb | 69 |
1 files changed, 44 insertions, 25 deletions
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<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 + + # match key mapping line + /^\{\s*\{(?<mdky>[^}]+)\}\s*,\s*\{\s*"(?<dsc>[^"]+)"/.match(line) do |m| + modAndKey = m['mdky'] + des = m['dsc'] - mod = (line.scan( /^alt|^ctrl/ ).first || 'none').to_sym - key = line.scan(/(?:^Key::(\w+)|(?<!\\)'\\?(.*?)(?<!\\)')/).flatten.compact.first - des = line.scan(/(?<!\\)"(?<desc>.*?)(?<!\\)"/).flatten.first + modAndKey.gsub!(/\s*\/\*[^*]+\*\/\s*/, '') # remove comment in key definition - key = 'Space' if key == ' ' + # 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 - commands[key] ||= {} - commands[key][mod] = des + 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 |
