Add const-default impls to Terminal structs
This commit is contained in:
parent
284220e8ab
commit
091cc35730
@ -39,8 +39,19 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
/// Specifies a set of special control characters
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct TerminalControlCharacters {
|
||||
pub eof: u8,
|
||||
pub erase: u8,
|
||||
pub werase: u8,
|
||||
pub interrupt: u8,
|
||||
pub kill: u8,
|
||||
}
|
||||
|
||||
/// Terminal I/O transformation and control settings
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct TerminalOptions {
|
||||
/// Controls output processing
|
||||
@ -49,4 +60,36 @@ pub struct TerminalOptions {
|
||||
pub input: TerminalInputOptions,
|
||||
/// Controls special bytes and line discipline
|
||||
pub line: TerminalLineOptions,
|
||||
/// Specifies control characters of the terminal
|
||||
pub chars: TerminalControlCharacters,
|
||||
}
|
||||
|
||||
impl TerminalControlCharacters {
|
||||
/// const-version of [Default] trait impl
|
||||
pub const fn const_default() -> Self {
|
||||
Self {
|
||||
eof: 0x04,
|
||||
erase: 0x7F,
|
||||
interrupt: 0x03,
|
||||
kill: 0x15,
|
||||
werase: 0x17,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TerminalOptions {
|
||||
/// const-version of [Default] trait impl
|
||||
pub const fn const_default() -> Self {
|
||||
Self {
|
||||
output: TerminalOutputOptions::const_default(),
|
||||
input: TerminalInputOptions::const_default(),
|
||||
line: TerminalLineOptions::const_default(),
|
||||
chars: TerminalControlCharacters::const_default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if CANONICAL flag is set for this terminal
|
||||
pub const fn is_canonical(&self) -> bool {
|
||||
self.line.contains(TerminalLineOptions::CANONICAL)
|
||||
}
|
||||
}
|
||||
|
@ -124,6 +124,13 @@ macro_rules! bitflags_impl_default {
|
||||
$name($($name::$flag.bits())|+)
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
/// const-version of [Default] trait impl
|
||||
pub const fn const_default() -> Self {
|
||||
Self($($name::$flag.bits())|+)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($name:ident, $repr:ty, ()) => {
|
||||
@ -132,6 +139,13 @@ macro_rules! bitflags_impl_default {
|
||||
$name(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl $name {
|
||||
/// const-version of [Default] trait impl
|
||||
pub const fn const_default() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user