Search code examples
javascriptcssvimperator

Hide liberator-bottombar only if not command's output available. (Vimperator)


What I'm trying to do is this, but if I'm executing some command, and that command has an output, I also want to be able to see the command's output, so, here is what I've done:

"javascript to hide statusbar
noremap <silent> <F8> :js toggle_bottombar()<CR>
noremap : :js toggle_bottombar('on', true)<CR>:
noremap b :js toggle_bottombar('on')<CR>b
noremap o :js toggle_bottombar('on')<CR>o
noremap O :js toggle_bottombar('on')<CR>O
noremap t :js toggle_bottombar('on')<CR>t
noremap T :js toggle_bottombar('on')<CR>T
noremap / :js toggle_bottombar('on')<CR>/
cnoremap <CR> <CR>:js toggle_bottombar('off')<CR>
cnoremap <Esc> <Esc>:js toggle_bottombar('off')<CR>

:js << EOF 

var executing_command = false;

function toggle_bottombar(p, command) {
  var bb = document.getElementById('liberator-bottombar');
  if (!bb)
    return;
if (p == 'on'){
    executing_command = (command === true) ? true : false; 
    bb.style.height = ''; 
    bb.style.overflow = ''; 
    return;
}   
if (p == 'off'){
    if (!executing_command){
        bb.style.height = '0px';
        bb.style.overflow = 'hidden';
    } else {
        toggle_bottombar('on');             
    }  
    return;
}   

bb.style.height = (bb.style.height == '') ? '0px' : ''; 
bb.style.overflow = (bb.style.height == '') ? '' : 'hidden';
}
toggle_bottombar();
EOF

And that half-works because when I type a command it keeps showing the status bar after I press enter but the output is missing, do you have any ideas for reaching this?

I tried with :help style but that doesn't help too much... not enough docs in there.


Solution

  • I finally reached what I was trying to. With this little changes you can see commands' outputs and keep the auto-hide functionality.

    noremap <silent> <F8> :js toggle_bottombar()<CR>
    noremap : :js toggle_bottombar('on')<CR>:
    noremap b :js toggle_bottombar('on')<CR>b
    noremap o :js toggle_bottombar('on')<CR>o
    noremap O :js toggle_bottombar('on')<CR>O
    noremap t :js toggle_bottombar('on')<CR>t
    noremap T :js toggle_bottombar('on')<CR>T
    noremap / :js toggle_bottombar('on')<CR>/
    noremap <Esc> <Esc>:js toggle_bottombar('off')<CR>
    cnoremap <CR> <CR>:js toggle_bottombar('off')<CR>
    cnoremap ` <CR> g<
    
    :js << EOF
    function toggle_bottombar(p) {
         var bb = document.getElementById('liberator-bottombar');
         if (!bb)
             return;
        if (p == 'on'){
            bb.style.height = '';
            bb.style.overflow = '';
            return;
        }   
        if (p == 'off'){
            bb.style.height = '0px';
            bb.style.overflow = 'hidden';
            return;
          }
    
         bb.style.height = (bb.style.height == '') ? '0px' : '';
         bb.style.overflow = (bb.style.height == '') ? '' : 'hidden';
    }       
    toggle_bottombar();
    EOF 
    

    This vimperator's doc guided me to the answer: liberator://help/message#more-prompt, and if you play with liberator components within vimperator's console, it is pretty much self explanatory.

    The only disadvantage of doing this, is that whenever you want to see a command's output you need to use "`" (tilda), but i couldn't figure out a better way.

    Note: It is necessary to press <Esc> two times for hiding entirely bottombar from command's output, first time command-line is hided and bottombar is showed, second time it does what it was desired. I guess it isn't the cleanest way to do it, but that doesn't belong to the original issue.