Skip to content

Commit

Permalink
Add TTY::Link::Terminals::Kitty to detect hyperlinks support in kitty
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Aug 24, 2024
1 parent 83d5098 commit 5495a56
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/tty/link/terminals/kitty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

module TTY
class Link
module Terminals
# Responsible for detecting hyperlink support in the kitty terminal
#
# @api private
class Kitty < Abstract
# The kitty terminal name pattern
#
# @return [Regexp]
#
# @api private
KITTY = /kitty/i.freeze
private_constant :KITTY

private

# Detect kitty terminal
#
# @example
# kitty.name?
# # => true
#
# @return [Boolean]
#
# @api private
def name?
!(term =~ KITTY).nil?
end

# Detect any kitty version to support terminal hyperlinks
#
# @example
# kitty.version?
# # => true
#
# @return [Boolean]
#
# @api private
def version?
true
end
end # Kitty
end # Terminals
end # Link
end # TTY
9 changes: 9 additions & 0 deletions spec/unit/link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@
end
end

context "when kitty" do
it "supports links on any version" do
env = {"TERM" => "xterm-kitty"}
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
33 changes: 33 additions & 0 deletions spec/unit/terminals/kitty_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

RSpec.describe TTY::Link::Terminals::Kitty, "#link?" do
let(:semantic_version) { TTY::Link::SemanticVersion }

it "supports links on any version" do
env = {"TERM" => "xterm-kitty"}
kitty = described_class.new(semantic_version, env)

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

it "supports a terminal name without the 'xterm-' prefix" do
env = {"TERM" => "Kitty"}
kitty = described_class.new(semantic_version, env)

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

it "doesn't support links without a terminal name" do
env = {"TERM" => nil}
kitty = described_class.new(semantic_version, env)

expect(kitty.link?).to eq(false)
end

it "doesn't support links with a non-kitty terminal name" do
env = {"TERM" => "other-terminal"}
kitty = described_class.new(semantic_version, env)

expect(kitty.link?).to eq(false)
end
end

0 comments on commit 5495a56

Please sign in to comment.