Skip to content

add native semantic prompt support initially for OSC 133/633#1019

Merged
fdncred merged 4 commits intonushell:mainfrom
fdncred:semantic_prompts
Feb 5, 2026
Merged

add native semantic prompt support initially for OSC 133/633#1019
fdncred merged 4 commits intonushell:mainfrom
fdncred:semantic_prompts

Conversation

@fdncred
Copy link
Contributor

@fdncred fdncred commented Feb 4, 2026

This PR adds native support for semantic prompt markers (OSC 133/633) to reedline, enabling proper terminal integration with Ghostty, VS Code, and other terminals that support the FinalTerm semantic prompts specification.

  • Uses ST (\x1b\\) terminator, not BEL (\x07)
  • Consumers (like nushell) can enable markers via with_semantic_markers()
  • C/D execution markers remain the responsibility of the shell

There are 2 new examples. semantic_prompt_verify is for manually inspecting the output to see what it looks like to humans. semantic_prompt_interactive is for using with ghostty or similar tools that provide a debug interface to see the escapes. for ghostty, use the "Terminal Inspector" and then on the Renderer menu make sure you enable Overlay Semantic Prompts.

I've done my best to ensure that these escapes are per spec. Let me know if you disagree or think I've missed something.

Example semantic_prompt_verify

❯ cargo run --example semantic_prompt_verify
Semantic Prompt Verification
============================

OSC 133 Markers (Standard):
----------------------------
  Primary prompt start:   OSC 133;P;k=i ST = \e]133;P;k=i\e\
  Secondary prompt start: OSC 133;P;k=s ST = \e]133;P;k=s\e\
  Right prompt start:     OSC 133;P;k=r ST = \e]133;P;k=r\e\
  Command input start:    OSC 133;B ST     = \e]133;B\e\

OSC 633 Markers (VS Code):
--------------------------
  Primary prompt start:   OSC 633;A;k=i ST = \e]633;A;k=i\e\
  Secondary prompt start: OSC 633;A;k=s ST = \e]633;A;k=s\e\
  Right prompt start:     OSC 633;P;k=r ST = \e]633;P;k=r\e\
  Command input start:    OSC 633;B ST     = \e]633;B\e\

Expected Prompt Sequence: (133;A is oveerridden with P to avoid newline issues)
------------------------
For a prompt like: '~/src > ls -la'

1. prompt_start(Primary)  -> OSC 133;P;k=i ST  (before '~/src ')
2. [left prompt text]     -> '~/src '
3. [indicator text]       -> '> '
4. command_input_start()  -> OSC 133;B ST     (after indicator)
5. prompt_start(Right)    -> OSC 133;P;k=r ST (before right prompt)
6. [right prompt text]    -> any right prompt

Multiline Continuation:
----------------------
For a multiline prompt continuation:

1. prompt_start(Secondary) -> OSC 133;P;k=s ST (before '::: ')
2. [continuation indicator] -> '::: '
3. command_input_start()   -> OSC 133;B ST    (after indicator)

Raw Byte Sequences:
------------------
  OSC 133;P;k=i ST = ESC ] 1 3 3 ; P ; k = i ESC \\
  OSC 133;P;k=s ST = ESC ] 1 3 3 ; P ; k = s ESC \\
  OSC 133;P;k=r ST = ESC ] 1 3 3 ; P ; k = r ESC \\
  OSC 133;B ST     = ESC ] 1 3 3 ; B ESC \\

Note: C (pre-exec) and D (post-exec) markers are emitted by the shell,
not by reedline, as they relate to command execution lifecycle.

Example semantic_prompt_interactive

image

//! - `B` - Marks the end of prompt and start of user input
//! - `C` - Marks the start of command execution (emitted by shell, not reedline)
//! - `D` - Marks the end of command execution with exit code (emitted by shell)
//! - `P` - Sets a property (used for right prompt marker `k=r`)
Copy link

@mitchellh mitchellh Feb 4, 2026

Choose a reason for hiding this comment

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

This is technically P for prompt. So it starts a prompt. The A is kind of weird: it does a \r\n if the cursor isn't at x=0 and THEN does a P. If you want, you can use P all the time instead of A for example if you're not sure if the cursor will be at x=0 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I've updated the comments with your suggestion and the code, of course. I left the vscode at 633;A but change the others to 133;P all the time. Thanks for the tip.

@mitchellh
Copy link

mitchellh commented Feb 4, 2026

This looks great! You may want to consider extending this to support an optional cl enum value or click_events Kitty extension for downstream programs that support it.

I don't know the full reedline/downstream relationship so I'm not sure if that can be safely defaulted to any value or if downstream must always opt-in.

I think with proper OSC133 support, Nushell should be able to support cl=m for free, for example. That would allow clicking the prompt line to move the cursor.

@fdncred
Copy link
Contributor Author

fdncred commented Feb 4, 2026

This looks great! You may want to consider extending this to support an optional cl enum value or click_events Kitty extension for downstream programs that support it.

I don't know the full reedline/downstream relationship so I'm not sure if that can be safely defaulted to any value or if downstream must always opt-in.

I think with proper OSC133 support, Nushell should be able to support cl=m for free, for example. That would allow clicking the prompt line to move the cursor.

Someone is already trying to implement click_events based off my reedline PR that hasn't landed yet. https://github.com/nushell/reedline/pull/1020/changes#diff-abcd983172046f9e9f64a31934996ed8bb05d631180ededb428e319e37753997R105

@fdncred
Copy link
Contributor Author

fdncred commented Feb 5, 2026

let's move forward with this for now. hopefully will land click_events=1 pr next #1020

@fdncred fdncred merged commit 57f8c6a into nushell:main Feb 5, 2026
6 checks passed
@fdncred fdncred deleted the semantic_prompts branch February 5, 2026 12:48
fdncred pushed a commit to nushell/nushell that referenced this pull request Feb 6, 2026
<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->

## Summary
- Enable OSC 133 semantic prompt markers (via @fdncred /
nushell/reedline/pull/1019)
- Enable OSC 133 click_events (via nushell/reedline/pull/1020).
- Keep OSC 633 support for VS Code and prefer it when available.

## Testing
- `cargo test -p nu-cli prompt_does_not_embed_osc_markers`
- `cargo test -p nu-cli semantic_markers_`
- `cargo test -p nu-protocol click_to_cursor_is_unknown_option`

## Release notes summary - What our users need to know
- Enabling `shell_integration.osc133` now also enables click-to-cursor
in supported terminals.

## Tasks after submitting
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)

<details>
<summary<strong>DEMO</strong></summary>


https://github.com/user-attachments/assets/ce11079f-0c4f-4f90-a1b1-e3c3d0b99351

</details>
TestingPlant pushed a commit to TestingPlant/nushell that referenced this pull request Feb 6, 2026
<!--
Thank you for improving Nushell!
Please, read our contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md
-->

## Summary
- Enable OSC 133 semantic prompt markers (via @fdncred /
nushell/reedline/pull/1019)
- Enable OSC 133 click_events (via nushell/reedline/pull/1020).
- Keep OSC 633 support for VS Code and prefer it when available.

## Testing
- `cargo test -p nu-cli prompt_does_not_embed_osc_markers`
- `cargo test -p nu-cli semantic_markers_`
- `cargo test -p nu-protocol click_to_cursor_is_unknown_option`

## Release notes summary - What our users need to know
- Enabling `shell_integration.osc133` now also enables click-to-cursor
in supported terminals.

## Tasks after submitting
- [ ] Update the
[documentation](https://github.com/nushell/nushell.github.io)

<details>
<summary<strong>DEMO</strong></summary>


https://github.com/user-attachments/assets/ce11079f-0c4f-4f90-a1b1-e3c3d0b99351

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants