Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit c5c9064

Browse files
authored
Merge pull request #74 from nguyenquangminh0711/bug/access-local-thread-variables
Simplify threading model in REPL proxy
2 parents 798dc83 + 52e9828 commit c5c9064

21 files changed

+778
-178
lines changed

.github/workflows/rspec.yml

+4-41
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ jobs:
5757
run: cd tmux && sh autogen.sh && ./configure && make && sudo make install
5858
- name: Tmux version
5959
run: tmux -V
60+
- name: Install dependencies
61+
run: bundle install
62+
- name: Kill tmux
63+
run: tmux kill-server || true
6064
- name: Start tmux
6165
run: tmux start-server
6266
- name: Start dummy tmux session
6367
run: tmux new-session -t dummy -d
6468
- name: Wait for tmux
6569
run: ruby spec/wait_for_tmux.rb
66-
- name: Install dependencies
67-
run: bundle install
68-
- name: Kill tmux
69-
run: tmux kill-server || true
7070
- name: Run tests
7171
run: bundle exec parallel_rspec spec/
7272
test-macos:
@@ -95,40 +95,3 @@ jobs:
9595
run: bundle install
9696
- name: Run tests
9797
run: bundle exec parallel_rspec -n 2 spec/
98-
test-byebug:
99-
strategy:
100-
fail-fast: false
101-
matrix:
102-
byebug: [9.1.0, 10.0.2]
103-
env:
104-
BUNDLE_GEMFILE: "./spec/gemfiles/Gemfile-byebug-${{ matrix.byebug }}"
105-
runs-on: ubuntu-latest
106-
steps:
107-
- uses: actions/checkout@v2
108-
- name: Set up Ruby
109-
uses: ruby/setup-ruby@v1
110-
with:
111-
ruby-version: 2.5
112-
- uses: actions/checkout@v2
113-
with:
114-
repository: tmux/tmux
115-
path: 'tmux'
116-
ref: '3.1b'
117-
- name: Install dependencies for tmux
118-
run: sudo apt install -y libevent-dev
119-
- name: Install tmux
120-
run: cd tmux && sh autogen.sh && ./configure && make && sudo make install
121-
- name: Tmux version
122-
run: tmux -V
123-
- name: Start tmux
124-
run: tmux start-server
125-
- name: Start dummy tmux session
126-
run: tmux new-session -t dummy -d
127-
- name: Wait for tmux
128-
run: ruby spec/wait_for_tmux.rb
129-
- name: Install dependencies
130-
run: bundle install
131-
- name: Kill tmux
132-
run: tmux kill-server || true
133-
- name: Run tests
134-
run: bundle exec parallel_rspec spec/

lib/ruby_jard/commands/filter_command.doc.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
│ jard filter [include, exclude] pattern │ │ │
1010
├──────────────────────────────────────────────────────────┼─────────────────────┼───────┤
1111
│ jard filter clear │ │ │
12+
├──────────────────────────────────────────────────────────┼─────────────────────┼───────┤
13+
│ jard filter switch │ │ │
1214
└──────────────────────────────────────────────────────────┴─────────────────────┴───────┘
1315

1416
Ruby Jard has a strong filtering system. This system consists of a filter mode, included list, and excluded list. Filter mode is how Ruby Jard reacts to control flow commands. See filter » https://rubyjard.org/docs/guides/filter for more information.
@@ -31,4 +33,5 @@ Ruby Jard has a strong filtering system. This system consists of a filter mode,
3133
jard filter exclude aws-* active* action* # Multiple patterns separated by <space>
3234
jard filter exclude lib/**/*.erb
3335
jard filter exclude ~/home/lib/**/*.rb
34-
jard filter clear # Clear filter
36+
jard filter clear # Clear filter
37+
jard filter switch # Switch to the next filter in the list

lib/ruby_jard/commands/filter_command.rb

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def process
3636
handle_excluded
3737
when :clear
3838
handle_clear
39+
when :switch
40+
handle_switch
3941
else
4042
raise Pry::CommandError,
4143
"Invalid filter '#{highlight(sub_command)}'."\
@@ -106,6 +108,11 @@ def handle_clear
106108
@config.filter_included = []
107109
RubyJard::ControlFlow.dispatch(:list)
108110
end
111+
112+
def handle_switch
113+
@config.filter = RubyJard::PathFilter.next_filter(@config.filter)
114+
RubyJard::ControlFlow.dispatch(:list)
115+
end
109116
end
110117
end
111118
end

lib/ruby_jard/control_flow.rb

+24-25
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,11 @@ class ControlFlow
1616
step: [:times], # lib/ruby_jard/commands/step_command.rb
1717
skip: [:times], # lib/ruby_jard/commands/skip_command.rb
1818
step_out: [:times], # lib/ruby_jard/commands/step_out_command.rb
19-
key_binding: [:action], # lib/ruby_jard/commands/step_command.rb
2019
list: [] # lib/ruby_jard/commands/list_command.rb
2120
}.freeze
2221

2322
attr_reader :command, :arguments
2423

25-
def initialize(command, arguments = {})
26-
@command = command
27-
@arguments = arguments
28-
29-
validate!
30-
end
31-
32-
def validate!
33-
if command.to_s.empty?
34-
raise RubyJard::Error, 'Control command is empty'
35-
end
36-
37-
unless ALLOW_LIST.key?(command)
38-
raise RubyJard::Error,
39-
"Control command `#{command}` is not registered in the allow list."
40-
end
41-
42-
invalid_keys = arguments.keys - ALLOW_LIST[command]
43-
unless invalid_keys.empty?
44-
raise RubyJard::Error,
45-
"Control command `#{command}` is attached with unregister arguments: #{invalid_keys}"
46-
end
47-
end
48-
4924
class << self
5025
def dispatch(command, arguments = {})
5126
if command.is_a?(RubyJard::ControlFlow)
@@ -70,5 +45,29 @@ def listen
7045
end
7146
end
7247
end
48+
49+
def initialize(command, arguments = {})
50+
@command = command
51+
@arguments = arguments
52+
53+
validate!
54+
end
55+
56+
def validate!
57+
if command.to_s.empty?
58+
raise RubyJard::Error, 'Control command is empty'
59+
end
60+
61+
unless ALLOW_LIST.key?(command)
62+
raise RubyJard::Error,
63+
"Control command `#{command}` is not registered in the allow list."
64+
end
65+
66+
invalid_keys = arguments.keys - ALLOW_LIST[command]
67+
unless invalid_keys.empty?
68+
raise RubyJard::Error,
69+
"Control command `#{command}` is attached with unregister arguments: #{invalid_keys}"
70+
end
71+
end
7372
end
7473
end

lib/ruby_jard/keys.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class Keys
3535
SHIFT_F11 = "\e[23;2~"
3636
SHIFT_F12 = "\e[24;2~"
3737
DEFAULT_KEY_BINDINGS = {
38-
F2 => (ACTION_FILTER = :switch_filter),
39-
F5 => (ACTION_LIST = :list),
40-
F6 => (ACTION_UP = :up),
41-
SHIFT_F6 => (ACTION_DOWN = :down),
42-
F7 => (ACTION_STEP = :step),
43-
SHIFT_F7 => (ACTION_STEP_OUT = :step_out),
44-
F8 => (ACTION_NEXT = :next),
45-
F9 => (ACTION_CONTINUE = :continue),
38+
F2 => (ACTION_FILTER = 'jard filter switch'),
39+
F5 => (ACTION_LIST = 'list'),
40+
F6 => (ACTION_UP = 'up'),
41+
SHIFT_F6 => (ACTION_DOWN = 'down'),
42+
F7 => (ACTION_STEP = 'step'),
43+
SHIFT_F7 => (ACTION_STEP_OUT = 'step-out'),
44+
F8 => (ACTION_NEXT = 'next'),
45+
F9 => (ACTION_CONTINUE = 'continue'),
4646
CTRL_D => ACTION_CONTINUE
4747
}.freeze
4848
end

lib/ruby_jard/repl_processor.rb

-10
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,6 @@ def handle_exit_command(_options = {})
187187
Kernel.exit
188188
end
189189

190-
def handle_key_binding_command(options = {})
191-
method_name = "handle_#{options[:action]}_command"
192-
if respond_to?(method_name, true)
193-
send(method_name)
194-
else
195-
raise RubyJard::Error,
196-
"Fail to handle key binding `#{options[:action]}`"
197-
end
198-
end
199-
200190
def handle_list_command(_options = {})
201191
process_commands
202192
end

0 commit comments

Comments
 (0)