-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TTY::Link::Terminals::Wezterm to detect hyperlinks support in Wez…
…Term
- Loading branch information
1 parent
2631e86
commit b9ae09c
Showing
3 changed files
with
153 additions
and
0 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,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "abstract" | ||
|
||
module TTY | ||
class Link | ||
module Terminals | ||
# Responsible for detecting hyperlink support in the WezTerm terminal | ||
# | ||
# @api private | ||
class Wezterm < Abstract | ||
# The WezTerm terminal name pattern | ||
# | ||
# @return [Regexp] | ||
# | ||
# @api private | ||
WEZTERM = /WezTerm/i.freeze | ||
private_constant :WEZTERM | ||
|
||
# The version release | ||
# | ||
# @return [String] | ||
# | ||
# @api private | ||
VERSION_RELEASE = "20180218" | ||
private_constant :VERSION_RELEASE | ||
|
||
# The version separator | ||
# | ||
# @return [String] | ||
# | ||
# @api private | ||
VERSION_SEPARATOR = "-" | ||
private_constant :VERSION_SEPARATOR | ||
|
||
private | ||
|
||
# Detect WezTerm terminal | ||
# | ||
# @example | ||
# wezterm.name? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def name? | ||
!(term_program =~ WEZTERM).nil? | ||
end | ||
|
||
# Detect whether the WezTerm version supports terminal hyperlinks | ||
# | ||
# @example | ||
# wezterm.version? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def version? | ||
return false unless term_program_version | ||
|
||
current_semantic_version = | ||
semantic_version(term_program_version, separator: VERSION_SEPARATOR) | ||
|
||
current_semantic_version >= semantic_version(VERSION_RELEASE, 0, 0) | ||
end | ||
end # Wezterm | ||
end # Terminals | ||
end # Link | ||
end # TTY |
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,70 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe TTY::Link::Terminals::Wezterm, "#link?" do | ||
let(:env_with_name) { {"TERM_PROGRAM" => "WezTerm"} } | ||
let(:semantic_version) { TTY::Link::SemanticVersion } | ||
|
||
it "doesn't support links without the term program environment variable" do | ||
wezterm = described_class.new(semantic_version, {}) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a terminal program name" do | ||
env = {"TERM_PROGRAM" => nil} | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links with a non-WezTerm program name" do | ||
env = {"TERM_PROGRAM" => "other-terminal"} | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
|
||
it "supports links above the 20240203 version" do | ||
env = { | ||
"TERM_PROGRAM" => "wezterm", | ||
"TERM_PROGRAM_VERSION" => "20250403" | ||
} | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(true) | ||
end | ||
|
||
it "supports links above the 20180218 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "20180219-123-abc"}) | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(true) | ||
end | ||
|
||
it "supports links on the 20180218 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "20180218-123-abc"}) | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(true) | ||
end | ||
|
||
it "doesn't support links below the 20180218 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "20180217-123-abc"}) | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => nil}) | ||
wezterm = described_class.new(semantic_version, env) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without the term program version env variable" do | ||
wezterm = described_class.new(semantic_version, env_with_name) | ||
|
||
expect(wezterm.link?).to eq(false) | ||
end | ||
end |