Skip to content

Commit

Permalink
Add TTY::Link::Terminals::Rio to detect hyperlinks support in Rio
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Aug 25, 2024
1 parent 31c45b6 commit 918c418
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/tty/link/terminals/rio.rb
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
12 changes: 12 additions & 0 deletions spec/unit/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@
end
end

context "when Rio" do
it "supports links above the 0.0.28 version" do
env = {
"TERM_PROGRAM" => "rio",
"TERM_PROGRAM_VERSION" => "0.0.28"
}
link = described_class.new(env: env, output: output)

expect(link.link?).to eq(true)
end
end

context "when VTE" do
it "supports links above the 0.50.1 version" do
env = {"VTE_VERSION" => "5001"}
Expand Down
70 changes: 70 additions & 0 deletions spec/unit/terminals/rio_spec.rb
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

0 comments on commit 918c418

Please sign in to comment.