11" =============================================================================
22" FILE: interactive.vim
33" AUTHOR: Shougo Matsushita <[email protected] >4- " Last Modified: 25 Dec 2009
4+ " Last Modified: 03 Jun 2009
55" License: MIT license {{{
66" Permission is hereby granted, free of charge, to any person obtaining
77" a copy of this software and associated documentation files (the
@@ -50,6 +50,12 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
5050 " Password input.
5151 set imsearch = 0
5252 let l: in = inputsecret (' Input Secret : ' )
53+
54+ if &termencoding != ' ' && &encoding != &termencoding
55+ " Convert encoding.
56+ let l: in = iconv (l: in , &encoding , &termencoding )
57+ endif
58+
5359 call b: vimproc_sub [0 ].write (l: in . " \<NL> " )
5460 let b: vimproc_is_secret = 0
5561 elseif ! b: vimproc_sub [0 ].eof
@@ -98,13 +104,8 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
98104 " Still nothing? We give up.
99105 if l: prompt_search == 0
100106 echohl WarningMsg | echo " Invalid input." | echohl None
101- " normal! G$
102- " startinsert!
103- " return
104107 endif
105108 endif
106- " Delete input string for echoback.
107- call setline (line (' .' ), getline (' .' )[: - (len (l: in )+ 1 )])
108109
109110 " record command history
110111 if ! exists (' b:interactive_command_history' )
@@ -116,33 +117,60 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
116117 let b: interactive_command_position = 0
117118
118119 try
120+ if &termencoding != ' ' && &encoding != &termencoding
121+ " Convert encoding.
122+ let l: in = iconv (l: in , &encoding , &termencoding )
123+ endif
124+
119125 if l: in = ~ " $"
120126 " EOF.
121127 call b: vimproc_sub [0 ].write (l: in [:-2 ] . s: is_win ? " " : " " )
128+ let b: skip_echoback = l: in [:-2 ]
122129 call vimshell#interactive#execute_pty_out ()
123130
124131 call vimshell#interactive#exit ()
125132 return
126133 elseif l: in = ~ ' \t$'
127134 " Completion.
128135 call b: vimproc_sub [0 ].write (l: in )
136+ let b: skip_echoback = l: in [: -1 ]
129137 elseif l: in != ' ...'
130- if l: in = ~ ' ^\.\.\. '
138+ if l: in = ~ ' ^-> '
131139 " Delete ...
132140 let l: in = l: in [3 :]
133141 endif
134142
135143 call b: vimproc_sub [0 ].write (l: in . " \<NL> " )
144+ let b: skip_echoback = l: in
136145 endif
137146 catch
138147 call b: vimproc_sub [0 ].close ()
139148 endtry
140149 endif
141150
142- call append (line (' $' ), ' ...' )
143- normal ! G$
151+ if getline (' $' ) != ' ...'
152+ call append (line (' $' ), ' ...' )
153+ normal ! G$
154+ endif
144155
145156 call vimshell#interactive#execute_pty_out ()
157+
158+ while b: vimproc_is_secret
159+ " Password input.
160+ set imsearch = 0
161+ let l: in = inputsecret (' Input Secret : ' )
162+
163+ if &termencoding != ' ' && &encoding != &termencoding
164+ " Convert encoding.
165+ let l: in = iconv (l: in , &encoding , &termencoding )
166+ endif
167+
168+ call b: vimproc_sub [0 ].write (l: in . " \<NL> " )
169+ let b: vimproc_is_secret = 0
170+
171+ call vimshell#interactive#execute_pty_out ()
172+ endwhile
173+
146174 if getline (line (' $' )) = ~ ' ^\s*$'
147175 call setline (line (' $' ), ' ...' )
148176 endif
@@ -162,21 +190,30 @@ function! vimshell#interactive#execute_pty_out()"{{{
162190 let l: i = 0
163191 let l: submax = len (b: vimproc_sub ) - 1
164192 let l: outputed = 0
193+ let l: output = ' '
165194 for sub in b: vimproc_sub
166195 if ! sub.eof
167196 let l: read = sub.read (-1 , 40 )
168197 while l: read != ' '
169- if l: i < l: submax
170- " Write pipe.
171- call b: vimproc_sub [l: i + 1 ].write (l: read )
172- else
173- call s: print_buffer (b: vimproc_fd , l: read )
174- redraw
175- endif
198+ let l: output .= l: read
199+ let l: outputed = 1
176200
177201 let l: read = sub.read (-1 , 40 )
178- let l: outputed = 1
179202 endwhile
203+
204+ if l: output != ' '
205+ if exists (' b:skip_echoback' )
206+ if vimshell#head_match (l: output , b: skip_echoback )
207+ let l: output = l: output [len (b: skip_echoback ) :]
208+ else
209+ " Newline.
210+ let l: output = " \<NL> " . l: output
211+ endif
212+ endif
213+
214+ call s: print_buffer (b: vimproc_fd , l: output )
215+ redraw
216+ endif
180217 endif
181218
182219 let l: i += 1
@@ -186,6 +223,7 @@ function! vimshell#interactive#execute_pty_out()"{{{
186223 if ! exists (' b:prompt_history' )
187224 let b: prompt_history = {}
188225 endif
226+
189227 if l: outputed
190228 let b: prompt_history [line (' .' )] = getline (' .' )
191229 endif
@@ -280,7 +318,7 @@ function! vimshell#interactive#force_exit()"{{{
280318 try
281319 " 15 == SIGTERM
282320 call sub.vp_kill (15 )
283- catch /No such process/
321+ catch
284322 endtry
285323 endfor
286324
@@ -330,11 +368,7 @@ function! vimshell#interactive#interrupt()"{{{
330368 endtry
331369 endfor
332370
333- if has (' win32' ) || has (' win64' )
334- call vimshell#interactive#execute_pipe_out ()
335- else
336- call vimshell#interactive#execute_pty_out ()
337- endif
371+ call vimshell#interactive#execute_pty_out ()
338372endfunction " }}}
339373
340374function ! vimshell#interactive#highlight_escape_sequence ()" {{{
@@ -431,7 +465,11 @@ function! s:print_buffer(fd, string)"{{{
431465 return
432466 endif
433467
434- if a: string = ~ s: password_regex
468+ " Convert encoding.
469+ let l: string = (&termencoding != ' ' && &encoding != &termencoding ) ?
470+ \ iconv (a: string , &termencoding , &encoding ) : a: string
471+
472+ if l: string = ~ s: password_regex
435473 " Set secret flag.
436474 let b: vimproc_is_secret = 1
437475 endif
@@ -441,23 +479,16 @@ function! s:print_buffer(fd, string)"{{{
441479 " Nothing.
442480 elseif a: fd .stdout == ' /dev/clip'
443481 " Write to clipboard.
444- let @+ .= a : string
482+ let @+ .= l : string
445483 else
446484 " Write file.
447- let l: file = extend (readfile (a: fd .stdout), split (a : string , ' \r\n\|\n' ))
485+ let l: file = extend (readfile (a: fd .stdout), split (l : string , ' \r\n\|\n' ))
448486 call writefile (l: file , a: fd .stdout)
449487 endif
450488
451489 return
452490 endif
453491
454- " Convert encoding for system().
455- if has (' win32' ) || has (' win64' )
456- let l: string = iconv (a: string , ' cp932' , &encoding )
457- else
458- let l: string = iconv (a: string , ' utf-8' , &encoding )
459- endif
460-
461492 " Strip <CR>.
462493 if getline (line (' $' )) == ' ...'
463494 $delete
@@ -480,28 +511,25 @@ function! s:error_buffer(fd, string)"{{{
480511 return
481512 endif
482513
514+ " Convert encoding.
515+ let l: string = (&termencoding != ' ' && &encoding != &termencoding ) ?
516+ \ iconv (a: string , &termencoding , &encoding ) : a: string
517+
483518 if a: fd .stderr != ' '
484519 if a: fd .stderr == ' /dev/null'
485520 " Nothing.
486521 elseif a: fd .stderr == ' /dev/clip'
487522 " Write to clipboard.
488- let @+ .= a : string
523+ let @+ .= l : string
489524 else
490525 " Write file.
491- let l: file = extend (readfile (a: fd .stderr), split (a : string , ' \r\n\|\n' ))
526+ let l: file = extend (readfile (a: fd .stderr), split (l : string , ' \r\n\|\n' ))
492527 call writefile (l: file , a: fd .stderr)
493528 endif
494529
495530 return
496531 endif
497532
498- " Convert encoding for system().
499- if has (' win32' ) || has (' win64' )
500- let l: string = iconv (a: string , ' cp932' , &encoding )
501- else
502- let l: string = iconv (a: string , ' utf-8' , &encoding )
503- endif
504-
505533 " Print buffer.
506534 " Strip <CR>.
507535 let l: last_line = getline (line (' $' ))
0 commit comments