Thursday, June 19, 2014

Custom Vorax Status Line

Vorax does a pretty well job when it comes to display the status line of the output window. It shows a lot of stuff like: the current output funnel (PAGEZIP, VERTICAL or TABLEZIP), the APPEND or STICKY flag and, of course, the current Oracle connection.


However, it looks a bit too minimalist, especially with all these nice statusline management plugins around:
I've played a little with all the above plugins and in the end I decided on Airline. Even Lighline is more KISS oriented, I didn't want to spend too much time on configuring everything: NERDTree, quickfix window etc. Unlike Lighline, Airline is designed to be extensible and plugins like NERDTree, vim-fugitive etc. may contribute with their own airline extensions in order to configure the look of the status line.

So, below is Vorax with airline:


It'a nice improvement, and the information from the status line is better highlighted. In addition, I configured the current Oracle connection to be also displayed in a Vorax buffer (sql or plsql), just to be sure we know where we're connected to, especially if the output window is not shown (it can be toggled, I'm sure you know this).

So, let's see how we can achieve this. I put the following in my .vimrc file:

" Let me choose the statusbar
let g:vorax_output_force_overwrite_status_line = 0

function! VoraxOutputFlags()
  let funnel = ["", "VERTICAL", "PAGEZIP", "TABLEZIP"][vorax#output#GetFunnel()]
  let append = g:vorax_output_window_append ? "APPEND" : ""
  let sticky = g:vorax_output_window_sticky_cursor ? "STICKY" : ""
  let heading = g:vorax_output_full_heading ? "HEADING" : ""
  let top = g:vorax_output_cursor_on_top ? "TOP" : ""
  return join(filter([funnel, append, sticky, heading, top], 'v:val != ""'), ' ')
endfunction

function! VoraxAirPlugin(...)
  let session = '%{vorax#sqlplus#SessionOwner()}'
  let txn = '%{vorax#utils#IsOpenTxn() ? "!" . g:vorax_output_txn_marker : ""}'
  if vorax#utils#IsVoraxBuffer()
    let w:airline_section_b = get(w:, 'airline_section_b', g:airline_section_b) . session
    let w:airline_section_warning = get(w:, 'airline_section_warning', g:airline_section_warning) . txn
  endif
  if &ft == 'outputvorax'
    let lrows = '%{exists("g:vorax_limit_rows") ? " [LIMIT ROWS <=" . g:vorax_limit_rows . "] " : ""}'
    let w:airline_section_a = '%{vorax#utils#Throbber()}'
    let w:airline_section_b = airline#section#create_left([session])
    let w:airline_section_c = 'Output window'
    let w:airline_section_x = ''
    let w:airline_section_y = g:airline_section_z
    let w:airline_section_z = airline#section#create(["%{VoraxOutputFlags()}"])
    let w:airline_section_warning = get(w:, 'airline_section_warning', g:airline_section_warning)
    let w:airline_section_warning .= airline#section#create([lrows, txn])
  elseif (&ft == 'connvorax') || (&ft == 'explorervorax') || (&ft == 'oradocvorax')
    let w:airline_section_a = ''
    let w:airline_section_b = ''
    let w:airline_section_c = (&ft == 'connvorax' ? 'Connection Profiles' : &ft == 'explorervorax' ? 'DB Explorer' : 'Oracle Documentation')
    let w:airline_section_x = ''
    let w:airline_section_y = ''
    let w:airline_section_z = ''
  endif
endfunction
call airline#add_statusline_func('VoraxAirPlugin')

" Let the statusbar as it is for inactive windows
let g:airline_inactive_collapse=0
That's all! The next logical step would be to defeat my lazyness and submit a real Airline extension for Vorax. I'm going to add this to my procrastination list.

7 comments:

Anonymous said...

I am getting following syntax error from bash:
bash: /home/chris/.bashrc: line 53: syntax error near unexpected token `('
bash: /home/chris/.bashrc: line 53: ` let w:airline_section_z = airline#section#create(["%{VoraxOutputFlags()}"])'

Alexandru Tică said...

In .bashrc?

chris goxp said...

yes,
bash 4.3.33

Alexandru Tică said...

Wasn't it supposed that vim code to go in your .vimrc file (instead of .bashrc)? Am I miss something?

chris goxp said...

I missed that :)

thanks for your help

Alexandru Tică said...

No problem! Have fun!

vijay peddireddy said...

Hi Alexandru Tică

I just wanted to say Thank you Thank you Thank you, ....... for developing this awesome tool .