diff options
Diffstat (limited to 'vim/boxdraw')
-rw-r--r-- | vim/boxdraw/bdua2b.pl | 91 | ||||
-rw-r--r-- | vim/boxdraw/bdub2a.pl | 30 | ||||
-rw-r--r-- | vim/boxdraw/boxdraw.txt | 164 | ||||
-rw-r--r-- | vim/boxdraw/boxdraw.vim | 291 | ||||
-rw-r--r-- | vim/boxdraw/outline.pl | 74 | ||||
-rw-r--r-- | vim/boxdraw/sampler.txt | 13 |
6 files changed, 663 insertions, 0 deletions
diff --git a/vim/boxdraw/bdua2b.pl b/vim/boxdraw/bdua2b.pl new file mode 100644 index 0000000..2e94b9a --- /dev/null +++ b/vim/boxdraw/bdua2b.pl @@ -0,0 +1,91 @@ +# Convert +-| style drawings into utf characters
+# BoxDraw-unicode-ascii to box
+# 2003-11-24 10:12:22 created by nsg
+# 2003-11-25 13:16:17 renamed and small fix in "intelligence"
+# 2004-06-18 14:18:11 boxsets
+# 2004-06-21 21:41:30 hex input codes
+use strict;
+use utf8;
+use 5.8.0;
+use Getopt::Std;
+
+our (
+ $opt_s, # boxset 's', 'd', 'v' or 'h'
+ $opt_x, # convert hex digits into appropriate bd characters
+ $opt_t, # ternary codes ' ' .. 'p'
+);
+getopts("s:xt");
+$opt_s||='s';
+
+my $o_utf8='--0251--001459--50585a----------0202----0c1c----525e------------51--51--53--5f--54--60------------------------------------------00185c--003468------------------1024----2c3c--------------------56--62--65--6b--------------------------------------------------505b5d----------506769----------5561------------646a------------57--63----------66--6c------------------------------------------------------------------01';
+
+binmode (STDOUT, ":utf8");
+my %boxset=(
+# 1|.,'}\u{25',"1 (_2 ]\ o_utf8) {~ 4#.2*#:i.16
+ 's'=>" \x{2502}\x{2500}\x{2514}\x{2502}\x{2502}\x{250c}\x{251c}\x{2500}\x{2518}\x{2500}\x{2534}\x{2510}\x{2524}\x{252c}\x{253c}\n",
+ 'd'=>" \x{2551}\x{2550}\x{255a}\x{2551}\x{2551}\x{2554}\x{2560}\x{2550}\x{255d}\x{2550}\x{2569}\x{2557}\x{2563}\x{2566}\x{256c}\n",
+ 'h'=>" \x{2502}\x{2550}\x{2558}\x{2502}\x{2502}\x{2552}\x{255e}\x{2550}\x{255b}\x{2550}\x{2567}\x{2555}\x{2561}\x{2564}\x{256a}\n",
+ 'v'=>" \x{2551}\x{2500}\x{2559}\x{2551}\x{2551}\x{2553}\x{255f}\x{2500}\x{255c}\x{2500}\x{2568}\x{2556}\x{2562}\x{2565}\x{256b}\n",
+);
+
+my $BOX=$boxset{$opt_s} || $boxset{'s'};
+
+my $prev='';
+my $pprev='';
+while(<STDIN>) {
+ process_line();
+}
+process_line();
+
+sub process_line
+{
+ my $out='';
+ for(my $i=0; $i<length($prev); ++$i) {
+ my $code=0;
+ my $c=substr($prev,$i,1);
+ if( $opt_x ) {
+ $code=0;
+ $code=hex($c) if $c=~/[[:xdigit:]]/;
+ } elsif( $opt_t ) {
+ $code=0;
+ if( ord($c)>32 ) {
+ $c=ord($c)-32;
+ for(0..3){$code =($code>>2)+(($c%3)<<6); $c=int($c/3);}
+ $c=chr(hex('25'.substr($o_utf8, $code*2,2)));
+ }
+ $code=0;
+ } else {
+ if( $c=~/[-+\|]/ ) {
+ $code |= 1 if substr($pprev,$i ,1)=~/[\|+]/ ;
+ $code |= 2 if substr($prev ,$i+1,1)=~/[-+]/ ;
+ $code |= 4 if substr($_ ,$i ,1)=~/[\|+]/ ;
+ $code |= 8 if substr($prev ,$i-1,1)=~/[-+]/ ;
+
+ $code = 10 if $code && '-' eq $c;
+ $code = 5 if $code && '|' eq $c;
+ }
+ }
+ $out.=$code?substr($BOX,$code,1):$c;
+ }
+ print $out;
+ $pprev=$prev;
+ $prev=$_;
+}
+
+#
+#
+# 0001 02
+# 0010 00
+# 0011 14
+# 0100 02
+# 0101 02
+# 0110 0c
+# 0111 1c
+# 1000 00
+# 1001 18
+# 1010 00
+# 1011 34
+# 1100 10
+# 1101 24
+# 1110 2c
+# 1111 3c
diff --git a/vim/boxdraw/bdub2a.pl b/vim/boxdraw/bdub2a.pl new file mode 100644 index 0000000..4482923 --- /dev/null +++ b/vim/boxdraw/bdub2a.pl @@ -0,0 +1,30 @@ +# Convert +-| style drawings into utf characters
+# BoxDraw-unicode-box to ascii
+# 2003-11-25 12:48:17 -- created by nsg
+
+use 5.8.0;
+use strict;
+use utf8;
+# binmode (STDOUT, ":utf8"); # incompatible with perl 5.6.1
+# binmode (STDIN, ":utf8"); # incompatible with perl 5.6.1
+
+while(<STDIN>) {
+ my $l=length;
+ tr/┌┬┐╓╥╖╒╤╕╔╦╗├┼┤╟╫╢╞╪╡╠╬╣└┴┘╙╨╜╘╧╛╚╩╝/++++++++++++++++++++++++++++++++++++/;
+ tr/═─│║/\-\-\|\|/;
+ printf "%03d ",$l;
+ print ;
+}
+
+# corners/splits:
+# ┌┬┐╓╥╖╒╤╕╔╦╗ 6ec
+# ├┼┤╟╫╢╞╪╡╠╬╣ 7fd
+# └┴┘╙╨╜╘╧╛╚╩╝ 3b9
+# round corners:
+# 256d 256e
+# 2570 256f
+# horizontal
+# ═ ─
+# vertical
+# │ ║
+
diff --git a/vim/boxdraw/boxdraw.txt b/vim/boxdraw/boxdraw.txt new file mode 100644 index 0000000..b821a43 --- /dev/null +++ b/vim/boxdraw/boxdraw.txt @@ -0,0 +1,164 @@ +Summary
+-------
+ * Draw diagrams and tables using "real box drawing characters" (AKA ANSI
+art).
+ * Move rectangular/linear blocks of text around.
+ * Trace box-drawing typeset diagrams -- follow the lines, etc.
+
+Detailed description
+--------------------
+These scripts facilitate drawing simple 'ANSI' graphic containing box
+drawing characters (not just '+', '-' and '|', but REAL box drawing
+characters). It can be useful to draw diagrams and fancy tables (at
+least, I use it this way).
+
+Upon sourcing the script defines several macros:
+
+<shift+arrow> -- moves cursor in specified direction leaving trail of
+box drawing characters, making all joins and crossings.
+g+<arrow> -- follow line of boxdrawing characters until it reaches
+intersection or ends.
+<shift+arrow> in visual mode -- move selected rectangular block in
+specified direction.
+\e -- ends box drawing mode (unmap shift+arrows macros and restore
+virtualedit value)
+\b -- restarts box drawing (map shift+arrows macros and set virtual
+ edit=all)
+\s -- selects 'single-line' boxdrawing characters
+\d -- selects 'double-line' boxdrawing characters
+\a -- convert all characters in selection into ascii '+', '-', '|' (utf8
+ only, not implemented)
+("\" prefix may be changed by changing mapleader variable, see :h mapleader)
+
+When rectangular block is selected, it can be moved around using
+<shift-arrow> keys. Unfortunately, as of version 6.1 multibyte
+characters and rectangular blocks do not live together too good, so this
+feature is experimental.
+
+When line block is selected, <shift-up> and <shift-down> moves it up or down
+nondestructively, <shift-left> decreases indent and <shift-up> increases
+indent.
+
+Currently box drawing is supported for utf8 and cp437 (DOS) encodings.
+
+Script does not use any "weird" box drawing characters from unicode set
+that are not present in, say, cp437. So, it is safe to save utf-8 file
+in any single byte encoding that contains regular single box drawing
+characters.
+This script also contains mapping that converts all boxdrawing
+characters in current selection into ascii '+', '-', '|'.
+
+If vim encoding is single byte, this script assumes cp437 (DOS). Most
+encodings have boxdrawing characters at the same place, however, some
+(notably, koi8-r) have them in different code postions.
+If you want to use it with encoding that contains such
+characters in diferent place, please drop me a note -- I will be happy
+to add support for that codepage too.
+
+To help you determine which boxdrawing characters are suppored by your
+terminal I have included file sampler.txt. Just type it (or cat it) on
+the termianal and encoding that labels the block that looks "right" will
+be your supported encoding.
+
+Note for PuTTY users
+--------------------
+
+It turns out that PuTTY does not translate Shift+Arrow combination into
+X key code (like xterm does), so mappings will not work for this
+terminal. I have modified initialization script to use <arrows> instead
+of <shift>+<arrows> in Unix environment.
+
+Perl scripts
+------------
+
+Some box-drawing related procedures are more naturally done with
+external scripts. These scripts take ascii standard input and produce
+utf8 encoded standard output.
+
+bdua2b.pl -- converts regular '+-|'-style drawing into single-line utf8
+ boxdrawing. This script has does not just blindly replace characters,
+ but instead looks to the neighbourhood and chooses boxdrawing
+ character that fits best. Use this script as a filter to convert
+ existing ascii drawings.
+ Option -ss selects single border characters, -sd -- double border,
+ -sh -- single vertical double horizontal, -sv single horizontal double
+ vertical.
+
+outline.pl -- outlines groups of similar characters in the input with
+ boxdrawing characters. Option -d makes output twice as wide, options
+ -s* select boxdrawing flavor as in previous script.
+ For example,
+
+ aaaacc
+ abbcc
+ ccbbc
+ cccb
+
+will be converted into
+
+ ┌───┬─┐
+ │┌─┬┘┌┘
+ ├┴┐└┐│
+ │ └┐├┘
+ └──┴┘
+
+or
+
+ ┌───────┬───┐
+ │ ┌───┬─┘ ┌─┘
+ ├─┴─┐ └─┐ │
+ │ └─┐ ├─┘
+ └─────┴─┘
+
+
+Both scripts were tested with ActivePerl 5.6.1.
+
+Plans:
+------
+* Support double boxes in a cleaner way.
+
+Installation
+------------
+Copy boxdraw.vim to the place where you normally keep vim scripts (e.g. ~/.vim
+or c:\vim\vimfiles) and source it every time you want to draw a diagram or nice
+table.
+
+You may wish also to add this to your menu by adding a line to your .gvimrc
+(_gvimrc) file (use actual path to boxdraw.vim):
+:menu Tools.Bo&x\ Draw :so ~/.vim/boxdraw.vim<CR>
+
+Environment
+-----------
+I run Windows and use boxdraw.vim in gvim (it supports utf-8 very
+nicely) and bd-single in vim (its support of utf-8 is kind of unclear
+for me). Both major Windows monospaced fonts (Courier New and Lucida
+Console) support wide range of Unicode characters, including box
+drawing.
+
+Why use box drawing characters?
+-------------------------------
+These characters are in Unicode standard for compatibility with wide
+range of existing 8-bit encodings that have them. The wording of Unicode
+standard discourages usage of such characters, other than for the
+purpose of converting between encodigns and storage of legacy data.
+Having said all that I found that sometimes a picture, even crude and
+primitive, is worth pages of explanations. Just about the only way to
+include picture in source code is to use ascii or "ansi" art. Ascii is
+more compatible, but "ansi" looks way better. Since I have to use
+Unicode to include cyrillic characters in comments anyway, I decided to
+stop on "ansi" art as a format of choice for in-source drawings.
+
+Author
+------
+Andrew Nikitin <nsg21@hotmail.com>
+
+History
+-------
+2002-01-09 -- v0.0 -- initial upload, single boxes in utf-8 encoding
+2002-01-10 -- v0.1 -- double boxes
+2002-01-30 -- v0.2 -- single-byte, box->ascii conversion
+2003-11-24 -- v0.3 -- perl scripts + some rectangular block movements
+2004-06-18 -- v0.4 -- following the lines, updated perl scripts
+2004-11-26 -- v1.0 -- combined single-byte and utf8 versions, included
+sampler.txt to help determine encoding
+2008-12-17 -- v1.1 -- special processing for line-block movements, changed cabbr for perl
diff --git a/vim/boxdraw/boxdraw.vim b/vim/boxdraw/boxdraw.vim new file mode 100644 index 0000000..284232f --- /dev/null +++ b/vim/boxdraw/boxdraw.vim @@ -0,0 +1,291 @@ +" Box drawing module for Vim 6.0 +" (C) Andrew Nikitin, 2002 +" 2002-01-07 -- created by nsg +" 2002-01-08 -- first box drawing (single only) +" 2002-01-09 -- (00:42) fixed col(".") bug (note vim bug k"tylj does not retu) +" 2002-01-09 -- optimize +" 2002-01-10 -- double boxes +" 2002-01-16 -- use script-local var and access function instead of global +" 2002-01-30 -- ,a mapping (box->ascii conversion) +" 2003-11-10 -- implemented MB avoiding "number Ctl-V" +" 2004-06-18 -- fixed ToAscii so it replaces "─"; trace path (g+arrow) +" 2004-06-23 -- merged single-byte and utf-8 support in one file +" 2004-06-30 -- do not use shift+arrows unless in win32 +" 2008-12-17 -- special processing for line-block movements, changed cabbr for +" perl + + +let s:o_utf8='--0251--001459--50585a----------0202----0c1c----525e------------51--51--53--5f--54--60------------------------------------------00185c--003468------------------1024----2c3c--------------------56--62--65--6b--------------------------------------------------505b5d----------506769----------5561------------646a------------57--63----------66--6c------------------------------------------------------------------01' +let s:i_utf8='44cc11------------------14------50------05------41------15--------------51--------------54--------------45--------------55--------------------------------------88221824289060a009060a81428219262a9162a29864a889468a9966aa14504105------40010410' +let s:o_cp437='--b3ba--c4c0d3--cdd4c8----------b3b3----dac3----d5c6------------ba--ba--d6--c7--c9--cc------------------------------------------c4d9bd--c4c1d0------------------bfb4----c2c5--------------------b7--b6--d2--d7--------------------------------------------------cdbebc----------cdcfca----------b8b5------------d1d8------------bb--b9----------cb--ce' +let s:i_cp437='----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------115191626090a222a08242815005455415445519260a288aa82a88aa894698640609182466994114' + +let s:scriptfile=expand("<sfile>:h") + +" +" Activate mode. Assigned to ,b macro. +" +fu! <SID>S() + if has("gui_running") + " se enc=utf8 + en + let s:ve=&ve + setl ve=all + " Note that typical terminal emulator program (Putty, in particular) does + " not support Shift arrows too good. You will, probably, have to redefines + " those to, say, + " ,<Up> etc. + if has("win32") + " Under Windows Shift+Arrows works quite smooth, unlike most terminals + nm <S-Up> :call <SID>M(1,'k')<CR> + nm <S-Down> :call <SID>M(16,'j')<CR> + nm <S-Left> :call <SID>M(64,'h')<CR> + nm <S-Right> :call <SID>M(4,'l')<CR> + nm g<Up> :call <SID>G(0)<CR> + nm g<Right> :call <SID>G(1)<CR> + nm g<Down> :call <SID>G(2)<CR> + nm g<Left> :call <SID>G(3)<CR> + vm <S-Up> <esc>:call <SID>MB('k')<CR> + vm <S-Down> <esc>:call <SID>MB('j')<CR> + vm <S-Left> <esc>:call <SID>MB('h')<CR> + vm <S-Right> <esc>:call <SID>MB('l')<CR> + else + nm <Up> :call <SID>M(1,'k')<CR> + nm <Down> :call <SID>M(16,'j')<CR> + nm <Left> :call <SID>M(64,'h')<CR> + nm <Right> :call <SID>M(4,'l')<CR> + nm g<Up> :call <SID>G(0)<CR> + nm g<Right> :call <SID>G(1)<CR> + nm g<Down> :call <SID>G(2)<CR> + nm g<Left> :call <SID>G(3)<CR> + vm <Up> <esc>:call <SID>MB('k')<CR> + vm <Down> <esc>:call <SID>MB('j')<CR> + vm <Left> <esc>:call <SID>MB('h')<CR> + vm <Right> <esc>:call <SID>MB('l')<CR> + en + vmap <Leader>a :ToAscii<cr> + nm <Leader>e :call <SID>E()<CR> + nm <Leader>s :call <SID>SetLT(1)<CR> + nm <Leader>d :call <SID>SetLT(2)<CR> + exec "cabbr <"."buffer> perl perl ".s:scriptfile + + let s:bdlt=1 + nm <Leader>b x + nun <Leader>b +endf + +fu! s:SetLT(thickness) + let s:bdlt=a:thickness +endf + +" Deactivate mode. +" Unmap macros, restore &ve option +fu! <SID>E() + if has("win32") + " Under Windows Shift+Arrows works quite smooth, unlike most terminals + nun <S-Up> + nun <S-Down> + nun <S-Left> + nun <S-Right> + nun g<Up> + nun g<Right> + nun g<Down> + nun g<Left> + vu <S-Up> + vu <S-Down> + vu <S-Left> + vu <S-Right> + else + nun <Up> + nun <Down> + nun <Left> + nun <Right> + nun g<Up> + nun g<Right> + nun g<Down> + nun g<Left> + vu <Up> + vu <Down> + vu <Left> + vu <Right> + en + nun <Leader>e + nm <buffer> <Leader>b :call <SID>S()<CR> + cuna <buffer> perl + let &ve=s:ve + unlet s:ve + "echo "Finished Boxdrawing mode" +endf + +fu! s:GetBoxCode(char) + " check if symbol from unicode boxdrawing range + " E2=1110(0010) + " 25= 10(0101)xx + if 'utf-8'== &enc + if(0xE2==char2nr(a:char[0])&&0x25==char2nr(a:char[1])/4) + retu '0x'.strpart(s:i_utf8,2*(char2nr(a:char[1])%4*64+char2nr(a:char[2])%64),2) + en + else " Assume cp437 encoding + retu '0x'.strpart(s:i_cp437,2*char2nr(a:char),2) + en + retu 0 +endf + +" Try neihgbour in direction 'd' if c is true. Mask m for the direction +" should also be supplied. +" Function returns neighboring bit +" Unicode entries are encoded in utf8 as +" 7 bit : 0vvvvvvv +" 11 bit : 110vvvvv 10vvvvvv +" 16 bit : 1110vvvv 10vvvvvv 10vvvvvv +fu! s:T(c,d,m) + if(a:c) + exe 'norm mt'.a:d.'"tyl`t' + let c=s:GetBoxCode(@t) + retu c%a:m*4/a:m + en + retu 0 +endf + +" 3*4^x, where x=0,1,2,3 +" fu! s:Mask(x) +" retu ((6+a:x*(45+a:x*(-54+a:x*27)))/2) +" endf + +" Move cursor (follow) in specified direction +" Return new direction if new position is valid, -1 otherwise +" dir: 'kljh' +" ^>V< +" 0123 +" mask: 3 12 48 192 +" let @x=3|echo (6+@x*(45+@x*(-54+@x*27)))/2 +" +fu! <SID>F(d) + exe 'norm '.('kljh'[a:d]).'"tyl' + let c=s:GetBoxCode(@t) + let i=0 + let r=-1 + while i<4 + if 0!=c%4 && a:d!=(i+2)%4 + if r<0 + let r=i + else + retu -1 + endif + endif + let c=c/4 + let i=i+1 + endw + retu r +endf + +fu! <SID>G(d) + let y=line(".") + let x=virtcol(".") + let n=a:d + while n>=0 + let n=s:F(n) + if y==line(".") && x==virtcol(".") + echo "Returned to same spot" + break + endif + endw +endf + +" Move cursor in specified direction (d= h,j,k or l). Mask s for +" the direction should also be supplied +" +fu! <SID>M(s,d) + let t=@t + let x=s:T(1<col("."),'h',16)*64+s:T(line(".")<line("$"),'j',4)*16+s:T(1,'l',256)*4+s:T(1<line("."),'k',64) + let @t=t + let c=a:s*s:bdlt+x-x%(a:s*4)/a:s*a:s + "echo 'need c='.c.' x='.x + if 'utf-8'==&enc + let o=strpart(s:o_utf8,2*c,2) + if o!='--' && o!='' + exe "norm r\<C-V>u25".o.a:d + en + else + let o=strpart(s:o_cp437,2*c,2) + if o!='--' && o!='' + exe "norm r\<C-V>x".o.a:d + en + en +" "echo "Boxdrawing mode" +endf + +scriptencoding utf8 +command! -range ToAscii :silent <line1>,<line2>s/┌\|┬\|┐\|╓\|╥\|╖\|╒\|╤\|╕\|╔\|╦\|╗\|├\|┼\|┤\|╟\|╫\|╢\|╞\|╪\|╡\|╠\|╬\|╣\|└\|┴\|┘\|╙\|╨\|╜\|╘\|╧\|╛\|╚\|╩\|╝/+/ge|:silent <line1>,<line2>s/[│║]/\|/ge|:silent <line1>,<line2>s/[═─]/-/ge + +command! -range ToHorz :<line1>,<line2>s/─\|═/-/g +command! -range ToHorz2 :<line1>,<line2>s/─/-/g +" 0000000: 636f 6d6d 616e 6421 202d 7261 6e67 6520 command! -range +" 0000010: 546f 486f 727a 203a 3c6c 696e 6531 3e2c ToHorz :<line1>, +" 0000020: 3c6c 696e 6532 3e73 2fe2 9480 5c7c e295 <line2>s/...\|.. +" 0000030: 9029 2f6f 2f67 0d0a .)/o/g.. +command! -range ToVert :<line1>,<line2>s/│\|║/\|/g + +" Move block dispatch +fu! s:MB(d) + if visualmode()=='' || visualmode()=='v' + call s:MRB(a:d) + elseif visualmode()=='V' + call s:MLB(a:d) + en +endf + +" Move line block +fu! s:MLB(d) + if a:d=='j' || a:d=='k' + let l:cmd= "norm gv\"yd".a:d."\"yP1V" + exe l:cmd + elseif a:d=='h' + normal gv + :'<,'>s/^.// + normal gv + elseif a:d=='l' + normal gv + :'<,'>s/^/ / + normal gv + en +endf + +" Move Rectangular block +" sideeffect: stores contents of a block in "y +" 1<C-V> does not work good in 6.0 when multibyte characters are involved +" gvp does not work good ... +" gv also has some problems +" See http://vim.sourceforge.net/tips/tip.php?tip_id=808 for different way to +" paste +fu! s:MRB(d) + " It seems that rectangular boxes and multibyte do not live together too + " good asof version 6.3 + " Normally something like + " exe 'norm gv"yygvr '.a:d.'1<C-V>"ypgv' + " should have worked + let l:y1=line(".") + let l:x1=virtcol(".") + "echo l:x1."-".l:y1 + normal gv"yygvo + let l:y2=line(".") + let l:x2=virtcol(".") + if l:x1>l:x2 | let l:t=l:x1 | let l:x1=l:x2 | let l:x2=l:t | endif + if l:y1>l:y2 | let l:t=l:y1 | let l:y1=l:y2 | let l:y2=l:t | endif + let l:pos=l:y1."G0" + if 1<l:x1 | let l:pos=l:pos.(l:x1-1)."l" | endif + let l:size="" + if 0<l:y2-l:y1 | let l:size=l:size.(l:y2-l:y1)."j" | endif + if 0<l:x2-l:x1 | let l:size=l:size.(l:x2-l:x1)."l" | endif + exe "normal gvr ".l:pos.a:d."".l:size."d\"yPgvjk" +endf + + +:nmap <buffer> ,b :call <SID>S()<CR> +if has("win32") + " Under win32 activate boxdrwaing mode upon start. + " If undesirable, prepend with :nmap ,b + " + :normal ,b +else +en diff --git a/vim/boxdraw/outline.pl b/vim/boxdraw/outline.pl new file mode 100644 index 0000000..f095e7f --- /dev/null +++ b/vim/boxdraw/outline.pl @@ -0,0 +1,74 @@ +# outlines groups of similar characters
+# 2003-11-24 15:07:28 Created by nsg
+# 2004-06-18 14:29:45 changed hex boxset to x; added double, horz, vert boxsets
+use strict;
+use utf8;
+use Getopt::Std;
+
+our (
+ $opt_s, # boxset (x=hex)
+ $opt_d, # double each input character
+ $opt_e, # output encoding
+);
+getopts("s:de:");
+$opt_s='s' if '' eq $opt_s;
+$opt_e='utf8' if '' eq $opt_e;
+
+binmode (STDIN, ":encoding($opt_e)");
+binmode (STDOUT, ":encoding($opt_e)");
+#binmode (STDOUT, ":encoding(utf8)");
+my $p='';
+
+my %boxset=(
+# 1|.,'}\u{25',"1 (_2 ]\ o_utf8) {~ 4#.2*#:i.16
+ 's'=>" \x{2502}\x{2500}\x{2514}\x{2502}\x{2502}\x{250c}\x{251c}\x{2500}\x{2518}\x{2500}\x{2534}\x{2510}\x{2524}\x{252c}\x{253c}\n",
+ 'd'=>" \x{2551}\x{2550}\x{255a}\x{2551}\x{2551}\x{2554}\x{2560}\x{2550}\x{255d}\x{2550}\x{2569}\x{2557}\x{2563}\x{2566}\x{256c}\n",
+ 'h'=>" \x{2502}\x{2550}\x{2558}\x{2502}\x{2502}\x{2552}\x{255e}\x{2550}\x{255b}\x{2550}\x{2567}\x{2555}\x{2561}\x{2564}\x{256a}\n",
+ 'v'=>" \x{2551}\x{2500}\x{2559}\x{2551}\x{2551}\x{2553}\x{255f}\x{2500}\x{255c}\x{2500}\x{2568}\x{2556}\x{2562}\x{2565}\x{256b}\n",
+);
+
+my $BOX=$boxset{$opt_s} || $boxset{'s'};
+
+# corners/splits:
+# ┌┬┐╓╥╖╒╤╕╔╦╗ 6ec
+# ├┼┤╟╫╢╞╪╡╠╬╣ 7fd
+# └┴┘╙╨╜╘╧╛╚╩╝ 3b9
+# round corners:
+# 256d 256e
+# 2570 256f
+# horizontal
+# ═ ─
+# vertical
+# │ ║
+
+while(<STDIN>){
+ chomp;
+ s/./$&$&/g if $opt_d;
+ process_line();
+ $p=$_;
+}
+$_='';
+process_line();
+
+sub process_line
+{
+ my $out;
+ my $l=length;
+ $l=length($p) if length($p)>$l;
+ for my$i(0..$l) {
+ my $c=0;
+ $c|=1 if sc($p,$i-1) ne sc($p,$i);
+ $c|=2 if sc($p,$i) ne sc($_,$i);
+ $c|=4 if sc($_,$i) ne sc($_,$i-1);
+ $c|=8 if sc($_,$i-1) ne sc($p,$i-1);
+ $out.=substr($BOX,$c,1) if 'x' ne $opt_s;
+ $out.=sprintf"%1x",$c if 'x' eq $opt_s;
+ }
+ print "$out\n";
+}
+
+sub sc # (str, index)
+{
+ return ' ' if 0>$_[1] || $_[1]>=length($_[0]);
+ return substr($_[0],$_[1],1);
+}
diff --git a/vim/boxdraw/sampler.txt b/vim/boxdraw/sampler.txt new file mode 100644 index 0000000..1f6aad8 --- /dev/null +++ b/vim/boxdraw/sampler.txt @@ -0,0 +1,13 @@ +Box drawing characters sampler. (C) nsg, 2004
+╒╕╔╗╓╖┌╥─┐
+├┼╢║╟╜└╫┬┤ utf-8
+╞╪╣╠╩╤╦╬╡│
+╘╧╝╚═╛╙╨┴┘
+
+ koi8-r, koi8-u*
+
+
+ոɻֿ·
+öŴٺ cp437 (A.K.A dos), cp737, cp86x, cp85x*, cp895, etc.
+ƾص˹
+ϼн
|