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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::cmd::Cmd;
use std::fmt::{Display, Error, Formatter};

impl Display for IOTCM {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(
            f,
            "IOTCM {:?} {:?} {:?} {}",
            self.file, self.level, self.method, self.command
        )
    }
}

/// How much highlighting should be sent to the user interface?
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum HighlightingLevel {
    None,
    NonInteractive,
    /// This includes both non-interactive highlighting and
    /// interactive highlighting of the expression that is currently
    /// being type-checked.
    Interactive,
}

impl Default for HighlightingLevel {
    fn default() -> Self {
        HighlightingLevel::NonInteractive
    }
}

/// How should highlighting be sent to the user interface?
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum HighlightingMethod {
    /// Via stdout.
    Direct,
    /// Both via files and via stdout.
    Indirect,
}

impl Default for HighlightingMethod {
    fn default() -> Self {
        HighlightingMethod::Direct
    }
}

#[derive(Debug, Clone)]
pub struct IOTCM {
    level: HighlightingLevel,
    file: String,
    method: HighlightingMethod,
    pub command: Cmd,
}

impl IOTCM {
    pub fn new(
        level: HighlightingLevel,
        file: String,
        method: HighlightingMethod,
        command: Cmd,
    ) -> Self {
        Self {
            level,
            file,
            method,
            command,
        }
    }

    pub fn simple(file: String, command: Cmd) -> Self {
        Self::new(Default::default(), file, Default::default(), command)
    }

    /// Convert `self` into a command string.
    pub fn to_string(&self) -> String {
        format!("{}\n", self)
    }
}