sponsor Vim development Vim logo Vim Book Ad

forms : Vim Forms TUI libraray

 script karma  Rating 50/16, Downloaded by 4068  Comments, bugs, improvements  Vim wiki

created by
richard emberson
 
script type
utility
 
description
Forms is a Vim TUI (Text User Interface) library. It allows for the creation
and display of text-based forms in both console Vim and GVim. Many of the
standard GUI widget types are supported by Forms such as labels, buttons,
menus and layout constructs. It supports navigation, selection and input with
a keyboard, as well as, navigation and selection with a mouse.

Screen-shot (background: dark/light) of clone of GVim menu/popup:
https://github.com/megaannum/forms/tree/master/images/menu_file.png
https://github.com/megaannum/forms/tree/master/images/menu_edit_colorscheme.png
https://github.com/megaannum/forms/tree/master/images/popup_change.png

Some example (background: dark/light) forms from the "Examples" form:
https://github.com/megaannum/forms/tree/master/images/examples.png
https://github.com/megaannum/forms/tree/master/images/examples_andmorelabels.png
https://github.com/megaannum/forms/tree/master/images/examples_boxchars.png
https://github.com/megaannum/forms/tree/master/images/examples_checkboxes.png
https://github.com/megaannum/forms/tree/master/images/examples_colorchooser.png
https://github.com/megaannum/forms/tree/master/images/examples_confirmchoice.png
https://github.com/megaannum/forms/tree/master/images/examples_dropshodow.png
https://github.com/megaannum/forms/tree/master/images/examples_filebrowser.png
https://github.com/megaannum/forms/tree/master/images/examples_fixedlayout.png
https://github.com/megaannum/forms/tree/master/images/examples_foureditors.png
https://github.com/megaannum/forms/tree/master/images/examples_frames.png
https://github.com/megaannum/forms/tree/master/images/examples_getinput.png
https://github.com/megaannum/forms/tree/master/images/examples_information.png
https://github.com/megaannum/forms/tree/master/images/examples_labelsingrid.png
https://github.com/megaannum/forms/tree/master/images/examples_labels.png
https://github.com/megaannum/forms/tree/master/images/examples_menusubmenu.png
https://github.com/megaannum/forms/tree/master/images/examples_morelabels.png
https://github.com/megaannum/forms/tree/master/images/examples_palletdesigner.png
https://github.com/megaannum/forms/tree/master/images/examples_popdownlist.png
https://github.com/megaannum/forms/tree/master/images/examples_radiobuttons.png
https://github.com/megaannum/forms/tree/master/images/examples_resize.png
https://github.com/megaannum/forms/tree/master/images/examples_runtimepathviewer.png
https://github.com/megaannum/forms/tree/master/images/examples_selectlists.png
https://github.com/megaannum/forms/tree/master/images/examples_sliders.png
https://github.com/megaannum/forms/tree/master/images/examples_subform.png
https://github.com/megaannum/forms/tree/master/images/examples_texteditor.png
https://github.com/megaannum/forms/tree/master/images/examples_textsearch.png
https://github.com/megaannum/forms/tree/master/images/examples_textsearchreplace.png
https://github.com/megaannum/forms/tree/master/images/examples_togglebuttons.png
https://github.com/megaannum/forms/tree/master/images/examples_vimhomeviewer.png
https://github.com/megaannum/forms/tree/master/images/examples_vlabels.png

Code for the above examples can be found at:
https://github.com/megaannum/forms/blob/master/autoload/forms/menu.vim
https://github.com/megaannum/forms/tree/master/autoload/forms/dialog
https://github.com/megaannum/forms/tree/master/autoload/forms/example

Forms tutorial:
https://github.com/megaannum/forms/blob/master/tutorial/forms/Tutorial.md

A user can always stop a form with no side effects by entering <Esc>.
This is basically a "panic button"; the user wants out.
If the user is a couple of sub-forms deep in a presentation, each <Esc>
entered pops the user out of the current form only.
Developers should be aware that a user might not take any of the actions
offered by a form and simply enter <Esc>. Such user action, <Esc>
to exit Forms, should NOT be prevented by a forms developer.

The behavior of a form created with the Forms library differs from that of a
GUI form. Generally, a GUI form can be displayed and moved about anywhere on
the screen. On the other hand, a TUI form has to reside within the Vim/GVim
window; it can not be moved outside of the text area. In addition, when a form
is being displayed, it captures all user input, keyboard and mouse in that
window, so that there is no access to the underlying text until the form is
closed. In that sense, all Forms forms are like modal GUI forms.

Because a form must fit within a text window, it is sometimes the case that
the form's height and/or width is greater than that of the hosting window.
Form developer should be aware of this and strive to make their forms
smaller than expected window sizes. One approach is to break a large form
into a number of sub-forms.
In case a form is too big, an information form is displayed to the user
stating that fact along with a suggested size to enlarge the window to
so that the form will fit. If the window is too small even to display
the information form, an error message is output (via a thrown exception).

A form can be displayed over the current text or the form can create a new tab
and displayed there.

Strictly speaking, the Forms library is a library and, so, there ought not
be any mappings. But, while developing Forms a number of examples were
created which, it turns out, were critical for uncovering bugs, missing
features in the implementation and usage issues. Two of the examples
might have general appeal, the menu and popup forms that mirror the
capability (and copy some of the support code of) the GVim menu and popup.
While power users will disdain the Forms menu and popup examples
as superfluous, covering Vim commands that are know by heart, so to
power users disdain the GVim menu/popup - so, the power user is not
the target user.  Rather, the same users that find the GVim menu/popup
useful will find the Forms menu/popup equally useful.
Here are the mappings for the menu and popup:

    nmap <Leader>m :call forms#menu#MakeMenu('n')<CR>
    vmap <Leader>m :call forms#menu#MakeMenu('v')<CR>
    nmap <Leader>p :call forms#menu#MakePopUp('n')<CR>
    vmap <Leader>p :call forms#menu#MakePopUp('v')<CR>

It should be noted that there are normal and visual mode mappings.
That is because some capabilities of the menu/popup are enabled/disabled
depending upon mode, as well as, which command to ultimately execute
may depend upon mode.

There is also a mapping which launches a form that links to some 40 Forms
demonstration forms. The demonstration forms range from a simple box
drawing example to a file browser and color chooser:

    nmap <Leader>d :call forms#example#demo#Make()<CR>

If any of the demonstration forms do not display or function as one might
expect on your platform, then drop me a line - thanks.

One will observe that these mappings use the characters: 'm' 'p' and 'd'.
While the demo mapping can/should ultimately be commented out by
all but Forms developers, at least for the non-power user, having
a short, easy to remember, mnemonic mapping for menu and popup is certainly
reasonable.

Source can be found at: https://github.com/megaannum/forms

The Forms library is currently being used in the following scripts:
Colorschemer utility
  http://www.vim.org/scripts/script.php?script_id=4240
Vimside, Vim Scala IDE
  http://www.vim.org/scripts/script.php?script_id=4298
 
install details
Download forms.zip and unzip in $HOME/.vim.After unpacking the {Forms} directory
layout should look like:
    $HOME/.vim/
      autoload/
        forms.vim
        forms/
          menu.vim
          dialog/...
          examples/...
      doc/forms.vim
      plugin/forms.vim
      tutorial/forms/...

Intalling with vim-addon-manager (VAM)

For more information about vim-addon-manager, see
[vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager) and
[Vim-addon-manager getting
started](https://github.com/MarcWeber/vim-addon-manager/blob/master/doc/vim-addon-manager-getting-started.txt)

In your .vimrc, add self as shown below:

    fun SetupVAM()
      ...
      let g:vim_addon_manager = {}
      let g:vim_addon_manager.plugin_sources = {}
      ....
      let g:vim_addon_manager.plugin_sources['self'] = {'type': 'git', 'url':
'git://github.com/megaannum/self'}
      let g:vim_addon_manager.plugin_sources['forms'] = {'type': 'git', 'url':
'git://github.com/megaannum/forms'}


      let plugins = [
        \ 'self',
        \ 'forms'
        \ ]

      call vam#ActivateAddons(plugins,{'auto_install' : 0})
      ...
    endf
    call SetupVAM()

Now start Vim. You will be asked by vim-addon-manager
if you would like to download and install the self plugin (no dependencies).

Installing with pathogen

I do not use pathogen. An example usage would be welcome.

Configuring Xterm and .vimrc for Forms

For console-base Vim running in an Xterm, the font used by Vim is the font
used by the Xterm. Running on my Linux systems I found the following
works to launch an Xterm appropriately configured: >
    /usr/bin/xterm -g 80x30 -bg lightgrey -sl 1000 +si -fn \
       '-misc-fixed-medium-r-normal-*-20-*-*-*-*-*-iso10646-*'
If with say, the font 10x20, then you may not be able to render all of
the unicode characters, but it ought to still work.

There is support for 256, 88, 16 and 8 color Xterms though
the 256 looks best. In your .vimrc file add one of:
    if ($TERM == 'xterm')
        let &t_Co=256
    endif
or
    if ($TERM == 'xterm')
        let &t_Co=88
    endif
or
    if ($TERM == 'xterm')
        let &t_Co=16
    endif
or
    if ($TERM == 'xterm')
        let &t_Co=8
    endif

Of course setting the number of colors to 88 for an 8 color xterm will not work.

For Vim urxvt256c (on Linux) the Forms demos work.
Vim knows that  &t_Co == 256.

Forms works with 88 color verion of rxvt that supports Unicode, urxvt.
Vim knows that  &t_Co == 88.

Forms works with non-Unicode, 8 color rxvt.
Vim knows that  &t_Co == 8.

Forms works kconsole (though kconsole's UTF-8 9608 2588 FULL BLOCK does not
render correctly).
Add to .vimrc file:
      let &t_Co=256
      let g:FORMS_COLOR_TERM_KONSOLE = 1

Forms works eterm (well, I hope it works, no access to ETerm so could not test).
Add to .vimrc file:
      let &t_Co=256
      let g:FORMS_COLOR_TERM_ETERM = 1

For GVim (on Linux) the Forms demos work.

It has not been tested on Mac or Window GVim.

See the doc/forms.txt for more information.

The Forms library depends upon the Self library:
http://www.vim.org/scripts/script.php?script_id=3072
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
forms.zip 1.21.2 2013-01-06 7.0 richard emberson Previous version did not have the plugin/forms.vim file (dumb error in my zipper script).
forms.zip 1.21.1 2012-11-29 7.0 richard emberson Commented out log statements in Forest/Node demos.
Fixed finding focus for a Deck.
Form demo now open in tab.
Fixed dotvimviewer demo to display '.vim' dir.
Forms Label checks that 'text' is String or Number.
Add 'hide' method to SelectList to clear selection item highlight.
Fixed 'Form too big' width message.
Removed Deck __textblock and simply space-out deck prior to each draw.
Added NodeViewer (node viewer).
Added ForestViewer/NodeViewer demo.
Added ForestViewer (muilti-hierarchical node viewer).
Replaced IS_TRUE/IS_FALSE with 1/0.
Form Command event not executing properly.
Made all character varibles globals rather than per-buffer.
forms.zip 1.15 2012-10-02 7.3 richard emberson Checkin error: fix tabs and read-only files issues.
forms.zip 1.13 2012-09-28 7.0 richard emberson Added a directory brower dialog.
Fixed file browser dialog so that it returned the correct result.
Fixed Forms event handling so that nested Form could return result to parent Form.
Fixed writing a String consisting of a single multi-byte char.
Added guard to make sure popdown list's select list has select list prior to accessing it.
Changed highlight group names from *Hi to *FORMS_HL
Added method to PopupList to support setting its postion (and the underlying selectlist's position.
Added arrow drawing ASCII and UTF-8 characters
The glyph highlighting methods now have guards to make sure that the highlight actually exists.
Extended poldownlist example
Added <Leader>cc mapping for invoking ColorChooser to plugin
Changed function names in xterm88 to include "88" in names
Added map from color name to rgb values.
If log file in non-writeable directory, write to $HOME directory
Add logforce method which logs by-passing boolean guard
Added autoload action guard let g:forms_reload_highlights_on_colorscheme_event
Add function! g:ShouldLoadeHighlights() which loads
Checks if highlights should be loaded
Added foreground (light/dark) color variables
Added foreground color to some of the highlights
Added function allowing pattern to be directly used in defining highlight
Select list now starts display at it chosen postion, rather than always at 0.
Popdown list now uses Select list (rather than menu) and is some 500 to 1000 faster to build.
Background Glyph now takes optional bacground highlight
If its a read-only-file, then Forms converts it to read-file and on Forms exit restores to read-only
forms.zip 1.6 2012-08-29 7.0 richard emberson Added support for 8 and 16 color terminals.
Works with non-unicode characters sets (there is some degradation).
forms.zip 1.5 2012-08-28 7.0 richard emberson Refactored code, Color utilities and Terminal code in separate files
Refactored code, Highlighting values defined and generated
Corrected XTerm colors
Added urxvt 88 color suport (Color Util and Forms Highlight)
Added Konsole, Eterm and urxvt256c
Highlight colors now configurable
ip used for rating: 3.148.102.90

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github