From 0064ce9591e7d175a2449635471be452845df2ec Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 31 Jan 2015 03:43:43 +0100 Subject: [PATCH] Add vim2r2.js script to convert vim themes for r2 --- doc/vim2r2.js | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 doc/vim2r2.js diff --git a/doc/vim2r2.js b/doc/vim2r2.js new file mode 100644 index 0000000000..e45860e6af --- /dev/null +++ b/doc/vim2r2.js @@ -0,0 +1,175 @@ +/* +# author: pancake +# description: Duktape/NodeJS script to convert VIM colorschemes for radare2 +# copyright: 2015 LGPLv3 +# +# Using NodeJS +# ------------ +# +# $ node vim2r2.js < /usr/share/vim/vim74/colors/slate.vim > slate.r2 +# $ r2 -i slate.r2 /bin/ls +# +# Using Duktape +# ------------- +# $ r2 -qc 'k colors=/usr/share/vim/vim74/colors/slate.vim' -i vim2r2.js -- +*/ + +var DEBUG = false; //true; +var THEME = "/usr/share/vim/vim74/colors/slate.vim"; + +function colorToR2(c) { + if (!c) return ""; + if (c[0]=='#') { + return "rgb:"+c[1]+c[3]+c[5]; + } + if (+c >0) { + return { + 1: 'red', + 2: 'green', + 3: 'yellow', + 4: 'blue', + 5: 'magenta', + 6: 'cyan', + 7: 'white', + 8: 'gray', + }[+c] || "cyan"; + } + return { + "red": "rgb:f00", + "brown": "rgb:630", + "darkcyan": "rgb:066", + "darkblue": "rgb:006", + "blue": "rgb:00f", + "darkgreen": "rgb:030", + "darkgrey": "rgb:666", + "yellow": "yellow", + "yellowgreen": "rgb:af3", + "khaki": "rgb:550", + "seagreen": "rgb:093", + "magenta": "rgb:909", + "green": "green", + "goldenrod": "rgb:fa0", + "white": "white", + "black": "black", + "gray": "rgb:888", + "grey90": "rgb:999", + "grey50": "rgb:777", + "grey30": "rgb:777", + "lightblue": "rgb:0bf", + "slategrey": "rgb:999", + "gold": "rgb:ff0", + 'cornflowerblue': 'rgb:46f', + 'navajowhite': 'rgb:ddd', + 'royalblue': 'rgb:47f' + }[c.toLowerCase()] || c; +} + +function watToR2(c) { + return { + 'Comment': ["comment"], + 'Question': ["prompt"], + 'StatusLine': ["prompt"], + 'ErrorMsg': ["trap"], + 'Repeat': ["trap"], + 'Number': ["num"], + 'Operator': ["trap"], + 'Normal': ["trap"], + 'Constant': ["trap"], + 'Ignore': ["nop"], + 'Function': ["jmp","ujmp", "cjmp"], + 'LineNr': ["offset"], + 'MoreMsg': ["flow"], + 'IncSearch': ["help"], + 'Directory': ["call"], + 'NonText': ["other"], + 'Title': ["flag"], + 'Statement': ["num"], + 'Type': ["reg"] + }[c] || []; +} + +function v2r_parse(str) { + var keys = {}; + function isHiLine(line) { + if (line.indexOf ("hi ")==0) + return true; + if (line.indexOf (":hi ")==0) + return true; + return false; + } + var trim = function(s) { + return String.prototype.trim.apply (s); + } + str = (""+str).replace(/\t/g,' '); + str.split ('\n').map(trim).forEach (function (line) { + if (line.indexOf ("let s:")==0) { + console.log("# ", line); + } else + if (isHiLine (line)) { + var words = line.split(" ").map(trim); + var wat = words[1]; + function processColor(col) { + var color = col.split('=')[1]; + var v = colorToR2 (color); + watToR2 (wat).forEach (function (k) { + keys[k] = v; + }); + } + if (DEBUG) + console.log (line); + var valid = [ 'ctermfg', 'guifg' ]; + valid.forEach (function (v) { + for (var i = 2; i