commit d22646dc7226644fd733277bbeac2c4f17eb9edb
parent b007eac56e68ce9bea81d1aaa972e3adf946ade9
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Wed, 7 Aug 2019 17:58:03 +0200
Vim colorscheme generation from simpler syntax
Former-commit-id: 1e35a37c7910e29f0f2b1cf843270f80784b7893
Diffstat:
7 files changed, 298 insertions(+), 4 deletions(-)
diff --git a/scripts/colgen.rb b/scripts/colgen.rb
@@ -0,0 +1,183 @@
+#!/usr/bin/env ruby
+# vim: foldmethod=indent foldlevel=0
+module Colorizer
+ BASIC16 = [
+ [ 0x00, 0x00, 0x00 ],
+ [ 0xCD, 0x00, 0x00 ],
+ [ 0x00, 0xCD, 0x00 ],
+ [ 0xCD, 0xCD, 0x00 ],
+ [ 0x00, 0x00, 0xEE ],
+ [ 0xCD, 0x00, 0xCD ],
+ [ 0x00, 0xCD, 0xCD ],
+ [ 0xE5, 0xE5, 0xE5 ],
+ [ 0x7F, 0x7F, 0x7F ],
+ [ 0xFF, 0x00, 0x00 ],
+ [ 0x00, 0xFF, 0x00 ],
+ [ 0xFF, 0xFF, 0x00 ],
+ [ 0x5C, 0x5C, 0xFF ],
+ [ 0xFF, 0x00, 0xFF ],
+ [ 0x00, 0xFF, 0xFF ],
+ [ 0xFF, 0xFF, 0xFF ]
+ ]
+
+ # Some functions that need to be defined
+ def xterm2rgb16(color)
+ # 16 basic colors
+ r, g, b = 0, 0, 0
+ r, g, b = BASIC16[color]
+ return [r, g, b]
+ end
+ def xterm2rgb256(color)
+ # 16 basic colors
+ r, g, b = 0, 0, 0
+ if color < 16
+ return xterm2rgb16(color)
+
+ # color cube color
+ elsif color >= 16 && color < 232
+ color=color-16
+ valuerange6 = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ]
+ r = valuerange6[(color/36)%6]
+ g = valuerange6[(color/6)%6]
+ b = valuerange6[color%6]
+
+ # gray tone
+ elsif color >= 232 && color <= 255
+ r = 8 + (color-232) * 0x0a
+ g, b = r, r
+ end
+
+ return [r, g, b]
+ end
+ def check16colorterm(rgblist, minlist)
+ min = minlist[0] + minlist[1] + minlist[2]
+ [[205,0,0], [0,205,0], [205,205,0], [205,0,205], [0,205,205], [0,0,238], [92,92,255]].each do |value|
+ # euclidian distance would be needed,
+ # but this works good enough and is faster.
+ t = value.each_with_index.map { |v, i| (v - rgblist[i]).abs }.sum
+ return value if min > t
+ end
+ return rgblist
+ end
+ def roundcolor(arr)
+ result = []
+ minlist = []
+ min = 1000
+ list = [ 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF ]
+ arr.each do |item|
+ r = nil
+ list.each do |val|
+ t = (val - item).abs
+ if (min > t)
+ min = t
+ r = val
+ end
+ end
+ result << r if not r.nil?
+ minlist << min
+ min = 1000
+ end
+ # Check with the values from the 16 color xterm, if the difference
+ # is lower
+ result = check16colorterm(result, minlist)
+ return result
+ end
+
+ def rgb2term color
+ if color == '000000'
+ return 0
+ elsif color == 'FFFFFF'
+ return 15
+ else
+ r = color[0..1].to_s.to_i(16)
+ g = color[2..3].to_s.to_i(16)
+ b = color[4..5].to_s.to_i(16)
+
+ # Try exact match first
+ colortable = (0..255).map { |x| xterm2rgb256(x) }
+ i = colortable.index([r, g, b])
+ return i if !i.nil? && i > -1
+
+ # Grey scale ?
+ if r == g && r == b
+ # 0 and 15 have already been take care of
+ if r < 5
+ return 0 # black
+ elsif r > 244
+ return 15 # white
+ end
+ # grey cube starts at index 232
+ return 232+(r-5)/10
+ end
+
+ # Round to the next step in the xterm color cube
+ # euclidian distance would be needed,
+ # but this works good enough and is faster.
+ round = roundcolor([r, g, b])
+ # Return closest match or -1 if not found
+ return colortable.index(round)
+ end
+ end
+end
+
+# Where my code starts
+# Next step - make it automatically name the file & move it to ~/.vim/colors, based on file passed as arg.
+include Colorizer
+primary=[]
+links={}
+background="light"
+if ARGV[0].nil?
+ abort "Colors file required as argument"
+elsif not File.file? ARGV[0]
+ abort "File #{ARGV[0]} not found."
+elsif not ARGV[0].end_with? ".vimcolor"
+ abort "File extension should be .vimcolor"
+end
+
+File.open(ARGV[0], "r").each do |line|
+ line.strip!
+ if line.start_with? "link"
+ from, to = line.split(" ")[1..-1]
+ from.split(',').each do |from_group|
+ links[from_group] = to
+ end
+ elsif line.empty? || line.start_with?("\"")
+ # Ignore
+ elsif line.start_with? "background"
+ background = line.split.last
+ else
+ line_arr = line.split
+ group = line_arr.first
+ rest = line_arr[1..-1].join ' '
+
+ colors, attrs = rest.split('.')
+ fg, bg = colors.split(',').map { |x| x.strip }
+
+ bg = "NONE" if bg.nil?
+
+ attrs = (attrs.nil? ? "NONE" : attrs.split(',').map { |x| x.strip }.join(","))
+ primary << [group, fg, bg, attrs]
+ end
+end
+
+
+File.open("#{ENV['HOME']}/.vim/colors/#{ARGV[0].sub('.vimcolor', '.vim')}", "w") do |f|
+ f.puts <<~EOF
+ if version > 580
+ highlight clear
+ if exists("syntax_on")
+ syntax reset
+ endif
+ endif
+ let g:colors_name = "#{ARGV[0].sub('.vimcolor', '')}"
+ set background=#{background}
+ EOF
+ primary.each do |item|
+ f.puts "hi #{item[0]} guifg=#{item[1]} guibg=#{item[2]} ctermfg=#{item[1] == "NONE" ? "NONE" : rgb2term(item[1][1..-1])} ctermbg=#{item[2] == "NONE" ? "NONE" : rgb2term(item[2][1..-1])} cterm=#{item[3]} gui=#{item[3]}"
+ end
+ links.each do |from,to|
+ f.puts "hi! link #{from} #{to}"
+ end
+end
+
+puts "Written to ~/.vim/colors/#{ARGV[0].sub('.vimcolor', '.vim')}"
diff --git a/vim/after/ftplugin/vimcolor.vim b/vim/after/ftplugin/vimcolor.vim
@@ -0,0 +1,4 @@
+setlocal makeprg=colgen.rb\ %
+autocmd BufWritePost <buffer> silent make | execute 'colorscheme '.expand('%<')
+vmap CH <Plug>Colorizer
+noremap CC :ColorClear<CR>
diff --git a/vim/colors/jokull.vimcolor b/vim/colors/jokull.vimcolor
@@ -0,0 +1,43 @@
+" This script uses the colorgen script
+" to create a colorscheme from something a bit more readable.
+" Format is 'group fg_hex, bg_hex. attrs'
+background light
+normal #2c2625, #e4e4e4
+cursorline NONE, #d0d0d0
+string #009051. italic
+identifier #112d4e
+function #0096ff. bold
+statement #73fdff.
+include #76d6ff. bold
+type #005493
+delimiter #fffb00
+comment #ecfcff. italic
+search NONE, #d7f1e0
+folded #73fdff, #d0d0d0
+tablinefill NONE, #d0d0d0
+tablinesel NONE, #e5e5e5
+wildmenu #005493, #e5e5e5. bold
+linenr NONE
+preproc NONE
+vertsplit NONE
+todo Blue, Yellow
+nontext #81A1C1
+statusline NONE, #7abecd
+statuslinenc NONE, #a8dbfd
+visual NONE, #a8caff
+
+link tabline tablinefill
+link incsearch search
+link repeat,conditional,operator statement
+link define,macro,precondit include
+link debug,special,specialchar,specialcomment,tag,cursorlinenr,number delimiter
+link label,storageclass,typedef structure
+link character constant
+link signcolumn,netrwdir linenr
+link netrwexe title
+link spellbad todo
+link spellocal,spellrare,spellcap string
+link vimwikilink constant
+link mkdlink type
+link pmenu statuslinenc
+link pmenusel statusline
diff --git a/vim/colors/junipero.vim b/vim/colors/junipero.vim
@@ -1,5 +1,4 @@
" Created with github.com/chrisbra/Colorizer and http://bytefluent.com/vivify/
-set background=dark
if version > 580
highlight clear
if exists("syntax_on")
@@ -20,6 +19,7 @@ function! s:h(group, style)
endfunction
let g:colors_name = "junipero"
+set background=dark
let s:text_color = {"gui": "#969696", "cterm": "246"}
let s:bg_color = {"gui": "#11121A", "cterm": "0"}
diff --git a/vim/colors/myjunipero.vimcolor b/vim/colors/myjunipero.vimcolor
@@ -0,0 +1,65 @@
+background dark
+normal #969696, #11121A
+cursorline NONE, #222222
+Structure #0490e8, NONE. bold
+Constant #5c78f0, NONE. NONE
+String #2de3e6, NONE. NONE
+Float #4580b4, NONE. NONE
+Boolean #fca8ad, NONE. NONE
+Identifier #5094c4, NONE. NONE
+Function #f9c60e, #11121a. bold
+Number #136aed, NONE. NONE
+Conditional #d0688d, #11121a. NONE
+Operator #e8cdc0, #11121a. NONE
+Exception #d0a8ad, #11121a. bold
+Statement #ff6c11, NONE. NONE
+Repeat #e06070, #11121a. NONE
+Keyword #bebebe, #11121a. bold
+PreProc #ae15eb, NONE. NONE
+Include #ba75cf, NONE. NONE
+Type #ff3863, NONE. bold
+Delimiter #aaaaca, NONE. NONE
+Comment #349d58, #11121a. NONE
+NonText #382920, #11121a. NONE
+Ignore #666666, NONE. NONE
+SpecialKey #90dcb0, NONE. NONE
+Underlined #bac5ba, NONE. NONE
+Error NONE, #b03452. NONE
+Todo #ffd500, #5c0d43. NONE
+MatchParen #001122, #7b5a55. NONE
+Cursor #0000aa, #cad5c0. NONE
+Visual #102030, #80a0f0. NONE
+VisualNOS #201a30, #a3a5FF. NONE
+LineNr #2069a9, #101124. NONE
+Search #2de3e6, #6b5469. NONE
+IncSearch #babeaa, #3a4520. NONE
+WildMenu #000000, #804000. NONE
+VertSplit #223355, #22253c. NONE
+TabLineSel #6079c9, #363649. NONE
+Title #fff7fa, NONE. NONE
+PmenuSel #f0e0b2, #4a85ba. NONE
+PmenuThumb NONE, #000000. NONE
+PmenuSbar NONE, #0000ff. NONE
+Pmenu #bdbdbd, #915623. NONE
+Folded #bebebe, #232235. NONE
+FoldColumn #dbcaa5, #0a0a18. NONE
+Directory #bbd0df, NONE. NONE
+DiffDelete #300845, #200845. NONE
+DiffText #f5f5f5, #423f00. NONE
+DiffAdd #e0e3e3, #003802. NONE
+DiffChange #fcfcfc, #2e032e. NONE
+ModeMsg #00AACC, NONE. NONE
+Question #AABBCC, #130445. NONE
+MoreMsg #2e8b57, NONE. NONE
+ErrorMsg #f0e2e2, #ff4545. NONE
+WarningMsg #fa8072, NONE. NONE
+
+link Label,StorageClass,Typedef Structure
+link Character,VimwikiLink Constant
+link Define,Macro,PreCondit Include
+link Debug,Special,SpecialChar,SpecialComment,Tag Delimiter
+link StatusLine,StatusLineNC,TabLine,TabLineFill,SignColumn,netrwDir LineNr
+link netrwExe Title
+link SpellBad Todo
+link SpelLocal,SpellRare,SpellCap String
+link mkdLink Type
diff --git a/vim/ftdetect/vimcolor.vim b/vim/ftdetect/vimcolor.vim
@@ -0,0 +1 @@
+autocmd BufRead,BufNewFile *.vimcolor set filetype=vimcolor
diff --git a/vim/vimrc b/vim/vimrc
@@ -236,11 +236,9 @@ if has('termguicolors')
endif
if system("osascript -e 'tell application \"System Events\" to tell appearance preferences to return (get dark mode as text)'") == "true\n"
- set background=dark
colorscheme junipero
else
- set background=light
- colorscheme kuroi
+ colorscheme jokull
endif
" where to find tags files