ruby_jard 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.github/workflows/ruby.yml +85 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +70 -1
  7. data/CHANGELOG.md +31 -0
  8. data/Gemfile +6 -3
  9. data/README.md +122 -8
  10. data/bin/console +1 -2
  11. data/docs/color_schemes/256-light.png +0 -0
  12. data/docs/color_schemes/gruvbox.png +0 -0
  13. data/docs/color_schemes/one-half-dark.png +0 -0
  14. data/docs/color_schemes/one-half-light.png +0 -0
  15. data/lib/ruby_jard.rb +5 -5
  16. data/lib/ruby_jard/box_drawer.rb +4 -1
  17. data/lib/ruby_jard/color_schemes.rb +31 -15
  18. data/lib/ruby_jard/color_schemes/256_color_scheme.rb +37 -37
  19. data/lib/ruby_jard/color_schemes/256_light_color_scheme.rb +62 -0
  20. data/lib/ruby_jard/color_schemes/deep_space_color_scheme.rb +36 -36
  21. data/lib/ruby_jard/color_schemes/gruvbox_color_scheme.rb +62 -0
  22. data/lib/ruby_jard/color_schemes/one_half_dark_color_scheme.rb +61 -0
  23. data/lib/ruby_jard/color_schemes/one_half_light_color_scheme.rb +62 -0
  24. data/lib/ruby_jard/column.rb +3 -1
  25. data/lib/ruby_jard/commands/continue_command.rb +2 -3
  26. data/lib/ruby_jard/commands/down_command.rb +9 -5
  27. data/lib/ruby_jard/commands/exit_command.rb +27 -0
  28. data/lib/ruby_jard/commands/frame_command.rb +11 -10
  29. data/lib/ruby_jard/commands/jard/color_scheme_command.rb +52 -0
  30. data/lib/ruby_jard/commands/jard/hide_command.rb +40 -0
  31. data/lib/ruby_jard/commands/jard/output_command.rb +28 -0
  32. data/lib/ruby_jard/commands/jard/show_command.rb +41 -0
  33. data/lib/ruby_jard/commands/jard_command.rb +50 -0
  34. data/lib/ruby_jard/commands/list_command.rb +5 -4
  35. data/lib/ruby_jard/commands/next_command.rb +10 -5
  36. data/lib/ruby_jard/commands/step_command.rb +10 -5
  37. data/lib/ruby_jard/commands/step_out_command.rb +10 -5
  38. data/lib/ruby_jard/commands/up_command.rb +10 -5
  39. data/lib/ruby_jard/commands/validation_helpers.rb +50 -0
  40. data/lib/ruby_jard/config.rb +7 -3
  41. data/lib/ruby_jard/console.rb +10 -22
  42. data/lib/ruby_jard/control_flow.rb +3 -3
  43. data/lib/ruby_jard/decorators/color_decorator.rb +11 -5
  44. data/lib/ruby_jard/decorators/loc_decorator.rb +1 -1
  45. data/lib/ruby_jard/decorators/path_decorator.rb +20 -7
  46. data/lib/ruby_jard/decorators/source_decorator.rb +2 -0
  47. data/lib/ruby_jard/frame.rb +55 -0
  48. data/lib/ruby_jard/keys.rb +0 -3
  49. data/lib/ruby_jard/layout.rb +9 -2
  50. data/lib/ruby_jard/layout_calculator.rb +29 -12
  51. data/lib/ruby_jard/layout_picker.rb +34 -0
  52. data/lib/ruby_jard/layouts.rb +52 -0
  53. data/lib/ruby_jard/layouts/narrow_horizontal_layout.rb +28 -0
  54. data/lib/ruby_jard/layouts/narrow_vertical_layout.rb +32 -0
  55. data/lib/ruby_jard/layouts/tiny_layout.rb +25 -0
  56. data/lib/ruby_jard/layouts/wide_layout.rb +13 -15
  57. data/lib/ruby_jard/pager.rb +96 -0
  58. data/lib/ruby_jard/repl_processor.rb +61 -31
  59. data/lib/ruby_jard/repl_proxy.rb +193 -89
  60. data/lib/ruby_jard/row.rb +16 -1
  61. data/lib/ruby_jard/row_renderer.rb +51 -42
  62. data/lib/ruby_jard/screen.rb +2 -12
  63. data/lib/ruby_jard/screen_adjuster.rb +104 -0
  64. data/lib/ruby_jard/screen_drawer.rb +3 -0
  65. data/lib/ruby_jard/screen_manager.rb +32 -54
  66. data/lib/ruby_jard/screen_renderer.rb +30 -16
  67. data/lib/ruby_jard/screens.rb +31 -12
  68. data/lib/ruby_jard/screens/backtrace_screen.rb +23 -26
  69. data/lib/ruby_jard/screens/menu_screen.rb +53 -22
  70. data/lib/ruby_jard/screens/source_screen.rb +65 -37
  71. data/lib/ruby_jard/screens/threads_screen.rb +14 -14
  72. data/lib/ruby_jard/screens/variables_screen.rb +59 -34
  73. data/lib/ruby_jard/session.rb +19 -10
  74. data/lib/ruby_jard/span.rb +3 -0
  75. data/lib/ruby_jard/templates/layout_template.rb +1 -1
  76. data/lib/ruby_jard/templates/screen_template.rb +3 -4
  77. data/lib/ruby_jard/version.rb +1 -1
  78. data/ruby_jard.gemspec +1 -1
  79. metadata +38 -9
  80. data/lib/ruby_jard/commands/color_scheme_command.rb +0 -42
  81. data/lib/ruby_jard/layouts/narrow_layout.rb +0 -41
  82. data/lib/ruby_jard/screens/empty_screen.rb +0 -13
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ class ColorSchemes
5
+ class OneHalfLightColorScheme < ColorScheme
6
+ # Shameless copy from https://github.com/sonph/onehalf/blob/master/vim/colors/onehalflight.vim
7
+ GRAY1 = '#eaeaea'
8
+ GRAY2 = '#d4d4d4'
9
+ GRAY3 = '#a0a1a7'
10
+ GRAY4 = '#a0a1a7'
11
+ GRAY5 = '#383a42'
12
+
13
+ WHITE = '#fafafa'
14
+ RED = '#e45649'
15
+ GREEN = '#50a14f'
16
+ YELLOW = '#c18401'
17
+ BLUE = '#0184bc'
18
+ PURPLE = '#a626a4'
19
+ CYAN = '#0997b3'
20
+
21
+ BACKGROUND = WHITE
22
+ STYLES = {
23
+ background: [GRAY5, BACKGROUND],
24
+ border: [GRAY3, BACKGROUND],
25
+ title: [WHITE, GREEN],
26
+ title_highlighted: [WHITE, YELLOW],
27
+ title_secondary: [GRAY5, GRAY2],
28
+ title_background: [GRAY3, BACKGROUND],
29
+ menu_mode: [YELLOW, BACKGROUND],
30
+ menu_tips: [GRAY4, BACKGROUND],
31
+ thread_id: [GREEN, BACKGROUND],
32
+ thread_name: [GRAY5, BACKGROUND],
33
+ thread_status_run: [GREEN, BACKGROUND],
34
+ thread_status_sleep: [GRAY4, BACKGROUND],
35
+ thread_status_other: [GRAY4, BACKGROUND],
36
+ thread_location: [GRAY5, BACKGROUND],
37
+ frame_id: [GRAY4, BACKGROUND],
38
+ frame_id_highlighted: [YELLOW, BACKGROUND],
39
+ frame_location: [GRAY5, BACKGROUND],
40
+ variable_mark: [GRAY4, BACKGROUND],
41
+ variable_mark_inline: [YELLOW, BACKGROUND],
42
+ variable_size: [GRAY5, BACKGROUND],
43
+ variable_inspection: [GRAY5, BACKGROUND],
44
+ variable_assignment: [GRAY5, BACKGROUND],
45
+ source_line_mark: [YELLOW, BACKGROUND],
46
+ source_lineno: [GRAY4, BACKGROUND],
47
+ keyword: [PURPLE, BACKGROUND],
48
+ method: [BLUE, BACKGROUND],
49
+ comment: [GRAY4, BACKGROUND],
50
+ literal: [YELLOW, BACKGROUND],
51
+ string: [GREEN, BACKGROUND],
52
+ local_variable: [RED, BACKGROUND],
53
+ instance_variable: [RED, BACKGROUND],
54
+ constant: [YELLOW, BACKGROUND],
55
+ normal_token: [GRAY5, BACKGROUND],
56
+ object: [YELLOW, BACKGROUND]
57
+ }.freeze
58
+ end
59
+ end
60
+ end
61
+
62
+ RubyJard::ColorSchemes.add_color_scheme('one-half-light', RubyJard::ColorSchemes::OneHalfLightColorScheme)
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyJard
4
+ ##
5
+ # This class is an object to contain information of a column in a data drow display on a screen
4
6
  class Column
5
7
  # Only break at breakable word
6
8
  # | this_is_a <endline> |
@@ -12,7 +14,7 @@ module RubyJard
12
14
  WORD_WRAP_BREAK_WORD = :break_word
13
15
  extend Forwardable
14
16
 
15
- attr_accessor :spans, :content_length, :width, :word_wrap
17
+ attr_accessor :spans, :content_length, :width, :content_width, :word_wrap
16
18
 
17
19
  def initialize(spans: [], word_wrap: WORD_WRAP_NORMAL)
18
20
  @spans = spans
@@ -11,11 +11,10 @@ module RubyJard
11
11
 
12
12
  banner <<-BANNER
13
13
  Usage: continue
14
-
15
- Continue program execution. The program will stop at the next breakpoint, or run until it finishes.
16
-
17
14
  Examples:
18
15
  continue
16
+
17
+ Continue program execution. The program will stop at the next breakpoint, or run until it finishes.
19
18
  BANNER
20
19
 
21
20
  def process
@@ -4,22 +4,26 @@ module RubyJard
4
4
  module Commands
5
5
  # Command used to explore stacktrace.
6
6
  class DownCommand < Pry::ClassCommand
7
+ include RubyJard::Commands::ValidationHelpers
8
+
7
9
  group 'RubyJard'
8
10
  description 'Explore the frames bellow the current stopped line in the backtrace'
9
11
 
10
12
  match 'down'
11
13
 
12
14
  banner <<-BANNER
13
- Usage: down
14
-
15
- Explore the frames bellow the current stopped line in the backtrace.
16
-
15
+ Usage: down [-h] [times]
17
16
  Examples:
18
17
  down
18
+ down 1
19
+ down 7
20
+
21
+ Explore the frames bellow the current stopped line in the backtrace. All the C frames will be skipped.
19
22
  BANNER
20
23
 
21
24
  def process
22
- RubyJard::ControlFlow.dispatch(:down)
25
+ times = validate_positive_integer!(args.first || 1)
26
+ RubyJard::ControlFlow.dispatch(:down, times: times.to_i)
23
27
  end
24
28
  end
25
29
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ module Commands
5
+ # Command used to exit program execution.
6
+ class ExitCommand < Pry::ClassCommand
7
+ group 'RubyJard'
8
+ description 'Exit program execution.'
9
+
10
+ match 'exit'
11
+
12
+ banner <<-BANNER
13
+ Usage: exit
14
+ Examples:
15
+ exit
16
+
17
+ Exit program execution. The program will stop at the next breakpoint, or run until it finishes.
18
+ BANNER
19
+
20
+ def process
21
+ RubyJard::ControlFlow.dispatch(:exit)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ Pry::Commands.add_command(RubyJard::Commands::ExitCommand)
@@ -4,6 +4,8 @@ module RubyJard
4
4
  module Commands
5
5
  # Command used to explore stacktrace.
6
6
  class FrameCommand < Pry::ClassCommand
7
+ include RubyJard::Commands::ValidationHelpers
8
+
7
9
  group 'RubyJard'
8
10
  description 'Explore to any frame of current stacktrace.'
9
11
 
@@ -18,17 +20,16 @@ module RubyJard
18
20
  frame 4 # Jump to frame 4 in the backtrace
19
21
  BANNER
20
22
 
23
+ def initialize(context = {})
24
+ super(context)
25
+ @session = context[:session] || RubyJard.current_session
26
+ end
27
+
21
28
  def process
22
- frame = args.first
23
- raise Pry::CommandError, 'Frame ID is required' if frame.nil?
24
- raise Pry::CommandError, 'Frame ID must be numeric' unless frame =~ /^\d+$/i
25
-
26
- frame = frame.to_i
27
- if frame >= RubyJard.current_session.backtrace.length || frame < 0
28
- raise Pry::CommandError, "Frame #{frame} does not exist!"
29
- else
30
- RubyJard::ControlFlow.dispatch(:frame, frame: args.first)
31
- end
29
+ frame = validate_present!(args.first)
30
+ frame = validate_non_negative_integer!(frame)
31
+ frame = validate_range!(frame, 0, @session.current_backtrace.length - 1)
32
+ RubyJard::ControlFlow.dispatch(:frame, frame: frame)
32
33
  end
33
34
  end
34
35
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ module Commands
5
+ # Command used to explore stacktrace.
6
+ class ColorSchemeCommand < Pry::ClassCommand
7
+ group 'RubyJard'
8
+ description 'Control the color scheme used in Jard'
9
+
10
+ match 'color-scheme'
11
+
12
+ banner <<-BANNER
13
+ Usage: color-scheme -l
14
+ color-scheme [scheme-name]
15
+ BANNER
16
+
17
+ def initialize(context = {})
18
+ super(context)
19
+ @color_schemes = context[:color_schemes] || RubyJard::ColorSchemes
20
+ @config = context[:config] || RubyJard.config
21
+ end
22
+
23
+ def options(opt)
24
+ opt.on :l, :list, 'List all available color schemes'
25
+ end
26
+
27
+ def process
28
+ if opts[:l]
29
+ if @color_schemes.names.empty?
30
+ pry_instance.output.puts 'No loaded color schemes'
31
+ else
32
+ pry_instance.output.puts @color_schemes.names.join("\n")
33
+ end
34
+ else
35
+ color_scheme = args.first.to_s.strip
36
+ if color_scheme.empty?
37
+ raise Pry::CommandError,
38
+ 'You must provide a color scheme name. Please use `color-scheme -l` to list all color schemes.'
39
+ end
40
+
41
+ if @color_schemes[color_scheme].nil?
42
+ raise Pry::CommandError,
43
+ "Color scheme `#{color_scheme}` not found. Please use `color-scheme -l` to list all color schemes."
44
+ end
45
+
46
+ @config.color_scheme = color_scheme
47
+ RubyJard::ControlFlow.dispatch(:list)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ module Commands
5
+ ##
6
+ # Show a screen
7
+ class HideCommand < Pry::ClassCommand
8
+ description 'Hide a screen'
9
+ banner <<-BANNER
10
+ Usage: jard hide [-h] [screen]
11
+ BANNER
12
+ match 'hide'
13
+
14
+ def initialize(context = {})
15
+ super(context)
16
+
17
+ @screens = context[:screens] || RubyJard::Screens
18
+ @config = context[:config] || RubyJard.config
19
+ end
20
+
21
+ def process
22
+ screen = args.first.to_s.strip
23
+
24
+ if screen.empty?
25
+ raise Pry::CommandError,
26
+ "Please input one of the following: #{@screens.names.join(', ')}"
27
+ end
28
+
29
+ unless @screens.names.include?(screen)
30
+ raise Pry::CommandError,
31
+ "Screen `#{screen}` not found. Please input one of the following: #{@screens.names.join(', ')}"
32
+ end
33
+
34
+ @config.enabled_screens.delete(screen)
35
+
36
+ RubyJard::ControlFlow.dispatch(:list)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ module Commands
5
+ # Command used to explore stacktrace.
6
+ class OutputCommand < Pry::ClassCommand
7
+ group 'RubyJard'
8
+ description 'Show all current program output'
9
+
10
+ match 'output'
11
+
12
+ banner <<-BANNER
13
+ Usage: output
14
+ BANNER
15
+
16
+ def self.output_storage
17
+ RubyJard::ScreenManager.instance.output_storage
18
+ end
19
+
20
+ def process
21
+ pry_instance.pager.open(force_open: true, pager_start_at_the_end: true) do |pager|
22
+ self.class.output_storage.rewind
23
+ pager.write self.class.output_storage.read_nonblock(2048) until self.class.output_storage.eof?
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyJard
4
+ module Commands
5
+ ##
6
+ # Show a screen
7
+ class ShowCommand < Pry::ClassCommand
8
+ description 'Show a screen'
9
+ banner <<-BANNER
10
+ Usage: jard show [-h] [screen]
11
+ BANNER
12
+ match 'show'
13
+
14
+ def initialize(context = {})
15
+ super(context)
16
+
17
+ @screens = context[:screens] || RubyJard::Screens
18
+ @config = context[:config] || RubyJard.config
19
+ end
20
+
21
+ def process
22
+ screen = args.first.to_s.strip
23
+
24
+ if screen.empty?
25
+ raise Pry::CommandError,
26
+ "Please input one of the following: #{@screens.names.join(', ')}"
27
+ end
28
+
29
+ unless @screens.names.include?(screen)
30
+ raise Pry::CommandError,
31
+ "Screen `#{screen}` not found. Please input one of the following: #{@screens.names.join(', ')}"
32
+ end
33
+
34
+ @config.enabled_screens << screen
35
+ @config.enabled_screens.uniq!
36
+
37
+ RubyJard::ControlFlow.dispatch(:list)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_jard/commands/jard/show_command'
4
+ require 'ruby_jard/commands/jard/hide_command'
5
+ require 'ruby_jard/commands/jard/color_scheme_command'
6
+ require 'ruby_jard/commands/jard/output_command'
7
+
8
+ module RubyJard
9
+ module Commands
10
+ # Command used to explore stacktrace.
11
+ class JardCommand < Pry::ClassCommand
12
+ group 'RubyJard'
13
+ description 'Show all current program output'
14
+
15
+ match 'jard'
16
+
17
+ banner <<-BANNER
18
+ Usage: jard [-h] [sub commands]
19
+ BANNER
20
+
21
+ SUB_COMMANDS = {
22
+ 'show' => RubyJard::Commands::ShowCommand,
23
+ 'hide' => RubyJard::Commands::HideCommand,
24
+ 'color-scheme' => RubyJard::Commands::ColorSchemeCommand,
25
+ 'output' => RubyJard::Commands::OutputCommand
26
+ }.freeze
27
+
28
+ def subcommands(cmd)
29
+ SUB_COMMANDS.each do |command_name, sub_command|
30
+ cmd.command command_name do |opt|
31
+ opt.description sub_command.description
32
+ opt.run do |_, arguments|
33
+ @ran_sub_command = true
34
+ sub_command.new(context).send(:call_safely, *arguments)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def process
41
+ return if @ran_sub_command
42
+ return if ['-h', '--help'].include?(args.first) || SUB_COMMANDS.keys.include?(args.first)
43
+
44
+ pry_instance.output.puts help
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Pry::Commands.add_command(RubyJard::Commands::JardCommand)
@@ -10,12 +10,13 @@ module RubyJard
10
10
  match 'list'
11
11
 
12
12
  banner <<-BANNER
13
- Usage:
14
- - list
15
- - l
13
+ Usage: list
14
+ Examples:
15
+ list
16
+ l
17
+ whereami
16
18
 
17
19
  Refresh the current UI.
18
-
19
20
  BANNER
20
21
 
21
22
  def process
@@ -4,22 +4,27 @@ module RubyJard
4
4
  module Commands
5
5
  # Command used to continue program execution to the next line.
6
6
  class NextCommand < Pry::ClassCommand
7
+ include RubyJard::Commands::ValidationHelpers
8
+
7
9
  group 'RubyJard'
8
10
  description 'Next into the execution of the current line'
9
11
 
10
12
  match 'next'
11
13
 
12
14
  banner <<-BANNER
13
- Usage: next
14
-
15
- Continue program execution to the next line. If the current frame reaches the end, it continue the next line of upper frame.
16
-
15
+ Usage: next [times]
17
16
  Examples:
18
17
  next
18
+ next 1
19
+ next 7
20
+
21
+ Continue program execution to the next line. If the current frame reaches the end, it continue the next line of upper frame.
19
22
  BANNER
20
23
 
21
24
  def process
22
- RubyJard::ControlFlow.dispatch(:next)
25
+ times = validate_positive_integer!(args.first || 1)
26
+
27
+ RubyJard::ControlFlow.dispatch(:next, times: times.to_i)
23
28
  end
24
29
  end
25
30
  end