pryx 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d32d158a55d6f60171d02a8cd461db6cfe297367dcb45d83e9373f6a700af13
4
- data.tar.gz: 07f75f1b4519f23d1b78bd786f18a2fe429bb152026249c769b84c548ff99ac4
3
+ metadata.gz: a9d67d15a83b0d92beee0841d429cb42bc2c91ce2c0aea21b4a8ebb68cc88125
4
+ data.tar.gz: 828770b2b1bb5e958058d74136e9c759b461eac7ad8ff12c907ab92fa6b943f2
5
5
  SHA512:
6
- metadata.gz: b963742fd62610857bd1dbdb423f437adacd1457d2bbd453d44b106ac4ef893cb083029bdf89b98664e0787f519973be63c64ab19737dcbca46838bb1ebcc779
7
- data.tar.gz: fa57e77ccf9805f0f6937a89e798f106e729335eb4e450b37f0b5b9c6a369046645a30d123d6e2cbeab3feb2e6be94a3c34492495ee06414c37fb6e2a0a6d9c0
6
+ metadata.gz: 1d6f3688c0709bc039167c55aea81b6cee322381631b40f1507abdb4d18067c8e92a196d5deeb2899df61588a8bfd4397f8954301507c0e0357ab849995831fb
7
+ data.tar.gz: 8540e5b11640d70305e6f21f94459b7756bf13260ea441a87f62c89d3c4c90b308c021d0c5c59ea5d119300b31bbf1cba668620b394a316b8ae872c3a24728fb
@@ -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,38 +29,20 @@ class Binding
29
29
  self.pry
30
30
  end
31
31
  end
32
-
33
- def _irb(_host=nil)
34
- warn 'loading irb ...'
35
-
36
- IRB.conf[:USE_COLORIZE] = false
37
-
38
- self.irb
39
- end
40
32
  end
41
33
 
42
34
  module Kernel
43
35
  # 运行 pry! 会被拦截, 且只会被拦截一次.
44
- def pry!(caller=2, remote: nil, port: 9876)
36
+ def pry!(remote: nil, port: 9876)
45
37
  return unless ENV['Pry_was_started'].nil?
46
38
 
47
39
  ENV['Pry_was_started'] = 'true'
48
40
 
49
- if background?
50
- remote = '0.0.0.0'
51
- port = 9876
52
- end
53
-
54
- pry3(caller, remote: remote, port: port)
41
+ pry3(2, remote: remote, port: port)
55
42
 
56
43
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
57
44
  end
58
45
 
59
- # 注意:pryr 总是会被拦截。
60
- def pryr
61
- pry3(caller=2, remote: '0.0.0.0', port: 9876)
62
- end
63
-
64
46
  # 在 pry! 之前如果输入这个,会让下次执行的 pry! 被拦截一次, 而不管之前是否有执行过 pry!
65
47
  def repry!
66
48
  ENV['Pry_was_started'] = nil
@@ -68,13 +50,13 @@ module Kernel
68
50
 
69
51
  # 和 pry! 的差别就是,pry? 使用 pry-state 插件输出当前 context 的很多变量内容。
70
52
  # 注意:不需要总是开启 pry-state,因为有时候会输出太多内容,造成刷屏。
71
- def pry?(caller=2, remote: nil, port: 9876)
53
+ def pry?(remote: nil, port: 9876)
72
54
  return unless ENV['Pry_was_started'].nil?
73
55
 
74
56
  require 'pry-state'
75
57
  ENV['Pry_was_started'] = 'true'
76
58
 
77
- pry3(caller, remote: remote, port: port)
59
+ pry3(2, remote: remote, port: port)
78
60
 
79
61
  # 这里如果有代码, 将会让 pry! 进入这个方法, 因此保持为空.
80
62
  end
@@ -82,6 +64,8 @@ module Kernel
82
64
  # 等价于默认的 binding.pry, 会反复被拦截。
83
65
  # 起成 pry3 这个名字,也是为了方便直接使用。
84
66
  def pry3(caller=1, remote: nil, port: 9876)
67
+ remote = '0.0.0.0' if Pryx::Background.background?
68
+
85
69
  binding.of_caller(caller)._pry(remote, port)
86
70
  end
87
71
 
@@ -94,51 +78,11 @@ module Kernel
94
78
 
95
79
  def pry2(caller=1, remote: nil, port: 9876)
96
80
  if ENV['Pry2_should_start'] == 'true'
97
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
98
81
  ENV['Pry2_should_start'] = nil
99
82
  binding.of_caller(caller)._pry(remote, port)
100
83
  end
101
84
  end
102
85
 
103
- def reirb!
104
- ENV['IRB_was_started'] = nil
105
- end
106
-
107
- def irb!
108
- return unless ENV['IRB_was_started'].nil?
109
-
110
- ENV['IRB_was_started'] = 'true'
111
-
112
- binding.of_caller(1)._irb
113
- end
114
-
115
- def irb1
116
- ENV['IRB2_should_start'] = 'true'
117
- end
118
-
119
- def irb2(caller=1, remote: nil, port: 9876)
120
- if ENV['IRB2_should_start'] == 'true'
121
- # 首先恢复 Pry2_is_start 为未启动, 避免稍后的 pry2 再次被拦截.
122
- ENV['IRB2_should_start'] = nil
123
- binding.of_caller(caller)._irb
124
- end
125
- end
126
-
127
- # 如果是前台进程,则这个进程的组ID(pgid)一定会等于当前 terminal 的gid (tpgid)
128
- # 否则,如果不等,那么就是后台进程。
129
- # system("ps -e -o pid,pgid,tpgid |grep '^\s*#{pid}' |awk '$2==$3 {exit 1}'")
130
- # system("\\cat /proc/#{pid}/stat |awk '$5==$8 {exit 1}'")
131
- def background?(pid=$$)
132
- # 考虑是否需要验证
133
- ary = File.read("/proc/#{pid}/stat").split(' ').reverse
134
- # 执行 reverse 再处理,是因为要考虑文件名包含空格因素。例如:‘hello) (world’
135
- (ary[46] != ary[48]) && !$stdout.tty?
136
- end
137
-
138
- def foreground?(pid=$$)
139
- not background?(pid)
140
- end
141
-
142
86
  def notify_send(msg)
143
87
  system("notify-send \"#{msg}\"") if system 'which notify-send &>/dev/null'
144
88
 
@@ -147,7 +91,7 @@ module Kernel
147
91
  end
148
92
  end
149
93
 
150
- # Hack roda, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
94
+ # Hack for roda/rails, 在每一次发送请求之前,总是设定 ENV['Pry_was_started'] to nil.
151
95
  # 这可以确保,pry! 总是会被拦截,但是仅仅只会被拦截一次。
152
96
  begin
153
97
  require 'roda'
data/lib/pryx/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pryx
4
- VERSION = [0, 2, 2]
4
+ VERSION = [0, 3, 0]
5
5
 
6
6
  class << VERSION
7
7
  include Comparable
data/lib/pryx.rb CHANGED
@@ -1,13 +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
 
8
10
  # Add the non-bundler managermented gems back
9
11
  # this step is necessory when install pryx in docker-compose
10
12
  ENV['RUBYLIB'] = $LOAD_PATH.grep(/gems/).join(':')
11
13
 
14
+ # set export RUBYOPT+=" -rpryx" to work with pryx.
12
15
  module Pryx
13
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.2
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-21 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