1use crate::WmCtlError;
2use std::{convert, fmt};
3
4#[derive(Debug, Clone, PartialEq)]
7pub enum Shape {
8 Grow,
9 Max,
10 Halfw,
11 Halfh,
12 Small,
13 Medium,
14 Large,
15 Shrink,
16 Square,
17 UnMax,
18 Static(u32, u32),
19}
20
21impl fmt::Display for Shape {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 match self {
25 _ => write!(f, "{}", format!("{:?}", self).to_lowercase()),
26 }
27 }
28}
29
30impl convert::TryFrom<&str> for Shape {
32 type Error = WmCtlError;
33
34 fn try_from(val: &str) -> Result<Self, Self::Error> {
35 match val.to_lowercase().as_ref() {
36 "grow" => Ok(Shape::Grow),
37 "max" => Ok(Shape::Max),
38 "halfw" => Ok(Shape::Halfw),
39 "halfh" => Ok(Shape::Halfh),
40 "small" => Ok(Shape::Small),
41 "medium" => Ok(Shape::Medium),
42 "large" => Ok(Shape::Large),
43 "shrink" => Ok(Shape::Shrink),
44 "unmax" => Ok(Shape::UnMax),
45 _ => Err(WmCtlError::InvalidWinShape(val.to_string()).into()),
46 }
47 }
48}
49
50impl convert::TryFrom<String> for Shape {
52 type Error = WmCtlError;
53
54 fn try_from(val: String) -> Result<Self, Self::Error> {
55 Shape::try_from(val.as_str())
56 }
57}