Screen area and sizes

The screen in AppCUI is a 2D matrix of characters, with different widths (w) and heights (h).

It is important to note that each character is going to have the same size. For each character we have the following attributes:

  • Forenground color (the color of the character that we are printing)
  • Background color (the color of the character background)
  • Attributes: Bold, Italic, Underline, Boxed

The following collors are supported by AppCUI via Color enum from AppCUI::graphics module:

ColorEnum variantRGBColor
BlackColor::BlackRed=0, Green=0, Blue=0
Dark BlueColor::DarkBlueRed=0, Green=0, Blue=128
Dark GreenColor::DarkGreenRed=0, Green=128, Blue=0
Dark RedColor::DarkRedRed=128, Green=0, Blue=0
TealColor::TealRed=0, Green=128, Blue=128
MagentaColor::MagentaRed=128, Green=0, Blue=128
OliveColor::OliveRed=128, Green=128, Blue=0
SilverColor::SilverRed=192, Green=192, Blue=192
GrayColor::GrayRed=128, Green=128, Blue=128
BlueColor::BlueRed=0, Green=0, Blue=255
GreenColor::GreenRed=0, Green=255, Blue=0
RedColor::RedRed=255, Green=0, Blue=0
AquaColor::AquaRed=0, Green=255, Blue=255
PinkColor::PinkRed=255, Green=0, Blue=255
YellowColor::YellowRed=255, Green=255, Blue=0
WhiteColor::WhiteRed=255, Green=255, Blue=255

Besides this list, a special enuma variant Color::Transparent can be used to draw without a color (or in simple terms to keep the existing color). For example, if the current character has a forenground color Red writing another character on the same position with color Transparent will keep the color Red for the character.

Additionally, if the TRUE_COLORS feature is enabled, the following variant is supported:

  • Color::RGB(r, g, b) - this is a custom color that is defined by the RGB values.

REMARKS:

  1. Not all terminals support this exact set of colors. Further more, some terminals might allow changing the RGB color for certain colors in the pallete.
  2. Enabling TRUE_COLORS feature does not mean that the terminal supports 24-bit colors. It only means that the AppCUI framework will use 24-bit colors for the screen, but the terminal might still need to convert them to the terminal's color pallete.
  3. Enabling TRUE_COLORS feature will make the size of the Color enum to be 4 bytes (instead of 1 byte without this feature). If memory is a concern and you don't need true colors, it is recommended to NOT enable this feature.

The list of attributes available in AppCUI are described by CharFlags enum from AppCUI::graphics module and include the following flags:

  • Bold - bolded character
  • Underline - underlined character
  • Italic - italic character

These flags can be used with | operator if you want to combine them. For example: CharFlags::Bold | CharFlags::Underline means a character that is both bolded and underlined.

Character

As previously explained, a character is the basic unit of AppCUI (we can say that it is similar to what a pixel is for a regular UX system). The following method can be used to build a character:

#![allow(unused)]
fn main() {
pub fn new<T>(code: T, fore: Color, back: Color, flags: CharFlags) -> Character
}

where:

  • fore and back are characters colors (foreground and background)
  • code can be a character (like 'a' or 'b') or a value of type SpecialCharacter that can be used to quickly access special characters (like arrows). Any type of UTF-8 character is allowed.
  • flags are a set of flags (like Bold, Underline, ...) that can be used.

The list of all special characters that are supported by AppCUI (as described in the SpacialCharacter enum) are:

Box lines and corners

Variant
(appcui::graphics::SpecialCharacter enum)
Unicode codeVisual Representation
SpecialCharacter::BoxTopLeftCornerDoubleLine0x2554
SpecialCharacter::BoxTopRightCornerDoubleLine0x2557
SpecialCharacter::BoxBottomRightCornerDoubleLine0x255D
SpecialCharacter::BoxBottomLeftCornerDoubleLine0x255A
SpecialCharacter::BoxHorizontalDoubleLine0x2550
SpecialCharacter::BoxVerticalDoubleLine0x2551
SpecialCharacter::BoxCrossDoubleLine0x256C
SpecialCharacter::BoxTopLeftCornerSingleLine0x250C
SpecialCharacter::BoxTopRightCornerSingleLine0x2510
SpecialCharacter::BoxBottomRightCornerSingleLine0x2518
SpecialCharacter::BoxBottomLeftCornerSingleLine0x2514
SpecialCharacter::BoxHorizontalSingleLine0x2500
SpecialCharacter::BoxVerticalSingleLine0x2502
SpecialCharacter::BoxCrossSingleLine0x253C

Arrows

Variant
(appcui::graphics::SpecialCharacter enum)
Unicode codeVisual Representation
SpecialCharacter::ArrowUp0x2191
SpecialCharacter::ArrowDown0x2193
SpecialCharacter::ArrowLeft0x2190
SpecialCharacter::ArrowRight0x2192
SpecialCharacter::ArrowUpDown0x2195
SpecialCharacter::ArrowLeftRight0x2194
SpecialCharacter::TriangleUp0x25B2
SpecialCharacter::TriangleDown0x25BC
SpecialCharacter::TriangleLeft0x25C4
SpecialCharacter::TriangleRight0x25BA

Blocks

Variant
(appcui::graphics::SpecialCharacter enum)
Unicode codeVisual Representation
SpecialCharacter::Block00x20
SpecialCharacter::Block250x2591
SpecialCharacter::Block500x2592
SpecialCharacter::Block750x2593
SpecialCharacter::Block1000x2588
SpecialCharacter::BlockUpperHalf0x2580
SpecialCharacter::BlockLowerHalf0x2584
SpecialCharacter::BlockLeftHalf0x258C
SpecialCharacter::BlockRightHalf0x2590
SpecialCharacter::BlockCentered0x25A0
SpecialCharacter::LineOnTop0x2594
SpecialCharacter::LineOnBottom0x2581
SpecialCharacter::LineOnLeft0x258F
SpecialCharacter::LineOnRight0x2595

Other

Variant
(appcui::graphics::SpecialCharacter enum)
Unicode codeVisual Representation
SpecialCharacter::CircleFilled0x25CF
SpecialCharacter::CircleEmpty0x25CB
SpecialCharacter::CheckMark0x221A
SpecialCharacter::MenuSign0x2261
SpecialCharacter::FourPoints0x205E
SpecialCharacter::ThreePointsHorizontal0x2026

Other character constructors

Besides Character::new(...) the following constructors are also available:

  1. #![allow(unused)]
    fn main() {
     pub fn with_char<T>(code: T) -> Character
    }

    this is the same as calling:

    #![allow(unused)]
    fn main() {
    Character::new(code, Color::Transparent, Color::Transparent, CharFlags::None)
    }
  2. #![allow(unused)]
    fn main() {
     pub fn with_color(fore: Color, back: Color) -> Character
    }

    this is the same as calling:

    #![allow(unused)]
    fn main() {
    Character::new(0, fore, fore, CharFlags::None)
    }

    Note: Using the character with code 0 means keeping the existing character but chainging the colors and attributes.

Macro builds

You can also use char! macro to quickly create a character. The macro supports tha following positional and named parameters:

PositionParameterType
#1 (first)charactercharacter or string (for special chars)
#2 (second)foreground colorColor for foreground (special constants are accepted in this case - see below)
#3 (third)background colorColor for background (special constants are accepted in this case - see below)

and the named parameters:

NameTypeOptionalDescription
value or char or chStringYesThe character or the name or representation of a special character. If string characters ' or " are being used, the content of the string is analyzed. This is useful for when the character is a special token such as : or = or ,. If not specified a special character with value 0 is being used that translates as an invariant character (meaning that it will not modify the existing character, but only its color and attributes.)
code or unicodeHex valueYesThe unicode value of a character. Using this parameter will invalidate the previous parameter
fore or foreground or forecolor or colorColorYesThe foreground color of the character. If not specified it is defaulted to Transparent.
back or background or backcolorColorYesThe background color of the character. If not specified it is defaulted to Transparent.
attr or attributesFlagsYesOne of the following combination: Bold, Italic, Underline

The following values can be used as color parameters for foreground and background parameters:

ValuesColorEnum variantColor
blackBlackColor::Black
DarkBlue or dbDark BlueColor::DarkBlue
DarkGreen or dgDark GreenColor::DarkGreen
DarkRed or drDark RedColor::DarkRed
TealTealColor::Teal
MagentaMagentaColor::Magenta
OliveOliveColor::Olive
Silver or Gray75SilverColor::Silver
Gray or gray50GrayColor::Yellow
Blue or bBlueColor::Blue
Green or gGreenColor::Green
Red or rRedColor::Red
Aqua or aAquaColor::Aqua
PinkPinkColor::Pink
Yellow or yYellowColor::Yellow
White or wWhiteColor::White

For Transparent color you can use the following values: transparent, invisible or ?.

You can also specify special characters by either using their specific name from the enum SpecialChars or by using certaing adnotations as presented in the following table:

ValueVariant
(appcui::graphics::SpecialCharacter enum)
Visual Representation
up or /|\SpecialCharacter::ArrowUp
down or \|/SpecialCharacter::ArrowDown
left or <-SpecialCharacter::ArrowLeft
right or ->SpecialCharacter::ArrowRight
updown or up-downSpecialCharacter::ArrowUpDown
leftright or left-right or
<->
SpecialCharacter::ArrowLeftRight
/\SpecialCharacter::TriangleUp
\/SpecialCharacter::TriangleDown
<|SpecialCharacter::TriangleLeft
|>SpecialCharacter::TriangleRight
...SpecialCharacter::ThreePointsHorizontal

Character attributes

Sometimes, you might want to use a character with a specific color and attributes. For example, you might want to use a bolded character with a red color on a yellow background. This is in particular useful when building a theme where you just select the attributes and colors and then apply them to the characters. AppCUI provides a specific structure called CharAttribute that allows you to define colors and attributes for a character. To create a CharAttribute you can use the following methods:

#![allow(unused)]
fn main() {
impl CharAttribute {
    pub fn new(fore: Color, back: Color, flags: CharFlags) -> CharAttribute {...}
    pub fn with_color(fore: Color, back: Color) -> CharAttribute {...}
    pub fn with_fore_color(fore: Color) -> CharAttribute {...}
    pub fn with_back_color(back: Color) -> CharAttribute {...}
}
}

or the macro charattr! that works similar to char! but it returns a CharAttribute object. The macro supports tha following positional and named parameters:

PositionParameterType
#1 (second)foreground colorColor for foreground (special constants are accepted in this case - see below)
#2 (third)background colorColor for background (special constants are accepted in this case - see below)

and the named parameters:

NameTypeOptionalDescription
fore or foreground or forecolor or colorColorYesThe foreground color of the character. If not specified it is defaulted to Transparent.
back or background or backcolorColorYesThe background color of the character. If not specified it is defaulted to Transparent.
attr or attributesFlagsYesOne of the following combination: Bold, Italic, Underline

Examples

Example 1: Letter A with a Red color on an Yellow background:

#![allow(unused)]
fn main() {
Character::new('A',Color::Red,Color::Yellow,CharFlags::None)
}

or

char!("A,red,yellow")

or

char!("A,r,y")

Example 2: Letter A (bolded and underlined) with a White color on a Dark blue background:

#![allow(unused)]
fn main() {
Character::new('A',Color::White,Color::DarkBlue,CharFlags::Bold | CharFlags::Underline)
}

or

char!("A,fore=White,back=DarkBlue,attr=[Bold,Underline]")

or

char!("A,w,db,attr=Bold+Underline")

Example 3: An arrow towards left a Red color while keeping the current background:

#![allow(unused)]
fn main() {
Character::new(SpecialCharacter::ArrowLeft,Color::Red,Color::Transparent,CharFlags::None)
}

or

char!("ArrowLeft,fore=Red,back=Transparent")

or

char!("<-,red")

or

char!("<-,r")

Example 4: An arrow towards left a DarkGreen color, Bolded and Underlined while keeping the current background. We will use a CharAttribute for this example:

#![allow(unused)]
fn main() {
let attr = CharAttribute::new(Color::DarkGreen,Color::Transparent,CharFlags::Bold | CharFlags::Underline);  
let c = Character::with_attr(SpecialCharacter::ArrowLeft,attr);
}

or

let attr = charattr!("DarkGreen,Transparent,attr:Bold+Underline");
let c = Character::with_attr(SpecialCharacter::ArrowLeft,attr));

or

let attr = charattr!("dg,?,attr:Bold+Underline");
let c = Character::with_attr(SpecialCharacter::ArrowLeft,attr);