pry-shell 0.1.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd9174cd55c1ae7d73d49eca821fa5fedc1b39547c2cfad9437504694c5cca81
4
- data.tar.gz: a57cda5282d83b3344277183b1cc3ed2893c413f6d0c18c0f36bf3649c9ef276
3
+ metadata.gz: 7ca5d9147b6818a50cab7d99b12452420053564e4fd09f25b007693a043e9ab7
4
+ data.tar.gz: e1aef7a03b4c1ed8b7cbe786da99335ed34014995c0abf045cee1f21a359bed4
5
5
  SHA512:
6
- metadata.gz: adfcbfe796953dccdb68c366722b82f0d8ba5115e7431f7583079c47774006ac88829d2bd8a3cda8a13b53ed0aa6aa50798d88e98bbaa9154c63c0ffe4603f8f
7
- data.tar.gz: b1d14c0e9f591f955471979b1d96716021bded61885efb33cf3cb46e1d23346c3f779867366eb42bb3b5ae2b2281cd8c712df7546759ce5bd650dba8e2326dff
6
+ metadata.gz: fdd570f82dd49a3ef2436cb4d355f8dbf8093fe2e67e9d7de665642c919b9aa8ffa946fec75e273a51c2005f5755f14f3bb5e1adacb3a21f9d1b220d2f5b621b
7
+ data.tar.gz: 055d2e42e2ee36529f0f6c44de96b49953ada94caea806d02e847f79e46b4bcffb314fe343acdc340cda7b43f55fb421305d9f77157732dd874ddf6ab1d3ecc2
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /log/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/.rubocop.yml CHANGED
@@ -19,3 +19,6 @@ Style/StringLiteralsInInterpolation:
19
19
 
20
20
  Layout/LineLength:
21
21
  Max: 120
22
+
23
+ Layout/SpaceInLambdaLiteral:
24
+ Enabled: false
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in pry-shell.gemspec
6
6
  gemspec
7
7
 
8
+ gem "pry-byebug"
8
9
  gem "rake", "~> 13.0"
9
10
  gem "rspec", "~> 3.0"
10
11
  gem "rubocop", "~> 1.7"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pry-shell (0.1.0)
4
+ pry-shell (0.4.1)
5
5
  pry (~> 0.13.0)
6
6
  tty-markdown
7
7
  tty-prompt
@@ -10,6 +10,7 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
+ byebug (11.1.3)
13
14
  coderay (1.1.3)
14
15
  diff-lcs (1.4.4)
15
16
  kramdown (2.3.1)
@@ -23,6 +24,9 @@ GEM
23
24
  pry (0.13.1)
24
25
  coderay (~> 1.1)
25
26
  method_source (~> 1.0)
27
+ pry-byebug (3.9.0)
28
+ byebug (~> 11.0)
29
+ pry (~> 0.13.0)
26
30
  rainbow (3.0.0)
27
31
  rake (13.0.3)
28
32
  regexp_parser (2.1.1)
@@ -83,6 +87,7 @@ PLATFORMS
83
87
  x86_64-darwin-19
84
88
 
85
89
  DEPENDENCIES
90
+ pry-byebug
86
91
  pry-shell!
87
92
  rake (~> 13.0)
88
93
  rspec (~> 3.0)
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Here's a [video showing how to use pry-shell](https://www.youtube.com/watch?v=Lzs_PL_BySo).
26
26
 
27
27
  ## Development
28
28
 
data/bin/console CHANGED
@@ -11,6 +11,20 @@ require "pry/shell"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- a = 1
14
+ def foo1
15
+ binding.pry_shell(with_byebug: true)
15
16
 
16
- binding.pry_shell
17
+ foo2
18
+ end
19
+
20
+ def foo2
21
+ foo3
22
+ end
23
+
24
+ def foo3
25
+ 5
26
+ end
27
+
28
+ a = 5 + foo1
29
+
30
+ puts a
data/lib/pry/shell.rb CHANGED
@@ -3,18 +3,21 @@
3
3
  require_relative "shell/version"
4
4
  require_relative "shell/client"
5
5
  require_relative "shell/command"
6
+ require_relative "shell/configuration"
6
7
  require_relative "shell/logger"
7
8
  require_relative "shell/registry"
8
9
  require_relative "shell/server"
9
10
  require_relative "shell/session"
10
11
  require_relative "shell/io/base"
12
+ require_relative "shell/io/editor"
11
13
  require_relative "shell/io/input"
12
14
  require_relative "shell/io/output"
13
- require_relative "shell/patches/object"
14
- require_relative "shell/patches/repl"
15
+ require_relative "shell/io/pager"
15
16
  require_relative "shell/ui"
16
17
  require_relative "shell/ui/base"
17
18
  require_relative "shell/ui/about"
19
+ require_relative "shell/ui/configuration"
20
+ require_relative "shell/ui/configuration/auto_connect"
18
21
  require_relative "shell/ui/list"
19
22
  require_relative "shell/ui/menu"
20
23
  require_relative "shell/ui/session"
@@ -22,39 +25,49 @@ require_relative "shell/ui/session"
22
25
  class Pry
23
26
  class Shell
24
27
  DEFAULT_HOST = "localhost"
25
- DEFAULT_PORT = "8787"
28
+ DEFAULT_PORT = "1881"
26
29
 
27
30
  class << self
28
- attr_reader :registry
31
+ def run
32
+ run_server
33
+ draw_ui
34
+ rescue TTY::Reader::InputInterrupt, Interrupt
35
+ exit
36
+ end
29
37
 
30
- def run(host:, port:, auto_connect:)
31
- @registry = Registry.new(auto_connect)
38
+ def active_shell_options(thread: Thread.current)
39
+ thread[:active_shell_options]
40
+ end
32
41
 
33
- new(host, port, registry).run
42
+ def active_shell_options=(value)
43
+ Thread.current[:active_shell_options] = value
34
44
  end
35
- end
36
45
 
37
- def initialize(host, port, registry)
38
- @host = host
39
- @port = port
40
- @registry = registry
41
- end
46
+ def clear_shell_options!
47
+ self.active_shell_options = nil
48
+ end
42
49
 
43
- def run
44
- run_server
45
- draw_ui
46
- end
50
+ def remove_active_connection!
51
+ active_shell_options&.fetch(:remove_connection)&.call
52
+ end
47
53
 
48
- private
54
+ def configuration
55
+ @configuration ||= Configuration.new
56
+ end
49
57
 
50
- attr_reader :host, :port, :registry
58
+ def registry
59
+ @registry ||= Registry.new
60
+ end
51
61
 
52
- def run_server
53
- Server.new(host, port, registry).run
54
- end
62
+ private
55
63
 
56
- def draw_ui
57
- UI.draw!
64
+ def run_server
65
+ Server.run
66
+ end
67
+
68
+ def draw_ui
69
+ UI.draw!
70
+ end
58
71
  end
59
72
  end
60
73
  end
data/lib/pry/shell/cli.rb CHANGED
@@ -10,35 +10,27 @@ class Pry
10
10
  def run
11
11
  options.parse!
12
12
 
13
- Shell.run(**config)
13
+ Shell.run
14
14
 
15
15
  join_drb_thread
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- def config
21
- @config ||= {
22
- host: DEFAULT_HOST,
23
- port: DEFAULT_PORT,
24
- auto_connect: false
25
- }
26
- end
27
-
28
20
  def options # rubocop:disable Metrics/MethodLength
29
21
  @parser = OptionParser.new do |o|
30
22
  o.banner = "Usage: bundle exec pry-shell [options]"
31
23
 
32
24
  o.on "-h", "--host HOST", "Host name" do |arg|
33
- config[:host] = arg
25
+ Shell.configuration.host = arg
34
26
  end
35
27
 
36
28
  o.on "-p", "--post PORT", "Port of the shell application" do |arg|
37
- config[:port] = arg
29
+ Shell.configuration.port = arg
38
30
  end
39
31
 
40
32
  o.on "-a", "--auto-connect", "Connect automatically to the first Pry session" do
41
- config[:auto_connect] = true
33
+ Shell.configuration.auto_connect = true
42
34
  end
43
35
 
44
36
  o.on "-v", "--version", "Print version and exit" do
@@ -9,13 +9,16 @@ class Pry
9
9
  # we should make sure the instance lives on the server.
10
10
  include DRb::DRbUndumped
11
11
 
12
+ MAX_PROCESS_NAME = 50
13
+
12
14
  attr_reader :id
13
15
 
14
- def initialize(id, process_name, host, location)
16
+ def initialize(id, process_name, host, pid, location)
15
17
  @id = id
16
18
  @process_name = process_name
17
19
  @host = host
18
20
  @location = location
21
+ @pid = pid
19
22
  @created_at = Time.now
20
23
  end
21
24
 
@@ -27,8 +30,16 @@ class Pry
27
30
  @output ||= IO::Output.new(self, Pry.config.output)
28
31
  end
29
32
 
33
+ def editor
34
+ @editor ||= proc { |file, line| IO::Editor.open(file, line) }
35
+ end
36
+
37
+ def pager_proxy
38
+ @pager_proxy ||= IO::Pager::Proxy.new(output)
39
+ end
40
+
30
41
  def to_s
31
- "#{process_name} @#{host} - #{full_location}"
42
+ "[#{pid}] \"#{humanized_process_name}\" @\"#{host}\" - #{full_location}"
32
43
  end
33
44
 
34
45
  def current?
@@ -37,11 +48,15 @@ class Pry
37
48
 
38
49
  private
39
50
 
40
- attr_reader :process_name, :host, :location, :created_at
51
+ attr_reader :process_name, :host, :pid, :location, :created_at
41
52
 
42
53
  def full_location
43
54
  location.join(":")
44
55
  end
56
+
57
+ def humanized_process_name
58
+ process_name.length > MAX_PROCESS_NAME ? "#{process_name[0..50]}..." : process_name
59
+ end
45
60
  end
46
61
  end
47
62
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Shell
5
+ class Configuration
6
+ CONFIG_KEYS = {
7
+ host: "localhost",
8
+ port: "1881",
9
+ auto_connect: false
10
+ }.freeze
11
+
12
+ CONFIG_KEYS.each do |config_key, default_value|
13
+ attr_writer config_key
14
+
15
+ define_method(config_key) do
16
+ return default_value unless instance_variable_defined?("@#{config_key}")
17
+
18
+ instance_variable_get("@#{config_key}")
19
+ end
20
+ end
21
+ end
22
+ end
23
+ 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
@@ -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
@@ -7,7 +7,7 @@ require "fileutils"
7
7
  class Pry
8
8
  class Shell
9
9
  class Logger
10
- LOG_FOLDER = "tmp"
10
+ LOG_FOLDER = "log"
11
11
 
12
12
  class << self
13
13
  extend Forwardable
@@ -4,8 +4,8 @@ class Pry
4
4
  class Shell
5
5
  module Patches
6
6
  module Object
7
- def pry_shell(host: DEFAULT_HOST, port: DEFAULT_PORT)
8
- Session.run(self, host: host, port: port)
7
+ def pry_shell(host: DEFAULT_HOST, port: DEFAULT_PORT, with_byebug: false)
8
+ Session.run(self, host: host, port: port, with_byebug: with_byebug)
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Shell
5
+ module Patches
6
+ module Pager
7
+ def pager
8
+ config.pager_proxy || super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Pry.prepend(Pry::Shell::Patches::Pager)
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "pry-byebug"
5
+ require "pry-byebug/pry_ext"
6
+
7
+ module Byebug
8
+ class PryShellProcessor < PryProcessor
9
+ class << self
10
+ def start
11
+ Byebug.start
12
+ Setting[:autolist] = false
13
+ Context.processor = self
14
+ Byebug.current_context.step_out(7, true)
15
+ at_exit { teardown! }
16
+ end
17
+
18
+ private
19
+
20
+ def teardown!
21
+ Pry::Shell.remove_active_connection!
22
+ Pry::Shell.clear_shell_options!
23
+ end
24
+ end
25
+
26
+ def resume_pry
27
+ run do
28
+ pry_started? ? start_new_pry_repl : start_new_pry_session
29
+ end
30
+ rescue DRb::DRbConnError
31
+ puts "DRb connection failed!"
32
+ end
33
+
34
+ private
35
+
36
+ def pry_started?
37
+ defined?(@pry) && @pry
38
+ end
39
+
40
+ def start_new_pry_session
41
+ @pry = Pry.start_without_pry_byebug(frame._binding, Pry::Shell.active_shell_options)
42
+ end
43
+
44
+ def start_new_pry_repl
45
+ Pry::Shell::Repl.new(@pry, target: frame._binding).start
46
+ end
47
+ end
48
+ end
49
+
50
+ class Pry
51
+ class Shell
52
+ module Patches
53
+ module PryByebug
54
+ def start_with_pry_byebug(target = nil, options = {})
55
+ return start_with_pry_shell(target) if Shell.active_shell_options
56
+
57
+ super
58
+ end
59
+
60
+ def start_with_pry_shell(target)
61
+ if Shell.active_shell_options[:with_byebug]
62
+ ::Byebug::PryShellProcessor.start
63
+ else
64
+ start_without_pry_byebug(target, Shell.active_shell_options)
65
+ end
66
+ end
67
+ end
68
+
69
+ module PryProcessor
70
+ def start
71
+ super
72
+
73
+ # We should step out one more frame as we are
74
+ # prepending another module to the hierarchy
75
+ ::Byebug.current_context.step_out(5, true)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ Pry.singleton_class.prepend(Pry::Shell::Patches::PryByebug)
83
+ Pry.singleton_class.alias_method(:start, :start_with_pry_byebug)
84
+
85
+ Byebug::PryProcessor.singleton_class.prepend(Pry::Shell::Patches::PryProcessor)
86
+ rescue LoadError # rubocop:disable Lint/SuppressedException
87
+ 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
@@ -7,29 +7,33 @@ class Pry
7
7
  class Registry
8
8
  include DRb::DRbUndumped
9
9
 
10
- attr_reader :auto_connect, :clients, :current
10
+ attr_reader :clients, :current, :mutex
11
11
 
12
- def initialize(auto_connect)
13
- @auto_connect = auto_connect
12
+ def initialize
14
13
  @clients = {}
14
+ @mutex = Mutex.new
15
15
  end
16
16
 
17
- def register(id:, name:, host:, location:)
18
- Client.new(id, name, host, location).tap do |client|
17
+ def register(id:, name:, host:, pid:, location:)
18
+ Client.new(id, name, host, pid, location).tap do |client|
19
19
  Logger.debug("New client connected - #{client}")
20
20
 
21
21
  @clients[id] = client
22
- connect_to(client) if auto_connect
22
+ connect_to(client) if Shell.configuration.auto_connect
23
23
  end
24
24
  end
25
25
 
26
26
  def connect_to(client)
27
27
  # This thread is necessary because `UI::Session.draw!`
28
28
  # puts the main thread into sleep!
29
- Thread.start do
30
- UI::Session.draw!
29
+ mutex.synchronize do
30
+ return if current
31
31
 
32
- @current = client
32
+ Thread.start do
33
+ UI::Session.draw!
34
+
35
+ @current = client
36
+ end
33
37
  end
34
38
  end
35
39
 
@@ -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
@@ -5,24 +5,18 @@ require "drb"
5
5
  class Pry
6
6
  class Shell
7
7
  class Server
8
- def initialize(host, port, registry)
9
- @host = host
10
- @port = port
11
- @registry = registry
12
- end
13
-
14
- def run
15
- Logger.info("Running Drb server on '#{uri}'")
16
-
17
- DRb.start_service(uri, registry)
18
- end
8
+ class << self
9
+ def run
10
+ Logger.info("Running Drb server on '#{uri}'")
19
11
 
20
- private
12
+ DRb.start_service(uri, Shell.registry)
13
+ end
21
14
 
22
- attr_reader :host, :port, :registry
15
+ private
23
16
 
24
- def uri
25
- "druby://#{host}:#{port}"
17
+ def uri
18
+ "druby://#{Shell.configuration.host}:#{Shell.configuration.port}"
19
+ end
26
20
  end
27
21
  end
28
22
  end
@@ -3,32 +3,59 @@
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
9
15
  class << self
10
- def run(object, host:, port:)
11
- new(object, host, port).run
16
+ def run(object, host:, port:, with_byebug:)
17
+ new(object, host, port, with_byebug).run
12
18
  end
13
19
  end
14
20
 
15
- def initialize(object, host, port)
21
+ def initialize(object, host, port, with_byebug)
16
22
  @object = object
17
23
  @host = host
18
24
  @port = port
25
+ @with_byebug = with_byebug
19
26
  end
20
27
 
21
28
  def run
22
- setup
29
+ Shell.active_shell_options = pry_options
23
30
 
24
- Pry.start(object)
31
+ Pry.start(object, pry_options)
25
32
  rescue DRb::DRbConnError
26
33
  puts "DRb connection failed!"
34
+ ensure
35
+ # Since we run `Byebug.current_context.step_out` this ensure
36
+ # block already runs and clears the options which are necessary
37
+ # to setup the Byebug.
38
+ # We are clearing this options in `PryShellProcessor` to ensure
39
+ # they do not leak.
40
+ Shell.clear_shell_options! unless with_byebug
27
41
  end
28
42
 
29
43
  private
30
44
 
31
- attr_reader :object, :host, :port
45
+ attr_reader :object, :host, :port, :with_byebug
46
+
47
+ def pry_options
48
+ {
49
+ remove_connection: -> { registry.remove(client) },
50
+ with_byebug: with_byebug,
51
+ driver: Pry::Shell::Repl,
52
+ pager: false,
53
+ input: client.input,
54
+ output: client.output,
55
+ editor: client.editor,
56
+ pager_proxy: client.pager_proxy # This is our own config
57
+ }
58
+ end
32
59
 
33
60
  def client
34
61
  @client ||= registry.register(id: id, **attributes)
@@ -46,17 +73,17 @@ class Pry
46
73
  end
47
74
 
48
75
  def attributes
49
- { name: $PROGRAM_NAME, host: Socket.gethostname, location: object.source_location }
76
+ {
77
+ name: $PROGRAM_NAME,
78
+ host: Socket.gethostname,
79
+ pid: Process.pid,
80
+ location: object.source_location
81
+ }
50
82
  end
51
83
 
52
84
  def uri
53
85
  "druby://#{host}:#{port}"
54
86
  end
55
-
56
- def setup
57
- Pry.config.input = client.input
58
- Pry.config.output = client.output
59
- end
60
87
  end
61
88
  end
62
89
  end
data/lib/pry/shell/ui.rb CHANGED
@@ -8,6 +8,7 @@ class Pry
8
8
  class << self
9
9
  def draw!
10
10
  UI::Menu.draw!
11
+ draw!
11
12
  rescue StopMainUI
12
13
  sleep
13
14
  draw!
@@ -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 `0.0.1`
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 XXX command.
12
+ You can switch between sessions by going back to the menu using the "\\m" command.
13
13
 
14
14
  Written by Mehmet Emin INAC.
15
15
  MARKDOWN
@@ -42,7 +42,7 @@ class Pry
42
42
  end
43
43
 
44
44
  def draw_footer
45
- return_menu_prompt
45
+ prompt.keypress("Press any key to return to the menu...")
46
46
  end
47
47
 
48
48
  def header
@@ -60,12 +60,6 @@ class Pry
60
60
  def print_markdown(text)
61
61
  puts TTY::Markdown.parse(text)
62
62
  end
63
-
64
- def return_menu_prompt
65
- prompt.keypress("Press any key to return to the menu...")
66
-
67
- Menu.draw!
68
- end
69
63
  end
70
64
  end
71
65
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Shell
5
+ class UI
6
+ class Configuration < Base
7
+ HEADER = "PRY-SHELL Configuration"
8
+ ITEMS = [
9
+ { name: "Auto-connect", value: "auto_connect" },
10
+ { name: "Go back to menu", value: "menu" }
11
+ ].freeze
12
+ ACTIONS = {
13
+ "auto_connect" => -> { AutoConnect.draw! & draw! },
14
+ "menu" => -> {}
15
+ }.freeze
16
+
17
+ class << self
18
+ def draw_content
19
+ selection = prompt.select("Select a configuration item to change it's value", ITEMS)
20
+
21
+ ACTIONS[selection].call
22
+ end
23
+
24
+ def draw_footer; end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Shell
5
+ class UI
6
+ class Configuration
7
+ class AutoConnect < Base
8
+ class << self
9
+ def draw!
10
+ Shell.configuration.auto_connect = show_prompt
11
+ end
12
+
13
+ private
14
+
15
+ def show_prompt
16
+ prompt.select("Accept connections automatically?", cycle: true) do |config|
17
+ config.default default_value
18
+
19
+ config.choice "yes", true
20
+ config.choice "no", false
21
+ end
22
+ end
23
+
24
+ def default_value
25
+ Shell.configuration.auto_connect ? "yes" : "no"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -7,11 +7,13 @@ class Pry
7
7
  HEADER = "PRY-SHELL Main Menu"
8
8
  ITEMS = [
9
9
  { name: "1) Available sessions", value: "list" },
10
- { name: "2) About pry-shell", value: "about" },
11
- { name: "3) Quit", value: "quit" }
10
+ { name: "2) Configuration", value: "configuration" },
11
+ { name: "3) About pry-shell", value: "about" },
12
+ { name: "4) Quit", value: "quit" }
12
13
  ].freeze
13
14
  MENU_ACTIONS = {
14
15
  "list" => -> { List.draw! },
16
+ "configuration" => -> { Configuration.draw! },
15
17
  "about" => -> { About.draw! },
16
18
  "quit" => -> { clear! && exit(0) }
17
19
  }.freeze
@@ -23,6 +25,9 @@ class Pry
23
25
  switch_to(selection)
24
26
  end
25
27
 
28
+ # Override this to remove "press any key" prompt
29
+ def draw_footer; end
30
+
26
31
  def switch_to(selected_ui)
27
32
  MENU_ACTIONS[selected_ui].call
28
33
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Pry
4
4
  class Shell
5
- VERSION = "0.1.0"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
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.1.0
4
+ version: 0.4.1
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-10 00:00:00.000000000 Z
11
+ date: 2021-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -75,18 +75,26 @@ files:
75
75
  - lib/pry/shell/cli.rb
76
76
  - lib/pry/shell/client.rb
77
77
  - lib/pry/shell/command.rb
78
+ - lib/pry/shell/configuration.rb
78
79
  - lib/pry/shell/io/base.rb
80
+ - lib/pry/shell/io/editor.rb
79
81
  - lib/pry/shell/io/input.rb
80
82
  - lib/pry/shell/io/output.rb
83
+ - lib/pry/shell/io/pager.rb
81
84
  - lib/pry/shell/logger.rb
82
85
  - lib/pry/shell/patches/object.rb
83
- - lib/pry/shell/patches/repl.rb
86
+ - lib/pry/shell/patches/pager.rb
87
+ - lib/pry/shell/patches/pry_byebug.rb
88
+ - lib/pry/shell/patches/rack_timeout.rb
84
89
  - lib/pry/shell/registry.rb
90
+ - lib/pry/shell/repl.rb
85
91
  - lib/pry/shell/server.rb
86
92
  - lib/pry/shell/session.rb
87
93
  - lib/pry/shell/ui.rb
88
94
  - lib/pry/shell/ui/about.rb
89
95
  - lib/pry/shell/ui/base.rb
96
+ - lib/pry/shell/ui/configuration.rb
97
+ - lib/pry/shell/ui/configuration/auto_connect.rb
90
98
  - lib/pry/shell/ui/list.rb
91
99
  - lib/pry/shell/ui/menu.rb
92
100
  - lib/pry/shell/ui/session.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)