-
-
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::Kitty to detect hyperlinks support in kitty
- Loading branch information
1 parent
83d5098
commit 5495a56
Showing
3 changed files
with
90 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,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 |
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,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 |