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
78
79
80
81
82
83
84
85
86
87
88
use types::Object;

use crate::Window;

/// Options passed to [`eval_statusline()`](crate::eval_statusline).
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct EvalStatuslineOpts {
    winid: Object,
    maxwidth: Object,
    fillchar: Object,
    highlights: Object,
    use_tabline: Object,
    use_winbar: Object,
    use_statuscol_lnum: Object,
}

impl EvalStatuslineOpts {
    #[inline(always)]
    /// Creates a new [`EvalStatuslineOptsBuilder`].
    pub fn builder() -> EvalStatuslineOptsBuilder {
        EvalStatuslineOptsBuilder::default()
    }
}

#[derive(Clone, Default)]
pub struct EvalStatuslineOptsBuilder(EvalStatuslineOpts);

impl EvalStatuslineOptsBuilder {
    /// Character used to fill blank spaces in the statusline.
    #[inline]
    pub fn fillchar(&mut self, fillchar: char) -> &mut Self {
        self.0.fillchar = fillchar.into();
        self
    }

    /// Return statuline informations from
    /// [`eval_statusline()`](crate::eval_statusline).
    #[inline]
    pub fn highlights(&mut self, highlights: bool) -> &mut Self {
        self.0.highlights = highlights.into();
        self
    }

    /// Maximum width for the statusline.
    #[inline]
    pub fn maxwidth(&mut self, maxwidth: u32) -> &mut Self {
        self.0.maxwidth = maxwidth.into();
        self
    }

    #[inline]
    pub fn use_statuscol_lnum(
        &mut self,
        use_statuscol_lnum: bool,
    ) -> &mut Self {
        self.0.use_statuscol_lnum = use_statuscol_lnum.into();
        self
    }

    /// Evaluate the tabline instead of the statusline. When `true` the
    /// [`window`](EvalStatuslineOptsBuilder::window) field is ignored.
    #[inline]
    pub fn use_tabline(&mut self, use_tabline: bool) -> &mut Self {
        self.0.use_tabline = use_tabline.into();
        self
    }

    /// Evaluate the winbar instead of the statusline. Mutually exclusive with
    /// [`use_tabline`](EvalStatuslineOptsBuilder::use_tabline).
    #[inline]
    pub fn use_winbar(&mut self, use_winbar: bool) -> &mut Self {
        self.0.use_winbar = use_winbar.into();
        self
    }

    /// Window to use as context for the statusline.
    #[inline]
    pub fn window(&mut self, window: Window) -> &mut Self {
        self.0.winid = window.into();
        self
    }

    #[inline]
    pub fn build(&mut self) -> EvalStatuslineOpts {
        std::mem::take(&mut self.0)
    }
}