pry-shell 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/pry/shell.rb +11 -3
- data/lib/pry/shell/client.rb +8 -0
- data/lib/pry/shell/io/editor.rb +36 -0
- data/lib/pry/shell/io/input.rb +10 -0
- data/lib/pry/shell/io/pager.rb +47 -0
- data/lib/pry/shell/patches/pager.rb +15 -0
- data/lib/pry/shell/patches/pry_byebug.rb +24 -0
- data/lib/pry/shell/patches/rack_timeout.rb +21 -0
- data/lib/pry/shell/registry.rb +9 -4
- data/lib/pry/shell/repl.rb +42 -0
- data/lib/pry/shell/session.rb +21 -7
- data/lib/pry/shell/ui/about.rb +2 -2
- data/lib/pry/shell/version.rb +1 -1
- metadata +8 -3
- data/lib/pry/shell/patches/repl.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f78367d80e34ffed27c18d3dfea89c22f3efc65fde39b043ac07628d6715b9c
|
4
|
+
data.tar.gz: 5b0e36dfdefe005810de67b5b41dcf4472b8e71744b325a2bdeab9be7bb42c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d03a089b432e1e91c0a4210965d8faca9ef584d06d633fda07c8abace3e671962d38bff45b6d328fc3728075591a08c280659a5094714a66acaf42c5e4bd8e
|
7
|
+
data.tar.gz: 392014b4371beace17450468b5d2000ea1fb48419a5af4dc39c6d9ad346ff91ddf4ff38d20b3a259608463dabe4220d61cf181eaa566f78a2d7cbe3f6fe4c93a
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/lib/pry/shell.rb
CHANGED
@@ -8,10 +8,10 @@ require_relative "shell/registry"
|
|
8
8
|
require_relative "shell/server"
|
9
9
|
require_relative "shell/session"
|
10
10
|
require_relative "shell/io/base"
|
11
|
+
require_relative "shell/io/editor"
|
11
12
|
require_relative "shell/io/input"
|
12
13
|
require_relative "shell/io/output"
|
13
|
-
require_relative "shell/
|
14
|
-
require_relative "shell/patches/repl"
|
14
|
+
require_relative "shell/io/pager"
|
15
15
|
require_relative "shell/ui"
|
16
16
|
require_relative "shell/ui/base"
|
17
17
|
require_relative "shell/ui/about"
|
@@ -22,7 +22,7 @@ require_relative "shell/ui/session"
|
|
22
22
|
class Pry
|
23
23
|
class Shell
|
24
24
|
DEFAULT_HOST = "localhost"
|
25
|
-
DEFAULT_PORT = "
|
25
|
+
DEFAULT_PORT = "1881"
|
26
26
|
|
27
27
|
class << self
|
28
28
|
attr_reader :registry
|
@@ -32,6 +32,14 @@ class Pry
|
|
32
32
|
|
33
33
|
new(host, port, registry).run
|
34
34
|
end
|
35
|
+
|
36
|
+
def active_shell_options(thread: Thread.current)
|
37
|
+
thread[:active_shell_options]
|
38
|
+
end
|
39
|
+
|
40
|
+
def active_shell_options=(value)
|
41
|
+
Thread.current[:active_shell_options] = value
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
def initialize(host, port, registry)
|
data/lib/pry/shell/client.rb
CHANGED
@@ -27,6 +27,14 @@ class Pry
|
|
27
27
|
@output ||= IO::Output.new(self, Pry.config.output)
|
28
28
|
end
|
29
29
|
|
30
|
+
def editor
|
31
|
+
@editor ||= proc { |file, line| IO::Editor.open(file, line) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def pager_proxy
|
35
|
+
@pager_proxy ||= IO::Pager::Proxy.new(output)
|
36
|
+
end
|
37
|
+
|
30
38
|
def to_s
|
31
39
|
"#{process_name} @#{host} - #{full_location}"
|
32
40
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Shell
|
5
|
+
module IO
|
6
|
+
class Editor
|
7
|
+
DUMMY_RETURN = "true"
|
8
|
+
|
9
|
+
def self.open(file, line)
|
10
|
+
new(file, line).open && DUMMY_RETURN
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(file, line)
|
14
|
+
@file = file
|
15
|
+
@line = line
|
16
|
+
end
|
17
|
+
|
18
|
+
def open
|
19
|
+
File.write(file, proxy_editor)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :file, :line
|
25
|
+
|
26
|
+
def proxy_editor
|
27
|
+
Pry::Editor.new(Pry.new).edit_tempfile_with_content(content, line)
|
28
|
+
end
|
29
|
+
|
30
|
+
def content
|
31
|
+
File.read(file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/pry/shell/io/input.rb
CHANGED
@@ -13,6 +13,16 @@ class Pry
|
|
13
13
|
|
14
14
|
Command.execute(client, string)
|
15
15
|
end
|
16
|
+
|
17
|
+
# Assigns the `completion_proc` given by the
|
18
|
+
# pry instance from the client slide.
|
19
|
+
def completion_proc=(val)
|
20
|
+
object.completion_proc = val if object.respond_to?(:completion_proc=)
|
21
|
+
end
|
22
|
+
|
23
|
+
def completion_proc
|
24
|
+
object.completion_proc if object.respond_to?(:completion_proc)
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Shell
|
5
|
+
module IO
|
6
|
+
class Pager < Pry::Pager
|
7
|
+
class Output < Pry::Output
|
8
|
+
def initialize(output) # rubocop:disable Lint/MissingSuper
|
9
|
+
@output = output
|
10
|
+
@color = Pry.config.color
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Proxy < Base
|
15
|
+
attr_reader :pager
|
16
|
+
|
17
|
+
def initialize(output) # rubocop:disable Lint/MissingSuper
|
18
|
+
output_proxy = Output.new(output)
|
19
|
+
@pager = Pager.new(output_proxy)
|
20
|
+
end
|
21
|
+
|
22
|
+
def page(text)
|
23
|
+
pager.page(text)
|
24
|
+
end
|
25
|
+
|
26
|
+
def open(&block)
|
27
|
+
pager.open(&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :output
|
32
|
+
|
33
|
+
def initialize(output) # rubocop:disable Lint/MissingSuper
|
34
|
+
@output = output
|
35
|
+
end
|
36
|
+
|
37
|
+
def best_available
|
38
|
+
if !Pry::Pager::SystemPager.available? || Pry::Helpers::Platform.jruby?
|
39
|
+
Pry::Pager::SimplePager.new(output)
|
40
|
+
else
|
41
|
+
Pry::Pager::SystemPager.new(output)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Shell
|
5
|
+
module Patches
|
6
|
+
module PryByebug
|
7
|
+
def start_with_pry_byebug(target = nil, options = {})
|
8
|
+
return start_without_pry_byebug(target, options) if Shell.active_shell_options
|
9
|
+
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require "pry-byebug"
|
19
|
+
require "pry-byebug/pry_ext"
|
20
|
+
|
21
|
+
Pry.singleton_class.prepend(Pry::Shell::Patches::PryByebug)
|
22
|
+
Pry.singleton_class.alias_method(:start, :start_with_pry_byebug)
|
23
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Shell
|
5
|
+
module Patches
|
6
|
+
module RackTimeout
|
7
|
+
def initialize(&on_timeout)
|
8
|
+
@on_timeout = -> (thread) { Shell.active_shell_options(thread: thread) || on_timeout || ON_TIMEOUT }
|
9
|
+
@scheduler = Rack::Timeout::Scheduler.singleton
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
require "rack-timeout"
|
18
|
+
|
19
|
+
Rack::Timeout::Scheduler::Timeout.prepend(Pry::Shell::Patches::RackTimeout)
|
20
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
21
|
+
end
|
data/lib/pry/shell/registry.rb
CHANGED
@@ -7,11 +7,12 @@ class Pry
|
|
7
7
|
class Registry
|
8
8
|
include DRb::DRbUndumped
|
9
9
|
|
10
|
-
attr_reader :auto_connect, :clients, :current
|
10
|
+
attr_reader :auto_connect, :clients, :current, :mutex
|
11
11
|
|
12
12
|
def initialize(auto_connect)
|
13
13
|
@auto_connect = auto_connect
|
14
14
|
@clients = {}
|
15
|
+
@mutex = Mutex.new
|
15
16
|
end
|
16
17
|
|
17
18
|
def register(id:, name:, host:, location:)
|
@@ -26,10 +27,14 @@ class Pry
|
|
26
27
|
def connect_to(client)
|
27
28
|
# This thread is necessary because `UI::Session.draw!`
|
28
29
|
# puts the main thread into sleep!
|
29
|
-
|
30
|
-
|
30
|
+
mutex.synchronize do
|
31
|
+
return if current
|
31
32
|
|
32
|
-
|
33
|
+
Thread.start do
|
34
|
+
UI::Session.draw!
|
35
|
+
|
36
|
+
@current = client
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pry"
|
4
|
+
|
5
|
+
class Pry
|
6
|
+
class Shell
|
7
|
+
class Repl < Pry::REPL
|
8
|
+
def read_line(current_prompt)
|
9
|
+
handle_read_errors do
|
10
|
+
setup_auto_completion
|
11
|
+
read_command(current_prompt)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def setup_auto_completion
|
18
|
+
if coolline_available?
|
19
|
+
input.completion_proc = proc do |cool|
|
20
|
+
completions = @pry.complete cool.completed_word
|
21
|
+
completions.compact
|
22
|
+
end
|
23
|
+
elsif input.respond_to? :completion_proc=
|
24
|
+
input.completion_proc = proc do |inp|
|
25
|
+
@pry.complete inp
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def read_command(current_prompt)
|
31
|
+
if readline_available?
|
32
|
+
set_readline_output
|
33
|
+
input_readline(current_prompt, false) # false since we'll add it manually
|
34
|
+
elsif coolline_available?
|
35
|
+
input_readline(current_prompt)
|
36
|
+
else
|
37
|
+
input_readline(current_prompt)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/pry/shell/session.rb
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
require "socket"
|
4
4
|
require "securerandom"
|
5
5
|
|
6
|
+
require_relative "patches/object"
|
7
|
+
require_relative "patches/pager"
|
8
|
+
require_relative "patches/pry_byebug"
|
9
|
+
require_relative "patches/rack_timeout"
|
10
|
+
require_relative "repl"
|
11
|
+
|
6
12
|
class Pry
|
7
13
|
class Shell
|
8
14
|
class Session
|
@@ -19,17 +25,30 @@ class Pry
|
|
19
25
|
end
|
20
26
|
|
21
27
|
def run
|
22
|
-
|
28
|
+
Shell.active_shell_options = pry_options
|
23
29
|
|
24
|
-
Pry.start(object)
|
30
|
+
Pry.start(object, pry_options)
|
25
31
|
rescue DRb::DRbConnError
|
26
32
|
puts "DRb connection failed!"
|
33
|
+
ensure
|
34
|
+
Shell.active_shell_options = nil
|
27
35
|
end
|
28
36
|
|
29
37
|
private
|
30
38
|
|
31
39
|
attr_reader :object, :host, :port
|
32
40
|
|
41
|
+
def pry_options
|
42
|
+
{
|
43
|
+
driver: Pry::Shell::Repl,
|
44
|
+
pager: false,
|
45
|
+
input: client.input,
|
46
|
+
output: client.output,
|
47
|
+
editor: client.editor,
|
48
|
+
pager_proxy: client.pager_proxy # This is our own config
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
33
52
|
def client
|
34
53
|
@client ||= registry.register(id: id, **attributes)
|
35
54
|
end
|
@@ -52,11 +71,6 @@ class Pry
|
|
52
71
|
def uri
|
53
72
|
"druby://#{host}:#{port}"
|
54
73
|
end
|
55
|
-
|
56
|
-
def setup
|
57
|
-
Pry.config.input = client.input
|
58
|
-
Pry.config.output = client.output
|
59
|
-
end
|
60
74
|
end
|
61
75
|
end
|
62
76
|
end
|
data/lib/pry/shell/ui/about.rb
CHANGED
@@ -6,10 +6,10 @@ class Pry
|
|
6
6
|
class About < Base
|
7
7
|
HEADER = "PRY-SHELL About"
|
8
8
|
CONTENT = <<~MARKDOWN
|
9
|
-
pry-shell version
|
9
|
+
pry-shell version "#{VERSION}"
|
10
10
|
|
11
11
|
Pry-shell provides you a standalone shell for accessing multiple `pry` sessions running on different processes.
|
12
|
-
You can switch between sessions by using
|
12
|
+
You can switch between sessions by using the "\\h" command.
|
13
13
|
|
14
14
|
Written by Mehmet Emin INAC.
|
15
15
|
MARKDOWN
|
data/lib/pry/shell/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Emin INAC
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -76,12 +76,17 @@ files:
|
|
76
76
|
- lib/pry/shell/client.rb
|
77
77
|
- lib/pry/shell/command.rb
|
78
78
|
- lib/pry/shell/io/base.rb
|
79
|
+
- lib/pry/shell/io/editor.rb
|
79
80
|
- lib/pry/shell/io/input.rb
|
80
81
|
- lib/pry/shell/io/output.rb
|
82
|
+
- lib/pry/shell/io/pager.rb
|
81
83
|
- lib/pry/shell/logger.rb
|
82
84
|
- lib/pry/shell/patches/object.rb
|
83
|
-
- lib/pry/shell/patches/
|
85
|
+
- lib/pry/shell/patches/pager.rb
|
86
|
+
- lib/pry/shell/patches/pry_byebug.rb
|
87
|
+
- lib/pry/shell/patches/rack_timeout.rb
|
84
88
|
- lib/pry/shell/registry.rb
|
89
|
+
- lib/pry/shell/repl.rb
|
85
90
|
- lib/pry/shell/server.rb
|
86
91
|
- lib/pry/shell/session.rb
|
87
92
|
- lib/pry/shell/ui.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pry"
|
4
|
-
|
5
|
-
class Pry
|
6
|
-
class Shell
|
7
|
-
module Patches
|
8
|
-
module Repl
|
9
|
-
def read_line(current_prompt)
|
10
|
-
handle_read_errors do
|
11
|
-
setup_auto_completion
|
12
|
-
read_command(current_prompt)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def setup_auto_completion
|
19
|
-
if coolline_available?
|
20
|
-
input.completion_proc = proc do |cool|
|
21
|
-
completions = @pry.complete cool.completed_word
|
22
|
-
completions.compact
|
23
|
-
end
|
24
|
-
elsif input.respond_to? :completion_proc=
|
25
|
-
input.completion_proc = proc do |inp|
|
26
|
-
@pry.complete inp
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def read_command(current_prompt)
|
32
|
-
if readline_available?
|
33
|
-
set_readline_output
|
34
|
-
input_readline(current_prompt, false) # false since we'll add it manually
|
35
|
-
elsif coolline_available?
|
36
|
-
input_readline(current_prompt)
|
37
|
-
else
|
38
|
-
input_readline(current_prompt)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
Pry::REPL.prepend(Pry::Shell::Patches::Repl)
|