Created
December 3, 2013 22:56
-
-
Save saitoha/7779129 to your computer and use it in GitHub Desktop.
Vimで画像を見る(DRCSのSIXEL拡張の話) ref: http://qiita.com/kefir_/items/78e64c545a70a0ebea8a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vimであいまいな幅の文字の論理幅を1にします | |
set ambiwidth=single | |
" RLoginであいまいな幅の文字の論理幅を1にします。 | |
call writefile(["\e[?8428h"], '/dev/tty') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% drcsconv -u -n256 -r24 neko.png > neko.drcs | |
% drcsconv -u -n256 -s24 vim.png > vim.drcs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% vim vim.drcs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:vsp neko.drcs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% vim vim.drcs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:vsp neko.drcs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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