ncursesw/include/attribute.rs
1/*
2    src/include/attribute.rs
3
4    Copyright (c) 2019, 2020 Stephen Whittle  All rights reserved.
5
6    Permission is hereby granted, free of charge, to any person obtaining a copy
7    of this software and associated documentation files (the "Software"),
8    to deal in the Software without restriction, including without limitation
9    the rights to use, copy, modify, merge, publish, distribute, sublicense,
10    and/or sell copies of the Software, and to permit persons to whom
11    the Software is furnished to do so, subject to the following conditions:
12    The above copyright notice and this permission notice shall be included
13    in all copies or substantial portions of the Software.
14    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20    IN THE SOFTWARE.
21*/
22
23use crate::shims::constants::{
24    A_NORMAL, A_CHARTEXT, A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK, A_DIM,
25    A_BOLD, A_ALTCHARSET, A_INVIS, A_PROTECT, A_HORIZONTAL, A_LEFT, A_LOW,
26    A_RIGHT, A_TOP, A_VERTICAL, A_ITALIC
27};
28
29/// Terminal Attribute.
30#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
31pub enum Attribute {
32    /// Normal display (no highlight).
33    Normal,
34    /// Bit-mask to extract a character.
35    CharText,
36    /// Best highlighting mode of the terminal.
37    Standout,
38    /// Underlining.
39    Underline,
40    /// Reverse video.
41    Reverse,
42    /// Blinking.
43    Blink,
44    /// Half bright.
45    Dim,
46    /// Extra bright or bold.
47    Bold,
48    /// Alternate character set.
49    AlternativeCharSet,
50    /// Invisible or blank mode.
51    Invisible,
52    /// Protected mode.
53    Protected,
54    Horizontal,
55    Left,
56    Low,
57    Right,
58    Top,
59    Vertical,
60    /// Italics.
61    Italic
62}
63
64impl Into<attr_t> for Attribute {
65    fn into(self) -> attr_t {
66        match self {
67            Attribute::Normal             => A_NORMAL,
68            Attribute::CharText           => A_CHARTEXT,
69            Attribute::Standout           => A_STANDOUT,
70            Attribute::Underline          => A_UNDERLINE,
71            Attribute::Reverse            => A_REVERSE,
72            Attribute::Blink              => A_BLINK,
73            Attribute::Dim                => A_DIM,
74            Attribute::Bold               => A_BOLD,
75            Attribute::AlternativeCharSet => A_ALTCHARSET,
76            Attribute::Invisible          => A_INVIS,
77            Attribute::Protected          => A_PROTECT,
78            Attribute::Horizontal         => A_HORIZONTAL,
79            Attribute::Left               => A_LEFT,
80            Attribute::Low                => A_LOW,
81            Attribute::Right              => A_RIGHT,
82            Attribute::Top                => A_TOP,
83            Attribute::Vertical           => A_VERTICAL,
84            Attribute::Italic             => A_ITALIC
85        }
86    }
87}
88
89impl Default for Attribute {
90    fn default() -> Self {
91        Attribute::Normal
92    }
93}