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

Commit

Permalink
Merge pull request #74 from nguyenquangminh0711/bug/access-local-thre…
Browse files Browse the repository at this point in the history
…ad-variables

Simplify threading model in REPL proxy
  • Loading branch information
0x2c7 committed Oct 13, 2020
2 parents 798dc83 + 52e9828 commit c5c9064
Show file tree
Hide file tree
Showing 21 changed files with 778 additions and 178 deletions.
45 changes: 4 additions & 41 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ jobs:
run: cd tmux && sh autogen.sh && ./configure && make && sudo make install
- name: Tmux version
run: tmux -V
- name: Install dependencies
run: bundle install
- name: Kill tmux
run: tmux kill-server || true
- name: Start tmux
run: tmux start-server
- name: Start dummy tmux session
run: tmux new-session -t dummy -d
- name: Wait for tmux
run: ruby spec/wait_for_tmux.rb
- name: Install dependencies
run: bundle install
- name: Kill tmux
run: tmux kill-server || true
- name: Run tests
run: bundle exec parallel_rspec spec/
test-macos:
Expand Down Expand Up @@ -95,40 +95,3 @@ jobs:
run: bundle install
- name: Run tests
run: bundle exec parallel_rspec -n 2 spec/
test-byebug:
strategy:
fail-fast: false
matrix:
byebug: [9.1.0, 10.0.2]
env:
BUNDLE_GEMFILE: "./spec/gemfiles/Gemfile-byebug-${{ matrix.byebug }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
- uses: actions/checkout@v2
with:
repository: tmux/tmux
path: 'tmux'
ref: '3.1b'
- name: Install dependencies for tmux
run: sudo apt install -y libevent-dev
- name: Install tmux
run: cd tmux && sh autogen.sh && ./configure && make && sudo make install
- name: Tmux version
run: tmux -V
- name: Start tmux
run: tmux start-server
- name: Start dummy tmux session
run: tmux new-session -t dummy -d
- name: Wait for tmux
run: ruby spec/wait_for_tmux.rb
- name: Install dependencies
run: bundle install
- name: Kill tmux
run: tmux kill-server || true
- name: Run tests
run: bundle exec parallel_rspec spec/
5 changes: 4 additions & 1 deletion lib/ruby_jard/commands/filter_command.doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
│ jard filter [include, exclude] pattern │ │ │
├──────────────────────────────────────────────────────────┼─────────────────────┼───────┤
│ jard filter clear │ │ │
├──────────────────────────────────────────────────────────┼─────────────────────┼───────┤
│ jard filter switch │ │ │
└──────────────────────────────────────────────────────────┴─────────────────────┴───────┘

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.
Expand All @@ -31,4 +33,5 @@ Ruby Jard has a strong filtering system. This system consists of a filter mode,
jard filter exclude aws-* active* action* # Multiple patterns separated by <space>
jard filter exclude lib/**/*.erb
jard filter exclude ~/home/lib/**/*.rb
jard filter clear # Clear filter
jard filter clear # Clear filter
jard filter switch # Switch to the next filter in the list
7 changes: 7 additions & 0 deletions lib/ruby_jard/commands/filter_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def process
handle_excluded
when :clear
handle_clear
when :switch
handle_switch
else
raise Pry::CommandError,
"Invalid filter '#{highlight(sub_command)}'."\
Expand Down Expand Up @@ -106,6 +108,11 @@ def handle_clear
@config.filter_included = []
RubyJard::ControlFlow.dispatch(:list)
end

def handle_switch
@config.filter = RubyJard::PathFilter.next_filter(@config.filter)
RubyJard::ControlFlow.dispatch(:list)
end
end
end
end
49 changes: 24 additions & 25 deletions lib/ruby_jard/control_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,11 @@ class ControlFlow
step: [:times], # lib/ruby_jard/commands/step_command.rb
skip: [:times], # lib/ruby_jard/commands/skip_command.rb
step_out: [:times], # lib/ruby_jard/commands/step_out_command.rb
key_binding: [:action], # lib/ruby_jard/commands/step_command.rb
list: [] # lib/ruby_jard/commands/list_command.rb
}.freeze

attr_reader :command, :arguments

def initialize(command, arguments = {})
@command = command
@arguments = arguments

validate!
end

def validate!
if command.to_s.empty?
raise RubyJard::Error, 'Control command is empty'
end

unless ALLOW_LIST.key?(command)
raise RubyJard::Error,
"Control command `#{command}` is not registered in the allow list."
end

invalid_keys = arguments.keys - ALLOW_LIST[command]
unless invalid_keys.empty?
raise RubyJard::Error,
"Control command `#{command}` is attached with unregister arguments: #{invalid_keys}"
end
end

class << self
def dispatch(command, arguments = {})
if command.is_a?(RubyJard::ControlFlow)
Expand All @@ -70,5 +45,29 @@ def listen
end
end
end

def initialize(command, arguments = {})
@command = command
@arguments = arguments

validate!
end

def validate!
if command.to_s.empty?
raise RubyJard::Error, 'Control command is empty'
end

unless ALLOW_LIST.key?(command)
raise RubyJard::Error,
"Control command `#{command}` is not registered in the allow list."
end

invalid_keys = arguments.keys - ALLOW_LIST[command]
unless invalid_keys.empty?
raise RubyJard::Error,
"Control command `#{command}` is attached with unregister arguments: #{invalid_keys}"
end
end
end
end
16 changes: 8 additions & 8 deletions lib/ruby_jard/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class Keys
SHIFT_F11 = "\e[23;2~"
SHIFT_F12 = "\e[24;2~"
DEFAULT_KEY_BINDINGS = {
F2 => (ACTION_FILTER = :switch_filter),
F5 => (ACTION_LIST = :list),
F6 => (ACTION_UP = :up),
SHIFT_F6 => (ACTION_DOWN = :down),
F7 => (ACTION_STEP = :step),
SHIFT_F7 => (ACTION_STEP_OUT = :step_out),
F8 => (ACTION_NEXT = :next),
F9 => (ACTION_CONTINUE = :continue),
F2 => (ACTION_FILTER = 'jard filter switch'),
F5 => (ACTION_LIST = 'list'),
F6 => (ACTION_UP = 'up'),
SHIFT_F6 => (ACTION_DOWN = 'down'),
F7 => (ACTION_STEP = 'step'),
SHIFT_F7 => (ACTION_STEP_OUT = 'step-out'),
F8 => (ACTION_NEXT = 'next'),
F9 => (ACTION_CONTINUE = 'continue'),
CTRL_D => ACTION_CONTINUE
}.freeze
end
Expand Down
10 changes: 0 additions & 10 deletions lib/ruby_jard/repl_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,6 @@ def handle_exit_command(_options = {})
Kernel.exit
end

def handle_key_binding_command(options = {})
method_name = "handle_#{options[:action]}_command"
if respond_to?(method_name, true)
send(method_name)
else
raise RubyJard::Error,
"Fail to handle key binding `#{options[:action]}`"
end
end

def handle_list_command(_options = {})
process_commands
end
Expand Down
Loading

0 comments on commit c5c9064

Please sign in to comment.