tty-editor 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  class Editor
5
- VERSION = '0.5.1'
5
+ VERSION = "0.6.0"
6
6
  end # Editor
7
7
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt
@@ -16,42 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: '0.22'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
27
- - !ruby/object:Gem::Dependency
28
- name: tty-which
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.4'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.5.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.5.0
26
+ version: '0.22'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: rake
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,42 +52,32 @@ dependencies:
80
52
  - - "~>"
81
53
  - !ruby/object:Gem::Version
82
54
  version: '3.0'
83
- description: Opens a file or text in the user's preferred editor.
55
+ description: Open a file or text in a terminal text editor.
84
56
  email:
85
- - me@piotrmurach.com
57
+ - piotr@piotrmurach.com
86
58
  executables: []
87
59
  extensions: []
88
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - CHANGELOG.md
63
+ - LICENSE.txt
89
64
  files:
90
65
  - CHANGELOG.md
91
66
  - LICENSE.txt
92
67
  - README.md
93
- - Rakefile
94
- - bin/console
95
- - bin/setup
96
- - examples/basic.rb
97
- - examples/choices.rb
98
- - examples/empty.rb
99
- - examples/env.rb
100
- - examples/tempfile.rb
101
68
  - lib/tty-editor.rb
102
69
  - lib/tty/editor.rb
103
70
  - lib/tty/editor/version.rb
104
- - spec/spec_helper.rb
105
- - spec/unit/available_spec.rb
106
- - spec/unit/command_path_spec.rb
107
- - spec/unit/command_spec.rb
108
- - spec/unit/executables_spec.rb
109
- - spec/unit/open_spec.rb
110
- - spec/unit/tempfile_path_spec.rb
111
- - tasks/console.rake
112
- - tasks/coverage.rake
113
- - tasks/spec.rake
114
- - tty-editor.gemspec
115
- homepage: https://piotrmurach.github.io/tty
71
+ homepage: https://ttytoolkit.org
116
72
  licenses:
117
73
  - MIT
118
- metadata: {}
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ bug_tracker_uri: https://github.com/piotrmurach/tty-editor/issues
77
+ changelog_uri: https://github.com/piotrmurach/tty-editor/blob/master/CHANGELOG.md
78
+ documentation_uri: https://www.rubydoc.info/gems/tty-editor
79
+ homepage_uri: https://ttytoolkit.org
80
+ source_code_uri: https://github.com/piotrmurach/tty-editor
119
81
  post_install_message:
120
82
  rdoc_options: []
121
83
  require_paths:
@@ -131,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
93
  - !ruby/object:Gem::Version
132
94
  version: '0'
133
95
  requirements: []
134
- rubygems_version: 3.0.3
96
+ rubygems_version: 3.1.2
135
97
  signing_key:
136
98
  specification_version: 4
137
- summary: Opens a file or text in the user's preferred editor.
99
+ summary: Open a file or text in a terminal text editor.
138
100
  test_files: []
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- task default: :spec
8
-
9
- desc 'Run all specs'
10
- task ci: %w[ spec ]
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tty/editor"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-editor'
4
-
5
- path = File.join(File.expand_path(File.dirname(__FILE__)), '../README.md')
6
-
7
- TTY::Editor.open(path)
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-editor'
4
-
5
- path = File.join(File.expand_path(File.dirname(__FILE__)), '../README.md')
6
-
7
- TTY::Editor.open(path) do |editor|
8
- editor.command :vim, :emacs
9
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-editor'
4
-
5
- TTY::Editor.open
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-editor'
4
-
5
- path = File.join(File.expand_path(File.dirname(__FILE__)), '../README.md')
6
-
7
- TTY::Editor.open(path, env: {"FOO" => "bar"})
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-editor'
4
-
5
- content = "Human madness is oftentimes a cunning and most feline thing.\n When you think it fled, it may have but become transfigured into some still subtler form."
6
-
7
- TTY::Editor.open(content: content)
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty/editor'
19
-
20
- module Helpers
21
- def fixtures_path(filename = nil)
22
- ::File.join(::File.dirname(__FILE__), 'fixtures', filename.to_s)
23
- end
24
-
25
- def tmp_path(filename = nil)
26
- File.join(File.dirname(__FILE__), '..', 'tmp', filename.to_s)
27
- end
28
- end
29
-
30
- RSpec.configure do |config|
31
- config.include(Helpers)
32
- config.expect_with :rspec do |expectations|
33
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
- end
35
-
36
- config.mock_with :rspec do |mocks|
37
- mocks.verify_partial_doubles = true
38
- end
39
-
40
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
41
- config.disable_monkey_patching!
42
-
43
- # This setting enables warnings. It's recommended, but in some cases may
44
- # be too noisy due to issues in dependencies.
45
- config.warnings = true
46
-
47
- if config.files_to_run.one?
48
- config.default_formatter = 'doc'
49
- end
50
-
51
- config.profile_examples = 2
52
-
53
- config.order = :random
54
-
55
- Kernel.srand config.seed
56
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Editor, '#available' do
4
- before do
5
- allow(ENV).to receive(:[]).with('VISUAL').and_return(nil)
6
- allow(ENV).to receive(:[]).with('EDITOR').and_return(nil)
7
- allow(TTY::Editor).to receive(:windows?).and_return(false)
8
- end
9
-
10
- it "detects editor from env" do
11
- allow(ENV).to receive(:[]).with('VISUAL').and_return('vi')
12
-
13
- expect(TTY::Editor.available).to eq(['vi'])
14
- end
15
-
16
- it "offers notepad editor on windows platform" do
17
- allow(TTY::Editor).to receive(:windows?).and_return(true)
18
-
19
- expect(TTY::Editor.available).to eq(['notepad'])
20
- end
21
-
22
- it 'finds a single editor on unix' do
23
- editor = TTY::Editor
24
- allow(editor).to receive(:exist?).and_return(false)
25
- allow(editor).to receive(:exist?).with('vim').and_return(true)
26
-
27
- expect(editor.available).to eql(['vim'])
28
- end
29
-
30
- it "finds all available editors" do
31
- editor = TTY::Editor
32
- allow(editor).to receive(:exist?).and_return(false)
33
- allow(editor).to receive(:exist?).with('vim').and_return(true)
34
- allow(editor).to receive(:exist?).with('emacs').and_return(true)
35
-
36
- expect(editor.available).to eql(['vim', 'emacs'])
37
- end
38
-
39
- it "doesn't find any editor on unix" do
40
- editor = TTY::Editor
41
- allow(editor).to receive(:exist?).and_return(false)
42
-
43
- expect(editor.available).to eq([])
44
- end
45
-
46
- it "uses custom editor" do
47
- editor = TTY::Editor
48
- name = 'sublime'
49
-
50
- expect(editor.available(name)).to eql([name])
51
- end
52
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Editor, '#command' do
4
- it 'escapes editor filename on Unix' do
5
- filename = "/usr/bin/hello world.rb"
6
- allow(::FileTest).to receive(:file?).with(filename).and_return(true)
7
- allow(::File).to receive(:exist?).with(filename).and_return(true)
8
- allow(TTY::Editor).to receive(:windows?).and_return(false)
9
-
10
- editor = TTY::Editor.new(filename, command: :vim)
11
-
12
- expect(editor.command_path).to eql("vim /usr/bin/hello\\ world.rb")
13
- end
14
-
15
- it "escapes path separators on Windows" do
16
- filename = 'C:\User\hello world.rb'
17
- allow(::FileTest).to receive(:file?).with(filename).and_return(true)
18
- allow(::File).to receive(:exist?).with(filename).and_return(true)
19
- allow(TTY::Editor).to receive(:windows?).and_return(true)
20
-
21
- editor = TTY::Editor.new(filename, command: :vim)
22
-
23
- expect(editor.command_path).to eql("vim C:\\\\User\\\\hello\\ world.rb")
24
- end
25
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Editor, '#command' do
4
- it 'specifies desired editor' do
5
- editor = TTY::Editor.new(fixtures_path('hello.txt'))
6
-
7
- allow(TTY::Editor).to receive(:available).and_return(['vim'])
8
- allow(TTY::Which).to receive(:which).with('vim').and_return('/usr/bin/vim')
9
-
10
- expect(editor.command).to eq('/usr/bin/vim')
11
- end
12
-
13
- it "doesn't find any available editor" do
14
- editor = TTY::Editor.new(fixtures_path('hello.txt'))
15
- allow(TTY::Editor).to receive(:available).and_return([])
16
-
17
- expect {
18
- editor.command
19
- }.to raise_error(TTY::Editor::EditorNotFoundError,
20
- /Could not find editor to use. Please specify \$VISUAL or \$EDITOR/)
21
- end
22
-
23
- it 'finds only one editor' do
24
- editor = TTY::Editor.new(fixtures_path('hello.txt'))
25
-
26
- allow(TTY::Editor).to receive(:available).and_return(['vim'])
27
- allow(TTY::Which).to receive(:which).with('vim').and_return('/usr/bin/vim')
28
-
29
- expect(editor.command).to eq('/usr/bin/vim')
30
- end
31
-
32
- it "finds more than one editor" do
33
- editor = TTY::Editor.new(fixtures_path('hello.txt'))
34
-
35
- prompt = double(:prompt, enum_select: 'vim')
36
-
37
- allow(TTY::Editor).to receive(:available).and_return(['vim', 'emacs'])
38
- allow(TTY::Which).to receive(:which).with('vim').and_return('/usr/bin/vim')
39
- allow(TTY::Prompt).to receive(:new).and_return(prompt)
40
-
41
- expect(editor.command).to eq('/usr/bin/vim')
42
- end
43
-
44
- it "caches editor name" do
45
- editor = TTY::Editor.new(fixtures_path('hello.txt'))
46
-
47
- allow(TTY::Editor).to receive(:available).and_return(['vim'])
48
- allow(TTY::Which).to receive(:which).with('vim').and_return('/usr/bin/vim')
49
-
50
- editor.command
51
- editor.command
52
-
53
- expect(TTY::Editor).to have_received(:available).once
54
- end
55
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Editor, '#executables' do
4
- it "returns default executables" do
5
- expect(TTY::Editor.executables).to be_an(Array)
6
- end
7
-
8
- it "includes default editor execs" do
9
- allow(ENV).to receive(:[]).with('VISUAL').and_return(nil)
10
- allow(ENV).to receive(:[]).with('EDITOR').and_return(nil)
11
-
12
- expect(TTY::Editor.executables).to eq([
13
- 'vim', 'vi', 'emacs', 'nano', 'nano-tiny', 'pico', 'mate -w'
14
- ])
15
- end
16
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
-
5
- RSpec.describe TTY::Editor, '#open' do
6
- before do
7
- ::FileUtils.mkdir_p(tmp_path)
8
- end
9
-
10
- after do
11
- ::FileUtils.rm_rf(tmp_path)
12
- end
13
-
14
-
15
- it "opens existing file" do
16
- file = fixtures_path('hello.txt')
17
- editor = TTY::Editor.new(file, command: :vim)
18
-
19
- allow(editor).to receive(:system).and_return(true)
20
- expect(editor.open).to eq(true)
21
-
22
- expect(editor).to have_received(:system).with({}, 'vim', file)
23
- end
24
-
25
- it "opens non-existing file without content" do
26
- new_file = File.join(tmp_path, 'new.rb')
27
- editor = TTY::Editor.new(new_file, command: :vim)
28
-
29
- allow(editor).to receive(:system).and_return(true)
30
- expect(editor.open).to eq(true)
31
-
32
- expect(::File.exist?(new_file)).to eq(true)
33
- expect(editor).to have_received(:system).with({}, 'vim', new_file)
34
- end
35
-
36
- it "opens non-existing file with new content" do
37
- new_file = File.join(tmp_path, 'new.rb')
38
- editor = TTY::Editor.new(new_file, content: 'Hello Ruby!', command: :vim)
39
-
40
- allow(editor).to receive(:system).and_return(true)
41
- expect(editor.open).to eq(true)
42
-
43
- expect(::File.read(new_file)).to eq("Hello Ruby!")
44
- expect(editor).to have_received(:system).with({}, 'vim', new_file)
45
- end
46
-
47
- it "opens existing file with existing content" do
48
- file = tmp_path('hello.txt')
49
- ::File.write(file, "Hello Ruby!\n")
50
- editor = TTY::Editor.new(file, content: 'more content', command: :vim)
51
-
52
- allow(editor).to receive(:system).and_return(true)
53
- expect(editor.open).to eq(true)
54
-
55
- expect(::File.read(file)).to eq("Hello Ruby!\nmore content")
56
- expect(editor).to have_received(:system).with({}, 'vim', file)
57
- end
58
-
59
- it "opens content in a temp file" do
60
- tmp_file = StringIO.new
61
- def tmp_file.path
62
- 'tty-editor-path'
63
- end
64
- allow(Tempfile).to receive(:new).and_return(tmp_file)
65
- allow(tmp_file).to receive(:<<)
66
- editor = TTY::Editor.new(content: 'Hello Ruby!', command: :vim)
67
-
68
- allow(editor).to receive(:system).and_return(true)
69
- expect(editor.open).to eq(true)
70
-
71
- expect(editor).to have_received(:system).with({}, 'vim', 'tty-editor-path')
72
- expect(tmp_file).to have_received(:<<).with('Hello Ruby!')
73
- end
74
-
75
- it "opens editor without filename or content" do
76
- editor = TTY::Editor.new(command: :vim)
77
- allow(editor).to receive(:system).and_return(true)
78
- expect(editor.open).to eq(true)
79
- expect(editor).to have_received(:system).with({}, 'vim', '')
80
- end
81
-
82
- it "fails to open non-file without content" do
83
- expect {
84
- TTY::Editor.open(fixtures_path)
85
- }.to raise_error(ArgumentError, /Don't know how to handle `#{fixtures_path}`./)
86
- end
87
-
88
- it 'opens file in editor with known command' do
89
- invocable = double(:invocable, open: nil)
90
- allow(TTY::Editor).to receive(:new).
91
- with('hello.rb', command: :vim).and_return(invocable)
92
-
93
- TTY::Editor.open('hello.rb', command: :vim)
94
-
95
- expect(TTY::Editor).to have_received(:new).with('hello.rb', command: :vim)
96
- end
97
-
98
- it 'fails to open editor with unknown command' do
99
- expect {
100
- TTY::Editor.open(fixtures_path('hello.txt'), command: :unknown)
101
- }.to raise_error(TTY::Editor::CommandInvocationError)
102
- end
103
- end