-
-
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::Vscode to detect hyperlinks support in VSCode
- Loading branch information
1 parent
cce4aef
commit 2631e86
Showing
3 changed files
with
136 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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "abstract" | ||
|
||
module TTY | ||
class Link | ||
module Terminals | ||
# Responsible for detecting hyperlink support in the VSCode terminal | ||
# | ||
# @api private | ||
class Vscode < Abstract | ||
# The VSCode terminal name pattern | ||
# | ||
# @return [Regexp] | ||
# | ||
# @api private | ||
VSCODE = /vscode/i.freeze | ||
private_constant :VSCODE | ||
|
||
private | ||
|
||
# Detect VSCode terminal | ||
# | ||
# @example | ||
# vscode.name? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def name? | ||
!(term_program =~ VSCODE).nil? | ||
end | ||
|
||
# Detect whether the VSCode version supports terminal hyperlinks | ||
# | ||
# @example | ||
# vscode.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, 72, 0) | ||
end | ||
end # Vscode | ||
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::Vscode, "#link?" do | ||
let(:env_with_name) { {"TERM_PROGRAM" => "vscode"} } | ||
let(:semantic_version) { TTY::Link::SemanticVersion } | ||
|
||
it "doesn't support links without the term program environment variable" do | ||
vscode = described_class.new(semantic_version, {}) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a terminal program name" do | ||
env = {"TERM_PROGRAM" => nil} | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links with a non-VSCode program name" do | ||
env = {"TERM_PROGRAM" => "other-terminal"} | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
|
||
it "supports links above the 1.92.2 version" do | ||
env = { | ||
"TERM_PROGRAM" => "VSCode", | ||
"TERM_PROGRAM_VERSION" => "2.3.4" | ||
} | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(true) | ||
end | ||
|
||
it "supports links above the 1.72.0 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "1.72.1"}) | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(true) | ||
end | ||
|
||
it "supports links on the 1.72.0 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "1.72.0"}) | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(true) | ||
end | ||
|
||
it "doesn't support links below the 1.72.0 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "1.71.2"}) | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => nil}) | ||
vscode = described_class.new(semantic_version, env) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without the term program version env variable" do | ||
vscode = described_class.new(semantic_version, env_with_name) | ||
|
||
expect(vscode.link?).to eq(false) | ||
end | ||
end |