Skip to main content

nu_protocol/config/
status_line.rs

1use super::prelude::*;
2use crate as nu_protocol;
3
4/// What the REPL shows on the line under the one being edited. `enable`
5/// switches all of it off at once.
6#[derive(Clone, Copy, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
7pub struct StatusLineConfig {
8    /// Draw the status line at all.
9    pub enable: bool,
10    /// The first parse or type error in the line.
11    pub errors: bool,
12    /// The signature of the command under the cursor.
13    pub signature: bool,
14    /// The type the pipeline at the cursor outputs.
15    #[nu_value(rename = "type")]
16    #[serde(rename = "type")]
17    pub output_type: bool,
18    /// The value of a line built only from const commands.
19    pub preview: bool,
20}
21
22impl Default for StatusLineConfig {
23    fn default() -> Self {
24        Self {
25            enable: true,
26            errors: true,
27            signature: true,
28            output_type: true,
29            preview: true,
30        }
31    }
32}
33
34impl UpdateFromValue for StatusLineConfig {
35    fn update<'a>(
36        &mut self,
37        value: &'a Value,
38        path: &mut ConfigPath<'a>,
39        errors: &mut ConfigErrors,
40    ) {
41        let Value::Record { val: record, .. } = value else {
42            errors.type_mismatch(path, Type::record(), value);
43            return;
44        };
45
46        for (col, val) in record.iter() {
47            let path = &mut path.push(col);
48            match col.as_str() {
49                "enable" => self.enable.update(val, path, errors),
50                "errors" => self.errors.update(val, path, errors),
51                "signature" => self.signature.update(val, path, errors),
52                "type" => self.output_type.update(val, path, errors),
53                "preview" => self.preview.update(val, path, errors),
54                _ => errors.unknown_option(path, val),
55            }
56        }
57    }
58}