8000 Add support for OSC 133 by iacore · Pull Request #10352 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

Add support for OSC 133#10352

Closed
iacore wants to merge 2 commits intofish-shell:masterfrom
iacore:patch-2
Closed

Add support for OSC 133#10352
iacore wants to merge 2 commits intofish-shell:masterfrom
iacore:patch-2

Conversation

@iacore
Copy link
@iacore iacore commented Mar 8, 2024

Description

Support marking prompts with OSC 133

Supercedes #10351.

TODOs:

  • Find out how feature detection is done
  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

src/curses.rs Outdated

prompt_start: if support_osc133 { Some(CString::new("\x1b]133;A\x1b\x5c").unwrap()) } else { None },
prompt_end: if support_osc133 { Some(CString::new("\x1b]133;B\x1b\x5c").unwrap()) } else { None },
command_start: if support_osc133 { Some(CString::new("\x1b]133;C\x1b\x5c").unwrap()) } else { None },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to open a new pull request, you can update the old one, or at least cross-reference #10351 for future readers for the benefit of future readers
Looks good to me overall.

I think we don't even need to define prompt_start fields, can simply hardcode them at the callsite.
Also make sure to remove unused code.

Copy link
Author
@iacore iacore Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the output is not a terminal, what will happen if it receives those escseq?

zelf.write_mbs_if_some(&term.and_then(|term| term.prompt_start.as_ref()));
let mut start = 0;
for line_break in left_prompt_layout.line_breaks {
zelf.write_str(&left_prompt[start..line_break]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run bind \eg 'echo; git status; git remote -v; echo; commandline -f repaint'

right, we offer bindings like \el and \w so this should definitely be supported

src/screen.rs Outdated
// Output the left prompt if it has changed.
if left_prompt != zelf.actual_left_prompt {
zelf.r#move(0, 0);
zelf.write_mbs_if_some(&term.and_then(|term| term.prompt_start.as_ref()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this feature used by terminals?
If it's just about not overwriting output, we should do it for right prompts too.
If it's meant to allow jumping between prompts, then the right prompt shouldn't get it.

Copy link
Author
@iacore iacore Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for kitty, it only needs marking of

  • start of PS1
  • start of PS2 (auto-complete i think)
  • start of application output

https://sw.kovidgoyal.net/kitty/shell-integration/#notes-for-shell-developers

/// capabilities we care about in the process.
fn new(db: terminfo::Database) -> Self {
// todo: how to do feature detection of OSC 133?
let support_osc133 = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably enable it unconditionally.
I'm not aware of a relevant terminal that doesn't have basic xterm compatibility.
We can add a knob to specify xterm compatibility that or turn off OSC 133 specifically but I think that can be done later.

We do have a bug where we fail to turn off bracketed paste and focus reporting for commands launched from bindings,
like bind \eg sh for example.
But we can definitely fix that, and it's not relevant here.

src/curses.rs Outdated
pub prompt_end: Option<CString>, // "\x1b133;B\x07"
pub command_start: Option<CString>, // "\x1b133;C\x07"
// pub command_end_before_status: Option<CString>, // "\x1b133;D;<exitcode>;\x07"
// pub command_end_after_status: Option<CString>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well add command start/end too here.
Emit it next to where we emit fish_preexec/fish_postexec, passing eval_res.status.status_value().
If you choose to do that, make sure it plays well with fish's default prompt which already renders a failing status in bold red.

@iacore
Copy link
Author
iacore commented Mar 9, 2024

Why is CString used everywhere? On every write it literally recalculates the length of the string.

    pub fn tputs(&mut self, str: &CStr) {
        self.begin_buffering();
        let _ = self.write(str.to_bytes());
        self.end_buffering();
    }

I will not use CString in this patch.

@iacore
Copy link
Author
iacore commented Mar 9, 2024

I am not sure where to print the other escape sequences. Anyone can take over this PR now. I have marked what needs to be added with // todo.

@krobelus krobelus added this to the fish next-3.x milestone Apr 6, 2024
@krobelus krobelus closed this in 3b9e3e2 Apr 6, 2024
sentriz added a commit to sentriz/dotfiles that referenced this pull request Jan 6, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0