color_scheme.rb
Created by Richard LeBer on 2011-06-27. Copyright 2011. All rights reserved
This is Free Software. See LICENSE and COPYING for details
VERSION | = | "1.6.21".freeze | The version of the installed library. | |
ERASE_LINE_STYLE | = | Style.new(:name=>:erase_line, :builtin=>true, :code=>"\e[K") | Embed in a String to clear all previous ANSI sequences. This MUST be done before the program exits! | |
ERASE_CHAR_STYLE | = | Style.new(:name=>:erase_char, :builtin=>true, :code=>"\e[P") | ||
CLEAR_STYLE | = | Style.new(:name=>:clear, :builtin=>true, :code=>"\e[0m") | ||
RESET_STYLE | = | Style.new(:name=>:reset, :builtin=>true, :code=>"\e[0m") | ||
BOLD_STYLE | = | Style.new(:name=>:bold, :builtin=>true, :code=>"\e[1m") | ||
DARK_STYLE | = | Style.new(:name=>:dark, :builtin=>true, :code=>"\e[2m") | for example bold black. Bold without a color displays the system-defined bold color (e.g. red on Mac iTerm) | |
UNDERLINE_STYLE | = | Style.new(:name=>:underline, :builtin=>true, :code=>"\e[4m") | ||
UNDERSCORE_STYLE | = | Style.new(:name=>:underscore, :builtin=>true, :code=>"\e[4m") | ||
BLINK_STYLE | = | Style.new(:name=>:blink, :builtin=>true, :code=>"\e[5m") | ||
REVERSE_STYLE | = | Style.new(:name=>:reverse, :builtin=>true, :code=>"\e[7m") | ||
CONCEALED_STYLE | = | Style.new(:name=>:concealed, :builtin=>true, :code=>"\e[8m") | ||
STYLES | = | %w{CLEAR RESET BOLD DARK UNDERLINE UNDERSCORE BLINK REVERSE CONCEALED} | ||
BLACK_STYLE | = | Style.new(:name=>:black, :builtin=>true, :code=>"\e[30m", :rgb=>[ 0, 0, 0]) | These RGB colors are approximate; see en.wikipedia.org/wiki/ANSI_escape_code | |
RED_STYLE | = | Style.new(:name=>:red, :builtin=>true, :code=>"\e[31m", :rgb=>[128, 0, 0]) | ||
GREEN_STYLE | = | Style.new(:name=>:green, :builtin=>true, :code=>"\e[32m", :rgb=>[ 0,128, 0]) | ||
BLUE_STYLE | = | Style.new(:name=>:blue, :builtin=>true, :code=>"\e[34m", :rgb=>[ 0, 0,128]) | ||
YELLOW_STYLE | = | Style.new(:name=>:yellow, :builtin=>true, :code=>"\e[33m", :rgb=>[128,128, 0]) | ||
MAGENTA_STYLE | = | Style.new(:name=>:magenta, :builtin=>true, :code=>"\e[35m", :rgb=>[128, 0,128]) | ||
CYAN_STYLE | = | Style.new(:name=>:cyan, :builtin=>true, :code=>"\e[36m", :rgb=>[ 0,128,128]) | ||
WHITE_STYLE | = | Style.new(:name=>:white, :builtin=>true, :code=>"\e[37m", :rgb=>[192,192,192]) | On Mac OSX Terminal, white is actually gray | |
GRAY_STYLE | = | Style.new(:name=>:gray, :builtin=>true, :code=>"\e[37m", :rgb=>[192,192,192]) | Alias for WHITE, since WHITE is actually a light gray on Macs | |
NONE_STYLE | = | Style.new(:name=>:none, :builtin=>true, :code=>"\e[38m", :rgb=>[ 0, 0, 0]) | On Mac OSX Terminal, this is black foreground, or bright white background. Also used as base for RGB colors, if available | |
BASIC_COLORS | = | %w{BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE GRAY NONE} | ||
COLORS | = | colors |
indent_level | [RW] | The indentation level |
indent_size | [RW] | The indentation size |
multi_indent | [RW] | Indentation over multiple lines |
page_at | [R] | The current row setting for paging output. |
wrap_at | [R] | The current column setting for wrapping output. |
This method provides easy access to ANSI color sequences, without the user needing to remember to CLEAR at the end of each sequence. Just pass the string to color, followed by a list of colors you would like it to be affected by. The colors can be HighLine class constants, or symbols (:blue for BLUE, for example). A CLEAR will automatically be embedded to the end of the returned String.
This method returns the original string unchanged if HighLine::use_color? is false.
Create an instance of HighLine, connected to the streams input and output.
A shortcut to HighLine.ask() a question that only accepts "yes" or "no" answers ("y" and "n" are allowed) and returns true or false (true for "yes"). If provided a true value, character will cause HighLine to fetch a single character response. A block can be provided to further configure the question as in HighLine.ask()
Raises EOFError if input is exhausted.
This method is the primary interface for user input. Just provide a question to ask the user, the answer_type you want returned, and optionally a code block setting up details of how you want the question handled. See HighLine.say() for details on the format of question, and HighLine::Question for more information about answer_type and what‘s valid in the code block.
If @question is set before ask() is called, parameters are ignored and that object (must be a HighLine::Question) is used to drive the process instead.
Raises EOFError if input is exhausted.
This method is HighLine‘s menu handler. For simple usage, you can just pass all the menu items you wish to display. At that point, choose() will build and display a menu, walk the user through selection, and return their choice among the provided items. You might use this in a case statement for quick and dirty menus.
However, choose() is capable of much more. If provided, a block will be passed a HighLine::Menu object to configure. Using this method, you can customize all the details of menu handling from index display, to building a complete shell-like menuing system. See HighLine::Menu for all the methods it responds to.
Raises EOFError if input is exhausted.
Executes block or outputs statement with indentation
This method is a utility for quickly and easily laying out lists. It can be accessed within ERb replacements of any text that will be sent to the user.
The only required parameter is items, which should be the Array of items to list. A specified mode controls how that list is formed and option has different effects, depending on the mode. Recognized modes are:
:columns_across: | items will be placed in columns, flowing from left to right. If given, option is the number of columns to be used. When absent, columns will be determined based on wrap_at or a default of 80 characters. |
:columns_down: | Identical to :columns_across, save flow goes down. |
:uneven_columns_across: | Like :columns_across but each column is sized independently. |
:uneven_columns_down: | Like :columns_down but each column is sized independently. |
:inline: | All items are placed on a single line. The last two items are separated by option or a default of " or ". All other items are separated by ", ". |
:rows: | The default mode. Each of the items is placed on its own line. The option parameter is ignored in this mode. |
Each member of the items Array is passed through ERb and thus can contain their own expansions. Color escape expansions do not contribute to the final field width.
The basic output method for HighLine objects. If the provided statement ends with a space or tab character, a newline will not be appended (output will be flush()ed). All other cases are passed straight to Kernel.puts().
The statement parameter is processed as an ERb template, supporting embedded Ruby code. The template is evaluated with a binding inside the HighLine instance, providing easy access to the ANSI color constants and the HighLine.color() method.