Commits

ZyX_I committed c3d4f2c

@aurum/log: Made :AuLog procinput be able to handle some non-single-key commands

Comments (0)

Files changed (2)

     Note: if you somehow switch buffers while log is being generated then 
           buffer with generated log will be wiped out, log generation will 
           stop.
+    Note: Input is processed between generating two revisions. As generator is 
+          normally much faster then you, then you are limited to single 
+          character commands. There is a hack though that allows you to bypass 
+          this problem: if you input “g” or “z” logger won’t execute your 
+          command until it receives next character, it will also wait for <CR> 
+          ("\r" or "\n") or <Esc> after you input “/”, “?” or “:”.
 
 recheight                                                  *g:aurum_recheight*
     VimL |expression| that evaluates to unsigned integer or unsigned integer. 

plugin/aurum/log.vim

     return ((a==b)?(0):((a>b)?(-1):(1)))
 endfunction
 let s:_functions+=['s:DateCmp']
+"▶2 iterfuncs.csshow
+let s:iterfuncs.csshow={}
+"▶3 iterfuncs.csshow.setup :: procinput → d
+function s:iterfuncs.csshow.setup(procinput)
+    return {     'input': '',
+           \ 'skipuntil': 0,
+           \       'buf': bufnr('%'),
+           \'lastw0line': -1,
+           \ 'didredraw': 0,
+           \ 'procinput': a:procinput,}
+endfunction
+"▶3 iterfuncs.csshow.next
+function s:iterfuncs.csshow.next(d)
+    if !a:d.didredraw
+        let haschar=getchar(1)
+        if haschar || (line('$')>=line('w0')+winheight(0))
+            redraw
+            let a:d.didredraw=!haschar
+            let a:d.lastw0line=line('w0')
+        endif
+    endif
+    if !a:d.procinput
+        return
+    endif
+    while getchar(1)
+        let char=getchar()
+        if type(char)==type(0)
+            let char=nr2char(char)
+        endif
+        let a:d.input.=char
+        if a:d.skipuntil isnot 0
+            if eval(a:d.skipuntil)
+                let a:d.skipuntil=0
+            endif
+        elseif char is# 'g' || char is# 'z'
+            let a:d.skipuntil='len(a:d.input)>='.(len(a:d.input)+1)
+        elseif stridx('/?:', char)!=-1
+            let a:d.skipuntil=
+                        \'match(a:d.input, "[\n\r\e]", '.len(a:d.input).')!=-1'
+        endif
+    endwhile
+    if !empty(a:d.input) && (a:d.skipuntil is 0 || eval(a:d.skipuntil))
+        let a:d.skipuntil=0
+        execute 'normal' a:d.input
+        let a:d.input=''
+        if bufnr('%')==a:d.buf
+            let lw0=line('w0')
+            if lw0!=a:d.lastw0line
+                redraw
+                let a:d.didredraw=(line('$')>=lw0+winheight(0))
+                let a:d.lastw0line=lw0
+            endif
+        else
+            if bufexists(a:d.buf)
+                execute 'silent bwipeout!' a:d.buf
+            endif
+            call s:_f.throw('ebuf')
+        endif
+    endif
+endfunction
+"▶3 iterfuncs.csshow.finish
+function s:iterfuncs.csshow.finish(d)
+    if !empty(a:d.input)
+        return feedkeys(a:d.input)
+    endif
+endfunction
 "▶2 glog.graphlog
 function s:F.glog.graphlog(repo, opts, csiterfuncs, bvar, read)
     "▶3 Get grapher
         let a:bvar.rectangles=rectangles
         let a:bvar.specials=specials
         let a:bvar.csstarts=csstarts
-        let didredraw=0
-        let procinput=a:bvar.procinput
-        let lastw0line=-1
-        let buf=bufnr('%')
+        let sd=s:iterfuncs.csshow.setup(a:bvar.procinput)
     endif
     "▶3 Initialize iterator functions
     let ld=literfuncs.start(a:repo,a:opts,[a:repo.functions.getworkhex(a:repo)])
                         else
                             call append('$', lines)
                         endif
-                        "▶4 Process user input
-                        if didredraw
-                            if procinput && getchar(1)
-                                let input=''
-                                while getchar(1)
-                                    let char=getchar()
-                                    if type(char)==type(0)
-                                        let input.=nr2char(char)
-                                    else
-                                        let input.=char
-                                    endif
-                                endwhile
-                                execute 'normal' input
-                                if bufnr('%')!=buf
-                                    if bufexists(buf)
-                                        execute 'silent bwipeout!' buf
-                                    endif
-                                    call s:_f.warn('ebuf')
-                                    return []
-                                endif
-                                let lw0=line('w0')
-                                if lw0!=lastw0line
-                                    redraw
-                                    let didredraw=(line('$')>=lw0+winheight(0))
-                                    let lastw0line=lw0
-                                endif
-                            endif
-                        "▶4 Redraw if necessary
-                        elseif line('$')>=line('w0')+winheight(0)
-                            redraw
-                            let didredraw=1
-                            let lastw0line=line('w0')
-                        endif
                         "▲4
+                        call s:iterfuncs.csshow.next(sd)
                     endif
                     "▲3
                     unlet rectangle special
         endif
         unlet cs
     endwhile
+    call s:iterfuncs.csshow.finish(sd)
     return r
 endfunction
 "▶1 iterfuncs: loggers