Vedeu
Vedeu is my attempt at creating a terminal based application framework without the need for Ncurses. I've tried to make Vedeu as simple and flexible as possible.
Requirements
Vedeu has been built on MacOSX 10.9 (Mavericks) with Ruby v2.1.2.
Note: You may have trouble running Vedeu with Windows installations.
Installation
Add this line to your application's Gemfile:
gem 'vedeu'
And then execute:
$ bundle
Example
Have a look at: Playa. Please browse the source of Playa and Vedeu to get a feel for how it all works. The RubyDoc may also help!
Usage
Expect proper documentation soon!
Getting Started
The basic mechanics of a Vedeu app are outlined below:
require 'vedeu'
class MyApp
include Vedeu
interface 'main' do
...
end
event :some_event do
# ...
end
event :other_event do |hash_args, array_args, args|
# ...
end
keys do
key('a') { trigger(':apple') }
key('b') { trigger(':banana') }
end
end
Building Interfaces & Views
Views with Vedeu are made up of simple building blocks. These blocks can be arranged in a multitude of ways which I hope is more than sufficient for your design needs.
- A view (
Composition) is made up of one or more interfaces. - An interface is an area on the screen where you can take input or direct output. You will define it's colour and style, its dimensions, including position and give it a name. You can then direct the output of a command, or event, to this interface and Vedeu will ensure the content is placed there.
- Interfaces (
Interface) are made up of lines (Line), their length being the width of the interface and their number being the height of the interface. - An interface with
width: 12, height: 5will have five lines, each made of 12 characters- providing 60 cells. Colours and styles are handled by terminal escape sequences and therefore do not consume a cell. - Lines are made up of zero, one or multiple streams (
Stream) which are basically subsets of the line. - An interface, line or stream can have a colour (
colour) attribute. - An interface, line or stream can have a style (
style) attribute. - Interfaces have a position (
y,x) on the screen, and a size. (width,height) - Interfaces can be placed relative to each other based on their attributes.
- An interface has a
top,right,bottom,left. - An interface also has a
northandwest(topandleftminus 1 respectively). - An interface also has a
southandeast(bottomandrightplus 1 respectively).
- An interface has a
- Colours are defined in CSS-style values, i.e.
#ff0000would be red. - Styles are named. See the table below for supported styles.
On Defining Interfaces
interface 'main' do
y 1
x 1
width 10 # see notes below
height 10
colour foreground: '#ffffff', background: '#000000'
end
Referring to the above example, interfaces have a name, and various default attributes.
ysets the starting row point. (See Geometry)xsets the starting column point.widthsets the character width of the interfaceheightsets the character height of the interface
Note: not setting a width or height will set the values to the terminal's reported width and height.
foregroundsets the default foreground colour. (See Colours)backgroundsets the default background colour.
Events
More information about events can be found here: Vedeu Events
Geometry
Geometry for Vedeu, as the same for ANSI terminals, is set top-left, which is cell/point 1, 1. Interfaces themselves have internal geometry which is handled automatically. Unless you are doing something special, you will probably only set it on a per-interface basis.
Colours
Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the stream level, the line level or for the whole interface. Terminals generally support either 8, 16 or 256 colours, with few supporting full 24-bit colour. Vedeu attempts to detect the colour depth using the $TERM environment variable.
To set your $TERM variable to allow 256 colour support:
echo "export TERM=xterm-256color" >> ~/.bashrc
or, if you wish not to tamper with $TERM:
echo "export VEDEU_TERM=xterm-256color" >> ~/.bashrc
If you know your terminal supports full 24-bit colour, set the $VEDEU_TERM environment variable:
echo "export VEDEU_TERM=xterm-truecolor" >> ~/.bashrc
Styles
Vedeu has a range of symbol styles which are compatible with most terminals which are ANSI compatible. Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
Debugging & Environment Variables
Vedeu has two types of debugging; VEDEU_DEBUG and VEDEU_TRACE. Both of these can be configured at run-time using the arguments you pass to your application. They can also be enabled/disabled globally by setting environment variables (see below). These messages are written to ~/.vedeu/vedeu.log.
To enable or disable, use true or false:
echo "export VEDEU_DEBUG=true" >> ~/.bashrc
echo "export VEDEU_TRACE=true" >> ~/.bashrc
Debugging (VEDEU_DEBUG) provides helpful messages which inform you what is happening in the application. Tracing (VEDEU_TRACE) is a noisy, blow-by-blow account of what is happening, letting you know which methods were called and which events have been triggered. Both (more so with tracing) can impact the performance of your application.
Development / Contributing
Pull requests are very welcome! Please try to follow these simple rules if applicable:
- Please create a topic branch for every separate change you make.
- Make sure your patches are well tested.
- Update the Yard documentation.
- Update the README.
- Please do not change the version number.
Any branch on the repository that is not master is probably experimental; do not rely on anything in these branches.
General contribution help
- Fork it (https://github.com/gavinlaking/vedeu/fork)
- Clone it
- Run
bundle - Run
rake(runs all tests and coverage report) orbundle exec guard - Create your feature branch (
git checkout -b my-new-feature) - Write some tests, write some code, have some fun!
- Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new pull request.
