simbelmyne_uci/
options.rs

1use std::fmt::Display;
2
3#[derive(Debug, Clone)]
4pub enum OptionType {
5  Check {
6    default: bool,
7  },
8  Spin {
9    min: i32,
10    max: i32,
11    default: i32,
12    step: i32,
13  },
14  Combo {
15    default: String,
16    allowed: Vec<String>,
17  },
18  Button,
19  String {
20    default: String,
21  },
22}
23
24impl Display for OptionType {
25  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26    match self {
27      Self::Check { default } => {
28        write!(f, "type check default {default}")?;
29      }
30
31      Self::Spin {
32        min, max, default, ..
33      } => {
34        write!(
35          f,
36          "type spin default {default:<5} min {min:<5} max {max:<5}"
37        )?;
38      }
39
40      Self::Combo { default, allowed } => {
41        write!(f, "type combo default {default} ")?;
42
43        for value in allowed {
44          write!(f, "var {value} ")?;
45        }
46      }
47
48      Self::Button => {
49        write!(f, "type button")?;
50      }
51
52      Self::String { default } => {
53        write!(f, "type string default {default}")?;
54      }
55    }
56
57    Ok(())
58  }
59}
60
61#[derive(Debug, Clone)]
62pub struct UciOption {
63  pub name: &'static str,
64  pub option_type: OptionType,
65}
66
67impl Display for UciOption {
68  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69    write!(f, "name {:<25} {}", self.name, self.option_type)
70  }
71}