Class: PryDe::BacktraceEdit

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-de/backtrace_edit.rb

Class Method Summary collapse

Class Method Details

.blue(str) ⇒ Object



71
# File 'lib/pry-de/backtrace_edit.rb', line 71

def blue str; color 34, str end

.color(num, str) ⇒ Object



73
74
75
# File 'lib/pry-de/backtrace_edit.rb', line 73

def color num, str
  "\e[#{num}m#{str}\e[0m" % [num, str]
end

.cyan(str) ⇒ Object



72
# File 'lib/pry-de/backtrace_edit.rb', line 72

def cyan str; color 36, str end

.edit(input) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pry-de/backtrace_edit.rb', line 12

def edit input
  hash = parse_line input
  path = hash[:path]
  unless File.exist? path
    return warn <<-EOT
From this line: '#{cyan input}'
parsed '#{yellow path}', which does not exist.
Assuming to not be a frame and, skipping
    EOT
  end
  viewer = vim_already_open_for(path) ? 'view' : 'vim'
  offset = ?+ + hash[:line]
  cmdheight = '+set cmdheight=2'
  msg = vim_message_for hash[:extra]
  warn blue "# #{hash[:extra]}"
  recenter = '+norm zz'
  verbose_system viewer, path, cmdheight, msg, recenter, offset
  raise 'OK, done.' unless $?.success?
end

.green(str) ⇒ Object



69
# File 'lib/pry-de/backtrace_edit.rb', line 69

def green str; color 32, str end

.interactObject



5
6
7
8
9
10
# File 'lib/pry-de/backtrace_edit.rb', line 5

def interact
  warn green 'ZZ to hop to next, :cq to end.'
  trace.each do |e| edit e end
rescue => e
  puts yellow e
end

.parse_line(input) ⇒ Object



55
56
57
58
59
60
# File 'lib/pry-de/backtrace_edit.rb', line 55

def parse_line input
  input.chomp!
  r = Hash[[:path, :line, :extra].zip(input.split(?:, 3))]
  r[:path].sub! /^\s*from /, ''
  r
end

.traceObject



32
33
34
35
36
37
# File 'lib/pry-de/backtrace_edit.rb', line 32

def trace
  require 'jist'
  trace = Jist.paste
  return trace_via_stdin if trace.empty? or not trace[/:in /]
  trace.split ?\n
end

.trace_via_stdinObject



39
40
41
42
43
# File 'lib/pry-de/backtrace_edit.rb', line 39

def trace_via_stdin
  warn yellow 'Copy from clipboard not working.'
  warn cyan 'Paste manually, then hit ^d'
  STDIN.readlines
end

.verbose_system(*args) ⇒ Object



62
63
64
65
66
67
# File 'lib/pry-de/backtrace_edit.rb', line 62

def verbose_system *args
  require 'shellwords'
  cmd = args.map(&:shellescape).join ' '
  warn cyan '    '+cmd
  system *args
end

.vim_already_open_for(path) ⇒ Object



45
46
47
48
# File 'lib/pry-de/backtrace_edit.rb', line 45

def vim_already_open_for path
  swpfile = "%s/.%s.swp" % [ File.dirname(path), File.basename(path) ]
  File.exist? swpfile
end

.vim_message_for(str) ⇒ Object



50
51
52
53
# File 'lib/pry-de/backtrace_edit.rb', line 50

def vim_message_for str
  cleaned = str.gsub ?", '\\"'
  '+set ch=2|echo "%s"' % cleaned
end

.yellow(str) ⇒ Object



70
# File 'lib/pry-de/backtrace_edit.rb', line 70

def yellow str; color 33, str end