Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hyperlinks and other OSC codes #43

Merged
merged 1 commit into from
Jun 2, 2023

Commits on Jun 2, 2023

  1. 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 that rely on
    it.
    
    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 than taken
    in the referenced pull request.
    
    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. These
    let us keep the prefix/suffix handling consistent.
    
    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.
    
    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.
    Matt Helsley committed Jun 2, 2023
    Configuration menu
    Copy the full SHA
    715ab28 View commit details
    Browse the repository at this point in the history