Skip to content

feat(ansi): support OSC 7 notify working directory#274

Merged
aymanbagabas merged 8 commits intocharmbracelet:mainfrom
rzhw:cwd
Nov 21, 2024
Merged

feat(ansi): support OSC 7 notify working directory#274
aymanbagabas merged 8 commits intocharmbracelet:mainfrom
rzhw:cwd

Conversation

@rzhw
Copy link
Copy Markdown
Contributor

@rzhw rzhw commented Nov 21, 2024

Copy link
Copy Markdown
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

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

Is there any documentation or references about this sequence?

@rzhw
Copy link
Copy Markdown
Contributor Author

rzhw commented Nov 21, 2024

Is there any documentation or references about this sequence?

Not super formally documented, but I've made a round-up of terminals supporting OSC 7 with links to their documentation or implementations in charmbracelet/sequin#24.

For formal documentation specifically:

There's also this blog article I've come across documenting the escape sequence.

@aymanbagabas
Copy link
Copy Markdown
Member

For formal documentation specifically:

There's also this blog article I've come across documenting the escape sequence.

No worries, I would just include the iterm2 and wezterm links in the code comments.

rzhw and others added 2 commits November 22, 2024 01:12
Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@rzhw
Copy link
Copy Markdown
Contributor Author

rzhw commented Nov 21, 2024

No worries, I would just include the iterm2 and wezterm links in the code comments.

Done in 52210b9, how's that look?

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@rzhw rzhw requested a review from aymanbagabas November 21, 2024 16:18
Copy link
Copy Markdown
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

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

Looks good! Could you please update the imports and format the file using gofumpt?

@rzhw
Copy link
Copy Markdown
Contributor Author

rzhw commented Nov 21, 2024

Looks good! Could you please update the imports and format the file using gofumpt?

Done!

BTW if you want to see this in action for yourself, I wrote this quick script that should let you Ctrl/Cmd+Click the ../main.go path (tested with VSCode and iTerm2) if you place it at the root of the repo and run it with go run main.go:

package main

import (
	"fmt"
	"os"
	"path/filepath"
	"runtime"

	"github.com/charmbracelet/x/ansi"
)

func main() {
	_, filename, _, ok := runtime.Caller(0)
	if !ok {
		panic("no caller")
	}
	dir := filepath.Dir(filename)
	fmt.Println("changing cwd OSC 7 to " + dir)
	fmt.Printf(ansi.NotifyWorkingDirectory("localhost", dir, "ansi"))
	fmt.Println("../main.go:13:5: error: use of undeclared identifier 'sdfsfds'")
	termProgram := os.Getenv("TERM_PROGRAM")
	if termProgram == "vscode" {
		fmt.Println("Hello, VSCode needs an extra line for some reason (don't need this for iTerm2)")
	}
}

@aymanbagabas aymanbagabas merged commit a372054 into charmbracelet:main Nov 21, 2024
@aymanbagabas
Copy link
Copy Markdown
Member

Thank you, @rzhw! This will be included in ansi/v0.5.2

@rzhw rzhw deleted the cwd branch November 21, 2024 16:59
@rzhw rzhw restored the cwd branch November 21, 2024 17:03
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