forked from neovide/neovide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe.rs
51 lines (42 loc) · 1.24 KB
/
frame.rs
1
2
3
4
5
6
7
8
9
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
use core::fmt;
use serde::Deserialize;
use clap::{builder::PossibleValue, ValueEnum};
// Options for the frame decorations
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, Deserialize)]
pub enum Frame {
#[default]
Full,
#[cfg(target_os = "macos")]
Transparent,
#[cfg(target_os = "macos")]
Buttonless,
None,
}
impl From<&'_ Frame> for &'static str {
fn from(frame: &'_ Frame) -> Self {
match frame {
Frame::Full => "full",
#[cfg(target_os = "macos")]
Frame::Transparent => "transparent",
#[cfg(target_os = "macos")]
Frame::Buttonless => "buttonless",
Frame::None => "none",
}
}
}
impl ValueEnum for Frame {
fn value_variants<'a>() -> &'a [Self] {
#[cfg(target_os = "macos")]
return &[Self::Full, Self::Transparent, Self::Buttonless, Self::None];
#[cfg(not(target_os = "macos"))]
return &[Self::Full, Self::None];
}
fn to_possible_value(&self) -> Option<PossibleValue> {
Some(PossibleValue::new(<&str>::from(self)))
}
}
impl fmt::Display for Frame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", <&str>::from(self))
}
}