pryx 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cb8e0fb8fe257e6d65d07e9e00184716a1b9f445f5750a62fd8ce1e2707b4cf
4
- data.tar.gz: d4821c497b6515d20124e60c443010aeff35864a8ae418be052d5ee57ee862c0
3
+ metadata.gz: a9d67d15a83b0d92beee0841d429cb42bc2c91ce2c0aea21b4a8ebb68cc88125
4
+ data.tar.gz: 828770b2b1bb5e958058d74136e9c759b461eac7ad8ff12c907ab92fa6b943f2
5
5
  SHA512:
6
- metadata.gz: 900109fc6a7cd7668945b6c2bf1a04818796834e7d9421d220ddef4cfe83e3b1f5796998acfeeeba9c75bb3c8b04b5308d647f0339fe286947e46204504352a4
7
- data.tar.gz: 8a3631de30224033da1ff976b67d317decd6ecb3302038098add08be935f21bd993425ec950109f899a2d9c94b72372b572d3c1183b483ea027f27310e1b0964
6
+ metadata.gz: 1d6f3688c0709bc039167c55aea81b6cee322381631b40f1507abdb4d18067c8e92a196d5deeb2899df61588a8bfd4397f8954301507c0e0357ab849995831fb
7
+ data.tar.gz: 8540e5b11640d70305e6f21f94459b7756bf13260ea441a87f62c89d3c4c90b308c021d0c5c59ea5d119300b31bbf1cba668620b394a316b8ae872c3a24728fb
data/lib/pry-disasm.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'pry'
4
4
  require 'pry-disasm/commands'
5
- require 'pry-disasm/version'
6
5
 
7
6
  class PryDisasm
8
7
  def self.process(expr)
@@ -0,0 +1,20 @@
1
+ module Pryx::Background
2
+ # 如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)
3
+ # 否则,如果不等,那么就是后台进程。
4
+ # system("\\cat /proc/#{pid}/stat |awk '$5==$8 {exit 1}'")
5
+ def self.background?(pid=$$)
6
+ # 这个实现似乎有错, 因为针对 nohup 1.rb& 这种情况,返回为前台进程。
7
+ # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’
8
+ # ary = File.read("/proc/#{pid}/stat").split(' ').reverse
9
+ # is_bg = (ary[46] != ary[48])
10
+
11
+ # 这个实现依赖于一些 linux 下基本工具,但是准确
12
+ is_bg = system("ps -e -o pid,pgid,tpgid |grep '^\s*#{pid}' |awk '$2==$3 {exit 1}'")
13
+
14
+ is_bg && !$stdout.tty?
15
+ end
16
+
17
+ def self.foreground?(pid=$$)
18
+ not background?(pid)
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'binding_of_caller'
2
+
3
+ class Binding
4
+ def _irb(_host=nil)
5
+ warn 'loading irb ...'
6
+
7
+ if defined? Break and defined? IRB
8
+ # This is need for work with looksee better.
9
+ # See discuss on https://github.com/oggy/looksee/issues/57
10
+ IRB.conf[:USE_COLORIZE] = false
11
+ else
12
+ warn "For work with Break and Looksee, please set
13
+ export RUBYOPT='-rpryx_irb'
14
+ instead of
15
+ export RUBYOPT='-rpryx'
16
+ "
17
+ end
18
+
19
+ self.irb
20
+ end
21
+ end
22
+
23
+ module Kernel
24
+ def irb!
25
+ return unless ENV['IRB_was_started'].nil?
26
+
27
+ ENV['IRB_was_started'] = 'true'
28
+
29
+ binding.of_caller(1)._irb
30
+ end
31
+
32
+ def reirb!
33
+ ENV['IRB_was_started'] = nil
34
+ end
35
+
36
+ def irb1
37
+ ENV['IRB2_should_start'] = 'true'
38
+ end
39
+
40
+ def irb2(caller=1, remote: nil, port: 9876)
41
+ if ENV['IRB2_should_start'] == 'true'
42
+ ENV['IRB2_should_start'] = nil
43
+ binding.of_caller(caller)._irb
44
+ end
45
+ end
46
+ end
data/lib/pryx/pry_hack.rb CHANGED
@@ -29,36 +29,20 @@ class Binding
29
29
  self.pry
30
30
  end
31
31
  end
32
-
33
- def _irb(_host=nil, _port=nil, _options={})
34
- warn 'loading irb ...'
35
-
36
- self.irb
37
- end
38
32
  end
39
33
 
40
34
  module Kernel
41
35
  # 运行 pry! 会被拦截, 且只会被拦截一次.
42
- def pry!(caller=2, remote: nil, port: 9876)
36
+ def pry!(remote: nil, port: 9876)
43
37
  return unless ENV['Pry_was_started'].nil?
44
38
 
45
39
  ENV['Pry_was_started'] = 'true'
46
40
 
47
- if background?
48
- remote = '0.0.0.0'
49
- port = 9876
50
- end
51
-
52
- pry3(caller, remote:, port:)
41
+ pry3(2, remote: remote, port: port)
53
42
 
54
43
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
55
44
  end
56
45
 
57
- # 注意:pryr 总是会被拦截。
58
- def pryr
59
- pry3(caller = 2, remote: '0.0.0.0', port: 9876)
60
- end
61
-
62
46
  # 在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!
63
47
  def repry!
64
48
  ENV['Pry_was_started'] = nil
@@ -66,13 +50,13 @@ module Kernel
66
50
 
67
51
  # 和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。
68
52
  # 注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。
69
- def pry?(caller=2, remote: nil, port: 9876)
53
+ def pry?(remote: nil, port: 9876)
70
54
  return unless ENV['Pry_was_started'].nil?
71
55
 
72
56
  require 'pry-state'
73
57
  ENV['Pry_was_started'] = 'true'
74
58
 
75
- pry3(caller, remote:, port:)
59
+ pry3(2, remote: remote, port: port)
76
60
 
77
61
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
78
62
  end
@@ -80,6 +64,8 @@ module Kernel
80
64
  # 等价于默认的 binding.pry, 会反复被拦截。
81
65
  # 起成 pry3 这个名字,也是为了方便直接使用。
82
66
  def pry3(caller=1, remote: nil, port: 9876)
67
+ remote = '0.0.0.0' if Pryx::Background.background?
68
+
83
69
  binding.of_caller(caller)._pry(remote, port)
84
70
  end
85
71
 
@@ -92,51 +78,11 @@ module Kernel
92
78
 
93
79
  def pry2(caller=1, remote: nil, port: 9876)
94
80
  if ENV['Pry2_should_start'] == 'true'
95
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
96
81
  ENV['Pry2_should_start'] = nil
97
82
  binding.of_caller(caller)._pry(remote, port)
98
83
  end
99
84
  end
100
85
 
101
- def reirb!
102
- ENV['IRB_was_started'] = nil
103
- end
104
-
105
- def irb!
106
- return unless ENV['IRB_was_started'].nil?
107
-
108
- ENV['IRB_was_started'] = 'true'
109
-
110
- binding.of_caller(1)._irb
111
- end
112
-
113
- def irb1
114
- ENV['IRB2_should_start'] = 'true'
115
- end
116
-
117
- def irb2(caller=1, remote: nil, port: 9876)
118
- if ENV['IRB2_should_start'] == 'true'
119
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
120
- ENV['IRB2_should_start'] = nil
121
- binding.of_caller(caller)._irb
122
- end
123
- end
124
-
125
- # 如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)
126
- # 否则,如果不等,那么就是后台进程。
127
- # system("ps -e -o pid,pgid,tpgid |grep '^\s*#{pid}' |awk '$2==$3 {exit 1}'")
128
- # system("\\cat /proc/#{pid}/stat |awk '$5==$8 {exit 1}'")
129
- def background?(pid=$$)
130
- # 考虑是否需要验证
131
- ary = File.read("/proc/#{pid}/stat").split(' ').reverse
132
- # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’
133
- (ary[46] != ary[48]) && !$stdout.tty?
134
- end
135
-
136
- def foreground?(pid=$$)
137
- not background?(pid)
138
- end
139
-
140
86
  def notify_send(msg)
141
87
  system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'
142
88
 
@@ -145,7 +91,7 @@ module Kernel
145
91
  end
146
92
  end
147
93
 
148
- # Hack roda, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
94
+ # Hack for roda/rails, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
149
95
  # 这可以确保,pry! 总是会被拦截,但是仅仅只会被拦截一次。
150
96
  begin
151
97
  require 'roda'
data/lib/pryx/version.rb CHANGED
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pryx
4
- VERSION = '0.2.0'
4
+ VERSION = [0, 3, 0]
5
+
6
+ class << VERSION
7
+ include Comparable
8
+
9
+ def to_s
10
+ join('.')
11
+ end
12
+ end
5
13
  end
data/lib/pryx.rb CHANGED
@@ -1,9 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pryx/version'
4
+ require 'pryx/background'
4
5
  require 'pryx/trap_backtrace'
5
6
  require 'pryx/looksee_hack'
6
7
  require 'pryx/pry_hack'
8
+ require 'pryx/irb_hack'
7
9
 
10
+ # Add the non-bundler managermented gems back
11
+ # this step is necessory when install pryx in docker-compose
12
+ ENV['RUBYLIB'] = $LOAD_PATH.grep(/gems/).join(':')
13
+
14
+ # set export RUBYOPT+=" -rpryx" to work with pryx.
8
15
  module Pryx
9
16
  end
data/lib/pryx_irb.rb CHANGED
@@ -1,3 +1,14 @@
1
+ # We need apply those hack before irb was loaded for work with irb.
2
+ # So we have to add it here, same hacks for Pry is add to method
3
+ # Binding#_pry which defined in lib/pryx/pry_hack.rb
4
+
5
+ # we need set `export RUBYOPT+=" -rpryx_irb"` instead of `-rpryx` to make
6
+ # irb work with break and ap gem.
7
+
8
+ # ap_hack 可以确保,当时用 irb! 的时候,输入代码是彩色的,并且 looksee 也正常显示
9
+ # 但是,ap_hack 不可以放到 break_hack 后面,否则会失效。
10
+ # WARN: 下面两行代码顺序不要换。
1
11
  require 'pryx/ap_hack'
2
12
  require 'pryx/break_hack'
13
+
3
14
  require 'pryx'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pryx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Billy.Zheng(zw963)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-20 00:00:00.000000000 Z
11
+ date: 2022-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -159,8 +159,10 @@ files:
159
159
  - lib/pry-remote.rb
160
160
  - lib/pryx.rb
161
161
  - lib/pryx/ap_hack.rb
162
+ - lib/pryx/background.rb
162
163
  - lib/pryx/break_hack.rb
163
164
  - lib/pryx/drip.wav
165
+ - lib/pryx/irb_hack.rb
164
166
  - lib/pryx/looksee_hack.rb
165
167
  - lib/pryx/pry_hack.rb
166
168
  - lib/pryx/trap_backtrace.rb