rust-expect 0.2.0

Next-generation Expect-style terminal automation library for Rust
Documentation
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//! ANSI escape sequence parser.
//!
//! This module provides parsing for ANSI escape sequences used in
//! terminal output, including cursor movement, colors, and text attributes.

use super::buffer::{Attributes, Color};

/// Parsed ANSI escape sequence.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AnsiSequence {
    /// Cursor up (CUU).
    CursorUp(u16),
    /// Cursor down (CUD).
    CursorDown(u16),
    /// Cursor forward (CUF).
    CursorForward(u16),
    /// Cursor backward (CUB).
    CursorBackward(u16),
    /// Cursor next line (CNL) - move to beginning of line n lines down.
    CursorNextLine(u16),
    /// Cursor previous line (CPL) - move to beginning of line n lines up.
    CursorPrevLine(u16),
    /// Cursor horizontal absolute (CHA) - move cursor to column n.
    CursorColumn(u16),
    /// Vertical position absolute (VPA) - move cursor to row n.
    CursorRow(u16),
    /// Cursor position (CUP).
    CursorPosition {
        /// Row position (1-based).
        row: u16,
        /// Column position (1-based).
        col: u16,
    },
    /// Erase in display (ED).
    EraseDisplay(EraseMode),
    /// Erase in line (EL).
    EraseLine(EraseMode),
    /// Erase characters (ECH) - erase n characters from cursor.
    EraseChars(u16),
    /// Select graphic rendition (SGR).
    SetGraphics(Vec<u16>),
    /// Scroll up (SU).
    ScrollUp(u16),
    /// Scroll down (SD).
    ScrollDown(u16),
    /// Reverse index (RI) - move cursor up, scroll down if at top.
    ReverseIndex,
    /// Index (IND) - move cursor down, scroll up if at bottom.
    Index,
    /// Next line (NEL) - move to start of next line, scroll if at bottom.
    NextLine,
    /// Save cursor position (DECSC).
    SaveCursor,
    /// Restore cursor position (DECRC).
    RestoreCursor,
    /// Set scroll region (DECSTBM).
    SetScrollRegion {
        /// Top row of scroll region (1-based).
        top: u16,
        /// Bottom row of scroll region (1-based).
        bottom: u16,
    },
    /// Show cursor (DECTCEM).
    ShowCursor,
    /// Hide cursor (DECTCEM).
    HideCursor,
    /// Insert lines (IL).
    InsertLines(u16),
    /// Delete lines (DL).
    DeleteLines(u16),
    /// Insert characters (ICH).
    InsertChars(u16),
    /// Delete characters (DCH).
    DeleteChars(u16),
    /// Repeat previous character (REP).
    RepeatChar(u16),
    /// Reset terminal.
    Reset,
    /// Unknown or unsupported sequence.
    Unknown(String),
}

/// Mode for erase operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EraseMode {
    /// Erase from cursor to end.
    ToEnd,
    /// Erase from start to cursor.
    ToStart,
    /// Erase entire area.
    All,
}

impl From<u16> for EraseMode {
    fn from(n: u16) -> Self {
        match n {
            0 => Self::ToEnd,
            1 => Self::ToStart,
            _ => Self::All,
        }
    }
}

/// ANSI sequence parser.
#[derive(Clone)]
pub struct AnsiParser {
    state: ParserState,
    params: Vec<u16>,
    intermediate: String,
    current_param: Option<u16>,
    /// Accumulator for the current incomplete UTF-8 codepoint, used so a
    /// multi-byte character delivered across separate `parse` calls produces
    /// one `Print(char)` for the full Unicode scalar rather than per-byte
    /// Latin-1 garbage.
    utf8_buf: [u8; 4],
    /// Number of bytes already accumulated in `utf8_buf` (0..=4).
    utf8_len: u8,
    /// Total bytes expected for the codepoint currently being assembled
    /// (2, 3, or 4). Zero when not in the middle of a UTF-8 sequence.
    utf8_needed: u8,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ParserState {
    Ground,
    Escape,
    CsiEntry,
    CsiParam,
    CsiIntermediate,
    OscString,
}

impl Default for AnsiParser {
    fn default() -> Self {
        Self::new()
    }
}

impl AnsiParser {
    /// Create a new parser.
    #[must_use]
    pub const fn new() -> Self {
        Self {
            state: ParserState::Ground,
            params: Vec::new(),
            intermediate: String::new(),
            current_param: None,
            utf8_buf: [0; 4],
            utf8_len: 0,
            utf8_needed: 0,
        }
    }

    /// Reset the parser state.
    pub fn reset(&mut self) {
        self.state = ParserState::Ground;
        self.params.clear();
        self.intermediate.clear();
        self.current_param = None;
        self.utf8_len = 0;
        self.utf8_needed = 0;
    }

    /// Parse a byte and return any completed sequences.
    ///
    /// Returns up to two emissions in the order they should be applied to
    /// the screen. The second slot is only populated on UTF-8 malformed-
    /// sequence recovery: when an expected continuation byte fails to
    /// arrive and is replaced by an unrelated byte, we emit a `U+FFFD`
    /// for the broken sequence (slot 0) and then process the new byte
    /// normally (slot 1). Callers should iterate via `.into_iter().flatten()`.
    pub fn parse(&mut self, byte: u8) -> [Option<ParseResult>; 2] {
        let primary = match self.state {
            ParserState::Ground => return self.ground(byte),
            ParserState::Escape => self.escape(byte),
            ParserState::CsiEntry => self.csi_entry(byte),
            ParserState::CsiParam => self.csi_param(byte),
            ParserState::CsiIntermediate => self.csi_intermediate(byte),
            ParserState::OscString => self.osc_string(byte),
        };
        [primary, None]
    }

    fn ground(&mut self, byte: u8) -> [Option<ParseResult>; 2] {
        // ESC and C0 control bytes terminate any in-progress UTF-8 sequence
        // and are handled directly. We don't expect them mid-codepoint in
        // well-formed input, but if it happens we abandon the partial
        // sequence rather than emit a stray replacement character.
        match byte {
            0x1b => {
                self.utf8_len = 0;
                self.utf8_needed = 0;
                self.state = ParserState::Escape;
                return [None, None];
            }
            0x00..=0x1a | 0x1c..=0x1f => {
                self.utf8_len = 0;
                self.utf8_needed = 0;
                return [Some(ParseResult::Control(byte)), None];
            }
            _ => {}
        }

        // UTF-8 decoding.
        //   0xxxxxxx (0x00-0x7F)  — 1-byte ASCII
        //   10xxxxxx (0x80-0xBF)  — continuation byte
        //   110xxxxx (0xC2-0xDF)  — start of 2-byte sequence
        //   1110xxxx (0xE0-0xEF)  — start of 3-byte sequence
        //   11110xxx (0xF0-0xF4)  — start of 4-byte sequence
        if self.utf8_needed == 0 {
            // Not currently assembling a multi-byte codepoint.
            if byte < 0x80 {
                return [Some(ParseResult::Print(byte as char)), None];
            }
            let needed = match byte {
                0xC2..=0xDF => 2,
                0xE0..=0xEF => 3,
                0xF0..=0xF4 => 4,
                // 0x80-0xBF as a starting byte is a stray continuation, and
                // 0xC0/0xC1/0xF5..=0xFF are invalid lead bytes. In all cases
                // emit U+FFFD and don't poison the accumulator.
                _ => {
                    return [
                        Some(ParseResult::Print(std::char::REPLACEMENT_CHARACTER)),
                        None,
                    ];
                }
            };
            self.utf8_buf[0] = byte;
            self.utf8_len = 1;
            self.utf8_needed = needed;
            return [None, None];
        }

        // Mid-sequence: expect a continuation byte.
        if (byte & 0xC0) != 0x80 {
            // Malformed: previous codepoint was incomplete. Emit U+FFFD
            // for the broken sequence (slot 0) and then process the new
            // byte normally (slot 1), preserving both visual order and
            // the new byte's intended effect.
            self.utf8_len = 0;
            self.utf8_needed = 0;
            let recovered = Some(ParseResult::Print(std::char::REPLACEMENT_CHARACTER));
            // ground() recursion is safe now that utf8_needed is cleared;
            // it cannot re-enter this branch on the same byte.
            // The recursive call returns at most one primary emission for a
            // byte arriving in Ground state with no UTF-8 backlog; the
            // secondary slot is always None on that path.
            let [reprocessed_primary, _] = self.ground(byte);
            return [recovered, reprocessed_primary];
        }

        // Valid continuation. Accumulate.
        let idx = self.utf8_len as usize;
        self.utf8_buf[idx] = byte;
        self.utf8_len += 1;

        if self.utf8_len < self.utf8_needed {
            return [None, None];
        }

        // Complete codepoint — decode.
        let bytes = &self.utf8_buf[..self.utf8_len as usize];
        let ch = std::str::from_utf8(bytes)
            .ok()
            .and_then(|s| s.chars().next())
            .unwrap_or(std::char::REPLACEMENT_CHARACTER);
        self.utf8_len = 0;
        self.utf8_needed = 0;
        [Some(ParseResult::Print(ch)), None]
    }

    fn escape(&mut self, byte: u8) -> Option<ParseResult> {
        match byte {
            b'[' => {
                self.state = ParserState::CsiEntry;
                self.params.clear();
                self.intermediate.clear();
                self.current_param = None;
                None
            }
            b']' => {
                self.state = ParserState::OscString;
                None
            }
            b'7' => {
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::SaveCursor))
            }
            b'8' => {
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::RestoreCursor))
            }
            b'c' => {
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::Reset))
            }
            b'D' => {
                // IND - Index: move cursor down, scroll up if at bottom
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::Index))
            }
            b'E' => {
                // NEL - Next Line: move to start of next line
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::NextLine))
            }
            b'M' => {
                // RI - Reverse Index: move cursor up, scroll down if at top
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::ReverseIndex))
            }
            _ => {
                self.reset();
                Some(ParseResult::Sequence(AnsiSequence::Unknown(format!(
                    "ESC {}",
                    byte as char
                ))))
            }
        }
    }

    fn csi_entry(&mut self, byte: u8) -> Option<ParseResult> {
        match byte {
            b'0'..=b'9' => {
                self.current_param = Some(u16::from(byte - b'0'));
                self.state = ParserState::CsiParam;
                None
            }
            b';' => {
                self.params.push(0);
                self.state = ParserState::CsiParam;
                None
            }
            b'?' => {
                self.intermediate.push('?');
                None
            }
            b'>' => {
                self.intermediate.push('>');
                None
            }
            b' '..=b'/' => {
                self.intermediate.push(byte as char);
                self.state = ParserState::CsiIntermediate;
                None
            }
            b'@'..=b'~' => Some(self.finalize_csi(byte)),
            _ => {
                self.reset();
                None
            }
        }
    }

    fn csi_param(&mut self, byte: u8) -> Option<ParseResult> {
        match byte {
            b'0'..=b'9' => {
                let digit = u16::from(byte - b'0');
                self.current_param = Some(
                    self.current_param
                        .unwrap_or(0)
                        .saturating_mul(10)
                        .saturating_add(digit),
                );
                None
            }
            b';' => {
                self.params.push(self.current_param.unwrap_or(0));
                self.current_param = None;
                None
            }
            b' '..=b'/' => {
                if let Some(p) = self.current_param.take() {
                    self.params.push(p);
                }
                self.intermediate.push(byte as char);
                self.state = ParserState::CsiIntermediate;
                None
            }
            b'@'..=b'~' => {
                if let Some(p) = self.current_param.take() {
                    self.params.push(p);
                }
                Some(self.finalize_csi(byte))
            }
            _ => {
                self.reset();
                None
            }
        }
    }

    fn csi_intermediate(&mut self, byte: u8) -> Option<ParseResult> {
        match byte {
            b' '..=b'/' => {
                self.intermediate.push(byte as char);
                None
            }
            b'@'..=b'~' => Some(self.finalize_csi(byte)),
            _ => {
                self.reset();
                None
            }
        }
    }

    fn osc_string(&mut self, byte: u8) -> Option<ParseResult> {
        match byte {
            0x07 | 0x1b => {
                // BEL or ESC terminates OSC
                self.reset();
                None
            }
            _ => None, // Ignore OSC content for now
        }
    }

    fn finalize_csi(&mut self, final_byte: u8) -> ParseResult {
        let params = std::mem::take(&mut self.params);
        let intermediate = std::mem::take(&mut self.intermediate);
        self.reset();

        let seq = match (final_byte, intermediate.as_str()) {
            // Cursor movement
            (b'A', "") => AnsiSequence::CursorUp(params.first().copied().unwrap_or(1)),
            (b'B', "") => AnsiSequence::CursorDown(params.first().copied().unwrap_or(1)),
            (b'C', "") => AnsiSequence::CursorForward(params.first().copied().unwrap_or(1)),
            (b'D', "") => AnsiSequence::CursorBackward(params.first().copied().unwrap_or(1)),
            (b'E', "") => AnsiSequence::CursorNextLine(params.first().copied().unwrap_or(1)),
            (b'F', "") => AnsiSequence::CursorPrevLine(params.first().copied().unwrap_or(1)),
            (b'G', "") => AnsiSequence::CursorColumn(params.first().copied().unwrap_or(1)),
            (b'd', "") => AnsiSequence::CursorRow(params.first().copied().unwrap_or(1)),
            (b'H' | b'f', "") => AnsiSequence::CursorPosition {
                row: params.first().copied().unwrap_or(1),
                col: params.get(1).copied().unwrap_or(1),
            },
            // Erase operations
            (b'J', "") => AnsiSequence::EraseDisplay(params.first().copied().unwrap_or(0).into()),
            (b'K', "") => AnsiSequence::EraseLine(params.first().copied().unwrap_or(0).into()),
            (b'X', "") => AnsiSequence::EraseChars(params.first().copied().unwrap_or(1)),
            // Graphics
            (b'm', "") => {
                AnsiSequence::SetGraphics(if params.is_empty() { vec![0] } else { params })
            }
            // Scrolling
            (b'S', "") => AnsiSequence::ScrollUp(params.first().copied().unwrap_or(1)),
            (b'T', "") => AnsiSequence::ScrollDown(params.first().copied().unwrap_or(1)),
            (b'r', "") => AnsiSequence::SetScrollRegion {
                top: params.first().copied().unwrap_or(1),
                bottom: params.get(1).copied().unwrap_or(0),
            },
            // Cursor save/restore
            (b's', "") => AnsiSequence::SaveCursor,
            (b'u', "") => AnsiSequence::RestoreCursor,
            // Line operations
            (b'L', "") => AnsiSequence::InsertLines(params.first().copied().unwrap_or(1)),
            (b'M', "") => AnsiSequence::DeleteLines(params.first().copied().unwrap_or(1)),
            // Character operations
            (b'@', "") => AnsiSequence::InsertChars(params.first().copied().unwrap_or(1)),
            (b'P', "") => AnsiSequence::DeleteChars(params.first().copied().unwrap_or(1)),
            (b'b', "") => AnsiSequence::RepeatChar(params.first().copied().unwrap_or(1)),
            // DEC private modes
            (b'h', "?") if params.first() == Some(&25) => AnsiSequence::ShowCursor,
            (b'l', "?") if params.first() == Some(&25) => AnsiSequence::HideCursor,
            _ => AnsiSequence::Unknown(format!(
                "CSI {}{}{}",
                params
                    .iter()
                    .map(std::string::ToString::to_string)
                    .collect::<Vec<_>>()
                    .join(";"),
                intermediate,
                final_byte as char
            )),
        };

        ParseResult::Sequence(seq)
    }
}

/// Result of parsing a byte.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParseResult {
    /// A printable character.
    Print(char),
    /// A control character.
    Control(u8),
    /// A complete ANSI sequence.
    Sequence(AnsiSequence),
}

/// Apply SGR (Select Graphic Rendition) parameters.
pub fn apply_sgr(params: &[u16], fg: &mut Color, bg: &mut Color, attrs: &mut Attributes) {
    let mut i = 0;
    while i < params.len() {
        match params[i] {
            0 => {
                *fg = Color::Default;
                *bg = Color::Default;
                *attrs = Attributes::empty();
            }
            1 => *attrs |= Attributes::BOLD,
            2 => *attrs |= Attributes::DIM,
            3 => *attrs |= Attributes::ITALIC,
            4 => *attrs |= Attributes::UNDERLINE,
            5 => *attrs |= Attributes::BLINK,
            7 => *attrs |= Attributes::INVERSE,
            8 => *attrs |= Attributes::HIDDEN,
            9 => *attrs |= Attributes::STRIKETHROUGH,
            22 => *attrs &= !(Attributes::BOLD | Attributes::DIM),
            23 => *attrs &= !Attributes::ITALIC,
            24 => *attrs &= !Attributes::UNDERLINE,
            25 => *attrs &= !Attributes::BLINK,
            27 => *attrs &= !Attributes::INVERSE,
            28 => *attrs &= !Attributes::HIDDEN,
            29 => *attrs &= !Attributes::STRIKETHROUGH,
            30..=37 => *fg = Color::from_ansi((params[i] - 30) as u8),
            38 => {
                if i + 2 < params.len() && params[i + 1] == 5 {
                    *fg = Color::Indexed(params[i + 2] as u8);
                    i += 2;
                } else if i + 4 < params.len() && params[i + 1] == 2 {
                    *fg = Color::Rgb(
                        params[i + 2] as u8,
                        params[i + 3] as u8,
                        params[i + 4] as u8,
                    );
                    i += 4;
                }
            }
            39 => *fg = Color::Default,
            40..=47 => *bg = Color::from_ansi((params[i] - 40) as u8),
            48 => {
                if i + 2 < params.len() && params[i + 1] == 5 {
                    *bg = Color::Indexed(params[i + 2] as u8);
                    i += 2;
                } else if i + 4 < params.len() && params[i + 1] == 2 {
                    *bg = Color::Rgb(
                        params[i + 2] as u8,
                        params[i + 3] as u8,
                        params[i + 4] as u8,
                    );
                    i += 4;
                }
            }
            49 => *bg = Color::Default,
            90..=97 => *fg = Color::from_ansi((params[i] - 90 + 8) as u8),
            100..=107 => *bg = Color::from_ansi((params[i] - 100 + 8) as u8),
            _ => {}
        }
        i += 1;
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    /// Helper that drains the up-to-two-result array `parse()` now returns.
    fn drain<'a>(
        parser: &'a mut AnsiParser,
        bytes: impl IntoIterator<Item = u8> + 'a,
    ) -> impl Iterator<Item = ParseResult> + 'a {
        bytes
            .into_iter()
            .flat_map(|b| parser.parse(b).into_iter().flatten())
    }

    #[test]
    fn parse_cursor_up() {
        let mut parser = AnsiParser::new();
        let result = drain(&mut parser, "\x1b[5A".bytes()).last();
        assert_eq!(
            result,
            Some(ParseResult::Sequence(AnsiSequence::CursorUp(5)))
        );
    }

    #[test]
    fn parse_cursor_position() {
        let mut parser = AnsiParser::new();
        let result = drain(&mut parser, "\x1b[10;20H".bytes()).last();
        assert_eq!(
            result,
            Some(ParseResult::Sequence(AnsiSequence::CursorPosition {
                row: 10,
                col: 20
            }))
        );
    }

    #[test]
    fn parse_sgr() {
        let mut parser = AnsiParser::new();
        let result = drain(&mut parser, "\x1b[1;31m".bytes()).last();
        assert_eq!(
            result,
            Some(ParseResult::Sequence(AnsiSequence::SetGraphics(vec![
                1, 31
            ])))
        );
    }

    #[test]
    fn parse_printable() {
        let mut parser = AnsiParser::new();
        let result = parser.parse(b'A');
        assert_eq!(result, [Some(ParseResult::Print('A')), None]);
    }

    /// Malformed-recovery: a UTF-8 start byte followed by a non-continuation
    /// byte must emit BOTH U+FFFD for the broken sequence AND the recovery
    /// byte's own emission, in that order.
    #[test]
    fn parse_malformed_utf8_emits_both_results() {
        let mut parser = AnsiParser::new();
        // 0xE2 starts a 3-byte sequence; 'X' is not a valid continuation.
        // We need to feed the lead byte first (which returns [None, None]
        // while waiting for continuations), then 'X' interrupts.
        assert_eq!(parser.parse(0xE2), [None, None]);
        let results: Vec<ParseResult> = parser.parse(b'X').into_iter().flatten().collect();
        assert_eq!(
            results,
            vec![
                ParseResult::Print(std::char::REPLACEMENT_CHARACTER),
                ParseResult::Print('X'),
            ],
            "malformed recovery must emit U+FFFD then the recovery byte's result"
        );
    }

    #[test]
    fn apply_sgr_colors() {
        let mut fg = Color::Default;
        let mut bg = Color::Default;
        let mut attrs = Attributes::empty();

        apply_sgr(&[1, 31, 42], &mut fg, &mut bg, &mut attrs);

        assert!(attrs.contains(Attributes::BOLD));
        assert_eq!(fg, Color::Red);
        assert_eq!(bg, Color::Green);
    }
}