Repository: zellij-org/zellij
File: src/input.rs (Rust)

Code before:
                InputMode::Command => self.read_command_mode(false),
                InputMode::CommandPersistent => self.read_command_mode(true),
                InputMode::Exiting => {
                    self.exit();
                    break;
                }
            }
        }
    }

    /// Read input to the terminal (or switch to command mode)
    fn read_normal_mode(&mut self) {
        assert_eq!(self.mode, InputMode::Normal);
        let err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());

        loop {
            let stdin_buffer = self.os_input.read_from_stdin();
            match stdin_buffer.as_slice() {
                [7] => {
                    // ctrl-g
                    self.mode = InputMode::Command;
                    return;
                }
                _ => {
                    self.send_screen_instructions
                        .send((ScreenInstruction::ClearScroll, err_ctx))
                        .unwrap();
                    self.send_screen_instructions
                        .send((ScreenInstruction::WriteCharacter(stdin_buffer), err_ctx))
                        .unwrap();
                }
            }
        }
    }

    /// Read input and parse it as commands for mosaic
    fn read_command_mode(&mut self, persistent: bool) {
        //@@@khs26 Add a powerbar type thing that we can write output to
        if persistent {
            assert_eq!(self.mode, InputMode::CommandPersistent);
        } else {
            assert_eq!(self.mode, InputMode::Command);
        }
        let err_ctx = OPENCALLS.with(|ctx| *ctx.borrow());

        loop {
            let stdin_buffer = self.os_input.read_from_stdin();
            // uncomment this to print the entered character to a log file (/tmp/mosaic/mosaic-log.txt) for debugging
            // debug_log_to_file(format!("buffer {:?}", stdin_buffer));

            match stdin_buffer.as_slice() {

Review comment (suggestion):
So, this is true to other places as well, but what do you think about making a wrapper struct around our various `Sender`s so that we won't have to keep specifying the `err_ctx` everywhere?

Something like:
```rust
struct SenderWithContext<T> {
    err_ctx: ErrorContext,
    sender: Sender<T>
}
impl<T> SenderWithContext <T>{
    pub fn send(event: T) {
        self.sender.send(event, self.err_ctx);
    }
    pub fn update_error_ctx (new_error_ctx: ErrorContext) {
        self.error_ctx = new_error_ctx;
    }
}
```

Code after:
                InputMode::Normal => self.read_normal_mode(),
                InputMode::Command => self.read_command_mode(false),
                InputMode::CommandPersistent => self.read_command_mode(true),
                InputMode::Exiting => {
                    self.exit();
                    break;
                }
            }
        }
    }

    /// Read input to the terminal (or switch to command mode)
    fn read_normal_mode(&mut self) {
        assert_eq!(self.mode, InputMode::Normal);

        loop {
            let stdin_buffer = self.os_input.read_from_stdin();
            match stdin_buffer.as_slice() {
                [7] => {
                    // ctrl-g
                    self.mode = InputMode::Command;
                    return;
                }
                _ => {
                    self.send_screen_instructions
                        .send(ScreenInstruction::ClearScroll)
                        .unwrap();
                    self.send_screen_instructions
                        .send(ScreenInstruction::WriteCharacter(stdin_buffer))
                        .unwrap();
                }
            }
        }
    }

    /// Read input and parse it as commands for mosaic
    fn read_command_mode(&mut self, persistent: bool) {
        //@@@khs26 Add a powerbar type thing that we can write output to
        if persistent {
            assert_eq!(self.mode, InputMode::CommandPersistent);
        } else {
            assert_eq!(self.mode, InputMode::Command);
        }

        loop {
            let stdin_buffer = self.os_input.read_from_stdin();
            // uncomment this to print the entered character to a log file (/tmp/mosaic/mosaic-log.txt) for debugging
            // debug_log_to_file(format!("buffer {:?}", stdin_buffer));

            match stdin_buffer.as_slice() {
                [7] => {