Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Vimで画像を見る(DRCSのSIXEL拡張の話) ref: http://qiita.com/kefir_/items/78e64c545a70a0ebea8a
" Vimであいまいな幅の文字の論理幅を1にします
set ambiwidth=single
" RLoginであいまいな幅の文字の論理幅を1にします。
call writefile(["\e[?8428h"], '/dev/tty')
setlocal nowrap
setlocal foldlevel=0
setlocal foldmethod=marker
setlocal foldmarker=^[P,^[\
let lines = getline(0,'$')
call filter(lines, 'len(v:val) > 0 && char2nr(v:val[0]) < 128')
call writefile(lines, '/dev/tty')
call cursor(len(lines), 0)
call feedkeys("z\<CR>")
% start=0; end=24; f="neko.png"; (for j in {$start..$end}; do echo -en "\x1bP1;0;0;15;1;3;24;0{ "; `printf "echo -en \\\\\\\\x%x" $((j + 64))`; cat $f|pngtopnm 2>/dev/null|pnmscale --width=1200|pnmcut 0 $((j * 24 - $start * 24)) 1200 24|pnmquant 256 2>/dev/null|ppmtosixel 2> /dev/null; done |sed 's/\x9c/\x1b\\/g' | sed 's/\x90.*$//g' && for j in {$start..$end}; do for i in {32..111}; do `printf "echo -en \\\\\\\\U10%x%x" $((j + 64)) i`; done; echo ""; done) > neko.drcs
% start=25; end=49; f="vim.png"; (for j in {$start..$end}; do echo -en "\x1bP1;0;0;15;1;3;24;0{ "; `printf "echo -en \\\\\\\\x%x" $((j + 64))`; cat $f|pngtopnm 2>/dev/null|pnmscale --width=1200|pnmcut 0 $((j * 24 - $start * 24)) 1200 24|pnmquant 256 2>/dev/null|ppmtosixel 2> /dev/null; done |sed 's/\x9c/\x1b\\/g' | sed 's/\x90.*$//g' && for j in {$start..$end}; do for i in {32..111}; do `printf "echo -en \\\\\\\\U10%x%x" $((j + 64)) i`; done; echo ""; done) > vim.drcs
% drcsconv -u -n256 -r24 neko.png > neko.drcs
% drcsconv -u -n256 -s24 vim.png > vim.drcs
% vim vim.drcs
:vsp neko.drcs
% vim vim.drcs
:vsp neko.drcs
function! s:ViewImage()
if &ambiwidth == 'single'
setlocal nowrap
setlocal foldlevel=0
setlocal foldmethod=marker
setlocal foldmarker=^[P,^[\
%delete
call system('cat "' . expand('%:p') . '" | drcsconv -u --ncolor=256 > /tmp/drcs')
let lines = readfile('/tmp/drcs')
call append(0, lines)
call filter(lines, 'len(v:val) > 0 && char2nr(v:val[0]) < 128')
call writefile(lines, '/dev/tty', 'b')
call cursor(len(lines) + 1, 0)
call feedkeys("z\<CR>")
endif
endfunction
autocmd! TermResponse * call s:ViewImage()
if len(v:termresponse)
call s:ViewImage()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment