-
-
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::Jediterm to detect hyperlinks support in Je…
…diTerm
- Loading branch information
1 parent
a75a8c6
commit 83d5098
Showing
3 changed files
with
113 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,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "abstract" | ||
|
||
module TTY | ||
class Link | ||
module Terminals | ||
# Responsible for detecting hyperlink support in the JediTerm terminal | ||
# | ||
# @api private | ||
class Jediterm < Abstract | ||
# The JediTerm terminal name pattern | ||
# | ||
# @return [Regexp] | ||
# | ||
# @api private | ||
JEDITERM = /JediTerm/i.freeze | ||
private_constant :JEDITERM | ||
|
||
# The terminal emulator environment variable name | ||
# | ||
# @return [String] | ||
# | ||
# @api private | ||
TERMINAL_EMULATOR = "TERMINAL_EMULATOR" | ||
private_constant :TERMINAL_EMULATOR | ||
|
||
private | ||
|
||
# Detect JediTerm terminal | ||
# | ||
# @example | ||
# jediterm.name? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def name? | ||
!(terminal_emulator =~ JEDITERM).nil? | ||
end | ||
|
||
# Detect any JediTerm version to support terminal hyperlinks | ||
# | ||
# @example | ||
# jediterm.version? | ||
# # => true | ||
# | ||
# @return [Boolean] | ||
# | ||
# @api private | ||
def version? | ||
true | ||
end | ||
|
||
# Read the terminal emulator environment variable | ||
# | ||
# @example | ||
# jediterm.terminal_emulator | ||
# # => "JetBrains-JediTerm" | ||
# | ||
# @return [String, nil] | ||
# | ||
# @api private | ||
def terminal_emulator | ||
env[TERMINAL_EMULATOR] | ||
end | ||
end # Jediterm | ||
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::Jediterm, "#link?" do | ||
let(:semantic_version) { TTY::Link::SemanticVersion } | ||
|
||
it "supports links on any version" do | ||
env = {"TERMINAL_EMULATOR" => "JetBrains-JediTerm"} | ||
jediterm = described_class.new(semantic_version, env) | ||
|
||
expect(jediterm.link?).to eq(true) | ||
end | ||
|
||
it "supports a terminal name without the 'JetBrains-' prefix" do | ||
env = {"TERMINAL_EMULATOR" => "jediterm"} | ||
jediterm = described_class.new(semantic_version, env) | ||
|
||
expect(jediterm.link?).to eq(true) | ||
end | ||
|
||
it "doesn't support links without a terminal name" do | ||
env = {"TERMINAL_EMULATOR" => nil} | ||
jediterm = described_class.new(semantic_version, env) | ||
|
||
expect(jediterm.link?).to eq(false) | ||
end | ||
|
||
it "doesn't support links with a non-JediTerm terminal name" do | ||
env = {"TERMINAL_EMULATOR" => "other-terminal"} | ||
jediterm = described_class.new(semantic_version, env) | ||
|
||
expect(jediterm.link?).to eq(false) | ||
end | ||
end |