-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add Ghostty terminal hyperlink support #3
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
Open
the-spectator
wants to merge
2
commits into
piotrmurach:master
Choose a base branch
from
the-spectator:feat/ghostty
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "abstract" | ||
|
|
||
| module TTY | ||
| class Link | ||
| module Terminals | ||
| # Responsible for detecting hyperlink support in the Ghostty terminal | ||
| # | ||
| # @api private | ||
| class Ghostty < Abstract | ||
| # The Ghostty terminal name pattern | ||
| # | ||
| # @return [Regexp] | ||
| # | ||
| # @api private | ||
| GHOSTTY = /ghostty/i.freeze | ||
| private_constant :GHOSTTY | ||
|
|
||
| private | ||
|
|
||
| # Detect Ghostty terminal | ||
| # | ||
| # @example | ||
| # ghostty.name? | ||
| # # => true | ||
| # | ||
| # @return [Boolean] | ||
| # | ||
| # @api private | ||
| def name? | ||
| !(term_program =~ GHOSTTY).nil? | ||
| end | ||
|
|
||
| # Detect whether the Ghostty version supports terminal hyperlinks | ||
| # | ||
| # @example | ||
| # ghostty.version? | ||
| # # => true | ||
| # | ||
| # @return [Boolean] | ||
| # | ||
| # @api private | ||
| def version? | ||
| return false unless term_program_version | ||
|
|
||
| current_semantic_version = semantic_version(term_program_version) | ||
|
|
||
| current_semantic_version >= semantic_version(1, 0, 0) | ||
| end | ||
| end # Ghostty | ||
| end # Terminals | ||
| end # Link | ||
| end # TTY |
This file contains hidden or 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 hidden or 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,74 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe TTY::Link::Terminals::Ghostty, "#link?" do | ||
| let(:env_with_name) { {"TERM_PROGRAM" => "ghostty"} } | ||
| let(:semantic_version) { TTY::Link::SemanticVersion } | ||
|
|
||
| it "doesn't support links without the term program environment variable" do | ||
| ghostty = described_class.new(semantic_version, {}) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
|
|
||
| it "doesn't support links without a terminal program name" do | ||
| env = {"TERM_PROGRAM" => nil} | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
|
|
||
| it "doesn't support links with a non-Ghostty program name" do | ||
| env = {"TERM_PROGRAM" => "other-terminal"} | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
|
|
||
| it "supports links above the 2.0.0 version" do | ||
| env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "2.3.4"}) | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(true) | ||
| end | ||
|
|
||
| it "supports links above the 1.0.0 version" do | ||
| env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "1.0.1"}) | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(true) | ||
| end | ||
|
|
||
| it "supports links on the 1.0.0 version" do | ||
| env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "1.0.0"}) | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(true) | ||
| end | ||
|
|
||
| it "supports links on the 1.0.0 version with a mixed-case program name" do | ||
| env = {"TERM_PROGRAM" => "GhosTTY", "TERM_PROGRAM_VERSION" => "1.0.0"} | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(true) | ||
| end | ||
|
|
||
| it "doesn't support links below the 1.0.0 version" do | ||
| env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "0.9.2"}) | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
|
|
||
| it "doesn't support links without a version" do | ||
| env = env_with_name.merge({"TERM_PROGRAM_VERSION" => nil}) | ||
| ghostty = described_class.new(semantic_version, env) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
|
|
||
| it "doesn't support links without the term program version env variable" do | ||
| ghostty = described_class.new(semantic_version, env_with_name) | ||
|
|
||
| expect(ghostty.link?).to eq(false) | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for messing you around with this. I looked at other terminal tests. Let's keep the order consistent. So the naming and order should be:
"doesn't support links without the term program...""doesn't support links without a terminal program name""doesn't support links with a non-Ghostty program name""supports links above the 2.0.0 version"NEW test with2.3.4version."supports links above the 1.0.0 version""supports links on the 1.0.0 version""supports links on the 1.0.0 version with a mixed-case program name""doesn't support links below the 1.0.0 version""doesn't support links without a version""doesn't support links without the term program version env variable"