-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support OSC 7 notify working directory (#25)
* feat: support OSC 7 notify working directory * upgrade x/ansi, fix, add tests * test for invalid url --------- Co-authored-by: Carlos Alexandro Becker <[email protected]>
- Loading branch information
Showing
9 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/charmbracelet/x/ansi" | ||
) | ||
|
||
//nolint:mnd | ||
func handleWorkingDirectoryURL(p *ansi.Parser) (string, error) { | ||
parts := bytes.Split(p.Data(), []byte{';'}) | ||
if len(parts) != 2 { | ||
// Invalid, ignore | ||
return "", errInvalid | ||
} | ||
|
||
u, err := url.ParseRequestURI(string(parts[1])) | ||
|
||
if err != nil || u.Scheme != "file" { | ||
// Should be a file URL. | ||
return "", errInvalid | ||
} | ||
|
||
return fmt.Sprintf("Set working directory to %s (on %s)", u.Path, u.Host), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OSC 7file://localhost/foo: invalid sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OSC 7;foooooo:/bar: invalid sequence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OSC 7;file://localhost/foo/bar: Set working directory to /foo/bar (on localhost) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OSC 7;file://localhost/foo: Set working directory to /foo (on localhost) |