-
-
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::Rio to detect hyperlinks support in Rio
- Loading branch information
1 parent
31c45b6
commit 918c418
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 Rio terminal | ||
# | ||
# @api private | ||
class Rio < Abstract | ||
# The Rio terminal name pattern | ||
# | ||
# @return [Regexp] | ||
# | ||
# @api private | ||
RIO = /rio/i.freeze | ||
private_constant :RIO | ||
|
||
private | ||
|
||
# Detect Rio terminal | ||
# | ||
# @example | ||
# rio.name? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def name? | ||
!(term_program =~ RIO).nil? | ||
end | ||
|
||
# Detect whether the Rio version supports terminal hyperlinks | ||
# | ||
# @example | ||
# rio.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(0, 0, 28) | ||
end | ||
end # Rio | ||
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::Rio, "#link?" do | ||
let(:env_with_name) { {"TERM_PROGRAM" => "rio"} } | ||
let(:semantic_version) { TTY::Link::SemanticVersion } | ||
|
||
it "doesn't support links without the term program environment variable" do | ||
rio = described_class.new(semantic_version, {}) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a terminal program name" do | ||
env = {"TERM_PROGRAM" => nil} | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links with a non-Rio program name" do | ||
env = {"TERM_PROGRAM" => "other-terminal"} | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
|
||
it "supports links above the 0.1.8 version" do | ||
env = { | ||
"TERM_PROGRAM" => "Rio", | ||
"TERM_PROGRAM_VERSION" => "0.2.3" | ||
} | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(true) | ||
end | ||
|
||
it "supports links above the 0.0.28 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "0.0.29"}) | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(true) | ||
end | ||
|
||
it "supports links on the 0.0.28 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "0.0.28"}) | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(true) | ||
end | ||
|
||
it "doesn't support links below the 0.0.28 version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => "0.0.27"}) | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without a version" do | ||
env = env_with_name.merge({"TERM_PROGRAM_VERSION" => nil}) | ||
rio = described_class.new(semantic_version, env) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links without the term program version env variable" do | ||
rio = described_class.new(semantic_version, env_with_name) | ||
|
||
expect(rio.link?).to eq(false) | ||
end | ||
end |