termenu

Struct FontStyle

Source
pub struct FontStyle { /* private fields */ }
Expand description

style of font

Examples:

  1. set more than one shape at the same time
let mut style = FontStyle::default();
style.set_shape(FontShape::Bold | FontShape::Italic);
  1. set the fg/bg color by name
let mut style = FontStyle::default();
style.set_fg_color(Color::Red);
style.set_bg_color(Color::Blue);
  1. set the fg/bg color by 256-color
let mut style = FontStyle::default();
style.set_fg_color_256((255, 0, 0));
style.set_bg_color_256((0, 0, 255));

Note: if you set the fg/bg color by name, the 256-color will be ignored

Implementations§

Source§

impl FontStyle

Source

pub fn set_shape(&mut self, shape: FontShape) -> &mut Self

Examples found in repository?
examples/complex.rs (line 28)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
fn main() {
    let mut menu = Menu::new().unwrap_or_else(|e| {
        quit_now!("Error: {}", e);
    });

    // build item list
    let mut item_list = Vec::new();
    for i in 1..=100 {
        item_list.push(Item::new(format!("{}th item", i).as_str(), i));
    }

    // build colorscheme, you can skip this step to use the default colorscheme
    // NOTE: sometimes your terminal might not support all the colors, so you may need to adjust
    // the colorscheme
    let mut colorscheme = termenu::ColorScheme::default();
    colorscheme
        .set_title_style(
            FontStyle::default()
                .set_shape(FontShape::Bold | FontShape::Underline)
                .set_fg_color(colored::Color::Green)
                .build(),
        )
        .set_query_style(FontStyle::default().set_shape(FontShape::Italic).build())
        .set_chosen_ln_style(
            FontStyle::default()
                .set_shape(FontShape::Underline)
                .set_fg_color(colored::Color::Black)
                .set_bg_color_256((215, 255, 0))
                .build(),
        )
        .set_more_tag_style(
            FontStyle::default()
                .set_fg_color(colored::Color::Magenta)
                .build(),
        );

    // run
    let selection = menu
        .set_title("test selection:")
        .show_end_tag(true)
        .set_max_height(0.3)
        .set_colorscheme(colorscheme)
        .add_list(item_list)
        .select() // this is the menu entry
        .unwrap_or_else(|e| {
            quit_now!("Error: {}", e);
        });

    // handle selection
    if let Some(selection) = selection {
        println!("You selected: {}", selection);
    } else {
        println!("You didn't select anything");
    }
}
Source

pub fn set_fg_color(&mut self, color: Color) -> &mut Self

Examples found in repository?
examples/complex.rs (line 29)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
fn main() {
    let mut menu = Menu::new().unwrap_or_else(|e| {
        quit_now!("Error: {}", e);
    });

    // build item list
    let mut item_list = Vec::new();
    for i in 1..=100 {
        item_list.push(Item::new(format!("{}th item", i).as_str(), i));
    }

    // build colorscheme, you can skip this step to use the default colorscheme
    // NOTE: sometimes your terminal might not support all the colors, so you may need to adjust
    // the colorscheme
    let mut colorscheme = termenu::ColorScheme::default();
    colorscheme
        .set_title_style(
            FontStyle::default()
                .set_shape(FontShape::Bold | FontShape::Underline)
                .set_fg_color(colored::Color::Green)
                .build(),
        )
        .set_query_style(FontStyle::default().set_shape(FontShape::Italic).build())
        .set_chosen_ln_style(
            FontStyle::default()
                .set_shape(FontShape::Underline)
                .set_fg_color(colored::Color::Black)
                .set_bg_color_256((215, 255, 0))
                .build(),
        )
        .set_more_tag_style(
            FontStyle::default()
                .set_fg_color(colored::Color::Magenta)
                .build(),
        );

    // run
    let selection = menu
        .set_title("test selection:")
        .show_end_tag(true)
        .set_max_height(0.3)
        .set_colorscheme(colorscheme)
        .add_list(item_list)
        .select() // this is the menu entry
        .unwrap_or_else(|e| {
            quit_now!("Error: {}", e);
        });

    // handle selection
    if let Some(selection) = selection {
        println!("You selected: {}", selection);
    } else {
        println!("You didn't select anything");
    }
}
Source

pub fn set_bg_color(&mut self, color: Color) -> &mut Self

Source

pub fn set_fg_color_256(&mut self, color: (u8, u8, u8)) -> &mut Self

Source

pub fn set_bg_color_256(&mut self, color: (u8, u8, u8)) -> &mut Self

Examples found in repository?
examples/complex.rs (line 37)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
fn main() {
    let mut menu = Menu::new().unwrap_or_else(|e| {
        quit_now!("Error: {}", e);
    });

    // build item list
    let mut item_list = Vec::new();
    for i in 1..=100 {
        item_list.push(Item::new(format!("{}th item", i).as_str(), i));
    }

    // build colorscheme, you can skip this step to use the default colorscheme
    // NOTE: sometimes your terminal might not support all the colors, so you may need to adjust
    // the colorscheme
    let mut colorscheme = termenu::ColorScheme::default();
    colorscheme
        .set_title_style(
            FontStyle::default()
                .set_shape(FontShape::Bold | FontShape::Underline)
                .set_fg_color(colored::Color::Green)
                .build(),
        )
        .set_query_style(FontStyle::default().set_shape(FontShape::Italic).build())
        .set_chosen_ln_style(
            FontStyle::default()
                .set_shape(FontShape::Underline)
                .set_fg_color(colored::Color::Black)
                .set_bg_color_256((215, 255, 0))
                .build(),
        )
        .set_more_tag_style(
            FontStyle::default()
                .set_fg_color(colored::Color::Magenta)
                .build(),
        );

    // run
    let selection = menu
        .set_title("test selection:")
        .show_end_tag(true)
        .set_max_height(0.3)
        .set_colorscheme(colorscheme)
        .add_list(item_list)
        .select() // this is the menu entry
        .unwrap_or_else(|e| {
            quit_now!("Error: {}", e);
        });

    // handle selection
    if let Some(selection) = selection {
        println!("You selected: {}", selection);
    } else {
        println!("You didn't select anything");
    }
}
Source

pub fn build(&mut self) -> Self

Examples found in repository?
examples/complex.rs (line 30)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
fn main() {
    let mut menu = Menu::new().unwrap_or_else(|e| {
        quit_now!("Error: {}", e);
    });

    // build item list
    let mut item_list = Vec::new();
    for i in 1..=100 {
        item_list.push(Item::new(format!("{}th item", i).as_str(), i));
    }

    // build colorscheme, you can skip this step to use the default colorscheme
    // NOTE: sometimes your terminal might not support all the colors, so you may need to adjust
    // the colorscheme
    let mut colorscheme = termenu::ColorScheme::default();
    colorscheme
        .set_title_style(
            FontStyle::default()
                .set_shape(FontShape::Bold | FontShape::Underline)
                .set_fg_color(colored::Color::Green)
                .build(),
        )
        .set_query_style(FontStyle::default().set_shape(FontShape::Italic).build())
        .set_chosen_ln_style(
            FontStyle::default()
                .set_shape(FontShape::Underline)
                .set_fg_color(colored::Color::Black)
                .set_bg_color_256((215, 255, 0))
                .build(),
        )
        .set_more_tag_style(
            FontStyle::default()
                .set_fg_color(colored::Color::Magenta)
                .build(),
        );

    // run
    let selection = menu
        .set_title("test selection:")
        .show_end_tag(true)
        .set_max_height(0.3)
        .set_colorscheme(colorscheme)
        .add_list(item_list)
        .select() // this is the menu entry
        .unwrap_or_else(|e| {
            quit_now!("Error: {}", e);
        });

    // handle selection
    if let Some(selection) = selection {
        println!("You selected: {}", selection);
    } else {
        println!("You didn't select anything");
    }
}

Trait Implementations§

Source§

impl Clone for FontStyle

Source§

fn clone(&self) -> FontStyle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for FontStyle

Source§

fn default() -> FontStyle

Returns the “default value” for a type. Read more
Source§

impl Copy for FontStyle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.