forked from nushell/nu-ansi-term
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hyperlinks and other OSC codes
Add support for producing colorized/stylized hyperlinks, among a selection of other OS Control (OSC) codes such as setting the window title, application/window icon, and notifying the terminal about the current working directory. There has already been some discussion and a change proposed for handling hyperlinks in the dormant rust-ansi-term repo: (See: ogham#61) The above proposed change breaks the Copy trait for Style and would require changing downstream projects (e.g. Starship). Also, I would argue that these features aren't really about styling text so much as adding more information for the terminal emulator to present to the user outside of the typical area for rendered terminal output. So this change takes a different approach. An enum describing the supported OSC codes, which is not exposed outside the crate, is used to indicate that a Style has additional terminal prefix and suffix output control codes to take care of for hyperlinks, titles, etc. However rather than library users using these enums directly or calling externally visible functions on Style or Color struct, AnsiGenericString uses them to implement its hyperlink(), title(), etc. functions. These store the hyperlink "src" string, title, etc. within the AnsiGenericString rather than in the Style. So Style remains Copy-able, and, since it already stores strings, AnsiGenericString traits are consistent with this choice. The locations of the functions better reflect what's happening because the supplied strings are not meant to be rendered inline with the ANSI-styled output. The OSControl enum also nicely describes the subset of OSC codes the package currently supports and keeps the prefix and suffix handling neatly adjacent to the Color and Style prefixes. -- Sorry if that's a bit verbose. I'm used to carefully describing even small changes.
- Loading branch information
Matt Helsley
committed
May 7, 2023
1 parent
773a306
commit 592c20a
Showing
4 changed files
with
224 additions
and
6 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
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