Repository: alacritty/alacritty
File: alacritty/src/event.rs (Rust)

Code before:

    /// Process a new character for keyboard hints.
    fn hint_input(&mut self, c: char) {
        if let Some(hint) = self.display.hint_state.keyboard_input(self.terminal, c) {
            self.mouse.block_hint_launcher = false;
            self.trigger_hint(&hint);
        }
        *self.dirty = true;
    }

    /// Trigger a hint action.
    fn trigger_hint(&mut self, hint: &HintMatch) {
        if self.mouse.block_hint_launcher {
            return;
        }

        match &hint.action {
            // Launch an external program.
            HintAction::Command(command) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                let mut args = command.args().to_vec();

                match text.strip_suffix('\n') {
                    Some(text) => args.push(text.to_string()),
                    None => args.push(text),
                }

                self.spawn_daemon(command.program(), &args);
            },
            // Copy the text to the clipboard.
            HintAction::Action(HintInternalAction::Copy) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                self.clipboard.store(ClipboardType::Clipboard, text);
            },
            // Write the text to the PTY/search.
            HintAction::Action(HintInternalAction::Paste) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                self.paste(&text);
            },
            // Select the text.
            HintAction::Action(HintInternalAction::Select) => {
                self.start_selection(SelectionType::Simple, *hint.bounds.start(), Side::Left);
                self.update_selection(*hint.bounds.end(), Side::Right);
                self.copy_selection(ClipboardType::Selection);
            },
            // Move the vi mode cursor.
            HintAction::Action(HintInternalAction::MoveViModeCursor) => {
                // Enter vi mode if we're not in it already.
                if !self.terminal.mode().contains(TermMode::VI) {
                    self.terminal.toggle_vi_mode();
                }

Review comment (suggestion):
```
let text = text.strip_suffix('\n').map(str::to_owned).unwrap_or(text);
```

There might be an even easier way to do it, but that's the best I could come up with.

Code after:

    /// Process a new character for keyboard hints.
    fn hint_input(&mut self, c: char) {
        if let Some(hint) = self.display.hint_state.keyboard_input(self.terminal, c) {
            self.mouse.block_hint_launcher = false;
            self.trigger_hint(&hint);
        }
        *self.dirty = true;
    }

    /// Trigger a hint action.
    fn trigger_hint(&mut self, hint: &HintMatch) {
        if self.mouse.block_hint_launcher {
            return;
        }

        match &hint.action {
            // Launch an external program.
            HintAction::Command(command) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                let mut args = command.args().to_vec();
                args.push(text);
                self.spawn_daemon(command.program(), &args);
            },
            // Copy the text to the clipboard.
            HintAction::Action(HintInternalAction::Copy) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                self.clipboard.store(ClipboardType::Clipboard, text);
            },
            // Write the text to the PTY/search.
            HintAction::Action(HintInternalAction::Paste) => {
                let text = self.terminal.bounds_to_string(*hint.bounds.start(), *hint.bounds.end());
                self.paste(&text);
            },
            // Select the text.
            HintAction::Action(HintInternalAction::Select) => {
                self.start_selection(SelectionType::Simple, *hint.bounds.start(), Side::Left);
                self.update_selection(*hint.bounds.end(), Side::Right);
                self.copy_selection(ClipboardType::Selection);
            },
            // Move the vi mode cursor.
            HintAction::Action(HintInternalAction::MoveViModeCursor) => {
                // Enter vi mode if we're not in it already.
                if !self.terminal.mode().contains(TermMode::VI) {
                    self.terminal.toggle_vi_mode();
                }

                self.terminal.vi_goto_point(*hint.bounds.start());
            },
        }
    }