Repository: nushell/nushell
File: crates/nu-cli/src/prompt.rs (Rust)

Code before:
        )
    }
}

impl Prompt for NushellPrompt {
    fn render_prompt_left(&self) -> Cow<'_, str> {
        #[cfg(windows)]
        {
            let _ = enable_vt_processing();
        }

        if let Some(prompt_string) = &self.left_prompt_string {
            prompt_string.replace('\n', "\r\n").into()
        } else {
            let default = DefaultPrompt::default();
            let prompt = default
                .render_prompt_left()
                .to_string()
                .replace('\n', "\r\n");

            match self.shell_integration_mode() {
                ShellIntegrationMode::Osc633 => {
                    format!("{VSCODE_PRE_PROMPT_MARKER}{VSCODE_PROMPT_KIND_INITIAL}{prompt}{VSCODE_POST_PROMPT_MARKER}").into()
                }
                ShellIntegrationMode::Osc133 => {
                    format!("{PRE_PROMPT_MARKER}{PROMPT_KIND_INITIAL}{prompt}{POST_PROMPT_MARKER}")
                        .into()
                }
                ShellIntegrationMode::None => prompt.into(),
            }
        }
    }

    fn render_prompt_right(&self) -> Cow<'_, str> {
        if let Some(prompt_string) = &self.right_prompt_string {
            prompt_string.replace('\n', "\r\n").into()
        } else {
            let default = DefaultPrompt::default();
            let prompt = default
                .render_prompt_right()
                .to_string()
                .replace('\n', "\r\n");

            match self.shell_integration_mode() {
                ShellIntegrationMode::Osc633 => {
                    format!("{VSCODE_PROMPT_KIND_RIGHT}{prompt}").into()
                }
                ShellIntegrationMode::Osc133 => format!("{PROMPT_KIND_RIGHT}{prompt}").into(),
                ShellIntegrationMode::None => prompt.into(),
            }
        }

Review comment (suggestion):
If you're optimizing for bytes here, you can combine `OSC 133 A` and `P` since `A` implies P. Right now you're sending `OSC 133 A` `OSC 133 P k=i` when you could just end `OSC 133 A k=i`.

Code after:
                .replace('\n', "\r\n")
                .into()
        }
    }

    fn render_prompt_indicator(&self, edit_mode: PromptEditMode) -> Cow<'_, str> {
        let indicator: &str = match edit_mode {
            PromptEditMode::Default => self.prompt_indicator.as_deref().unwrap_or("> "),
            PromptEditMode::Emacs => self.prompt_indicator.as_deref().unwrap_or("> "),
            PromptEditMode::Vi(vi_mode) => match vi_mode {
                PromptViMode::Normal => self.vi_normal_prompt_indicator.as_deref().unwrap_or("> "),
                PromptViMode::Insert => self.vi_insert_prompt_indicator.as_deref().unwrap_or(": "),
            },
            PromptEditMode::Custom(str) => &self.default_wrapped_custom_string(str),
        };

        indicator.to_string().into()
    }

    fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> {
        let indicator = match &self.multiline_indicator {
            Some(indicator) => indicator.as_str(),
            None => "::: ",
        };

        indicator.to_string().into()
    }

    fn render_prompt_history_search_indicator(
        &self,
        history_search: PromptHistorySearch,
    ) -> Cow<'_, str> {
        let prefix = match history_search.status {
            PromptHistorySearchStatus::Passing => "",
            PromptHistorySearchStatus::Failing => "failing ",
        };

        Cow::Owned(format!(
            "({}reverse-search: {})",
            prefix, history_search.term
        ))
    }

    fn right_prompt_on_last_line(&self) -> bool {
        self.render_right_prompt_on_last_line
    }
}