1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Move default_editor_for_platform to Pry::Editor

The name strongly suggests that this method belongs to `Pry::Editor` and it
makes no sense to have it on `Pry` class.
This commit is contained in:
Kyrylo Silin 2019-04-10 01:24:47 +03:00
parent f7f05fc703
commit 2f30e7dc63
5 changed files with 54 additions and 12 deletions

View file

@ -18,6 +18,7 @@ require 'pry/class_command'
require 'pry/block_command'
require 'pry/command_set'
require 'pry/syntax_highlighter'
require 'pry/editor'
Pry::Commands = Pry::CommandSet.new unless defined?(Pry::Commands)
@ -49,7 +50,6 @@ require 'pry/inspector'
require 'pry/color_printer'
require 'pry/pager'
require 'pry/terminal'
require 'pry/editor'
require 'pry/indent'
require 'pry/object_path'
require 'pry/output'

View file

@ -78,7 +78,7 @@ class Pry
color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
default_window_size: 5,
editor: Pry.default_editor_for_platform,
editor: Pry::Editor.default,
should_load_rc: true,
should_load_local_rc: true,
should_trap_interrupts: Pry::Helpers::Platform.jruby?,

View file

@ -2,6 +2,16 @@ require 'shellwords'
class Pry
class Editor
def self.default
return ENV['VISUAL'] if ENV['VISUAL'] && !ENV['VISUAL'].empty?
return ENV['EDITOR'] if ENV['EDITOR'] && !ENV['EDITOR'].empty?
return 'notepad' if Helpers::Platform.windows?
%w[editor nano vi].find do |editor|
Kernel.system("which #{editor} > /dev/null 2>&1")
end
end
include Pry::Helpers::CommandHelpers
attr_reader :pry_instance

View file

@ -306,16 +306,6 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
nil
end
def self.default_editor_for_platform
return ENV['VISUAL'] if ENV['VISUAL'] && !ENV['VISUAL'].empty?
return ENV['EDITOR'] if ENV['EDITOR'] && !ENV['EDITOR'].empty?
return 'notepad' if Helpers::Platform.windows?
%w[editor nano vi].detect do |editor|
system("which #{editor} > /dev/null 2>&1")
end
end
def self.auto_resize!
Pry.config.input # by default, load Readline

View file

@ -16,6 +16,48 @@ describe Pry::Editor do
@editor = Pry::Editor.new(Pry.new)
end
describe ".default" do
context "when $VISUAL is defined" do
before { ENV['VISUAL'] = 'emacs' }
after { ENV['VISUAL'] = nil }
it "returns the value of $VISUAL" do
expect(described_class.default).to eq('emacs')
end
end
context "when $EDITOR is defined" do
before { ENV['EDITOR'] = 'vim' }
after { ENV['EDITOR'] = nil }
it "returns the value of $EDITOR" do
expect(described_class.default).to eq('vim')
end
end
context "when platform is Windows" do
before do
allow(Pry::Helpers::Platform).to receive(:windows?).and_return(true)
end
it "returns 'notepad'" do
expect(described_class.default).to eq('notepad')
end
end
context "when no editor is detected" do
before { allow(Kernel).to receive(:system) }
%w[editor nano vi].each do |text_editor_name|
it "shells out to find '#{text_editor_name}'" do
expect(Kernel).to receive(:system)
.with("which #{text_editor_name} > /dev/null 2>&1")
described_class.default
end
end
end
end
describe "build_editor_invocation_string", skip: !Pry::Helpers::Platform.windows? do
it 'should shell-escape files' do
invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)