Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (88 sloc) 2.773 kB
8d7a289 @rocky Rename "base" files.
authored
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
3
4 # A base class for a debugger interface.
5
6 class Trepan
7
8 unless defined?(NotImplementedMessage)
9 NotImplementedMessage = 'This method must be overriden in a subclass'
10 end
11
12 # A debugger interface handles the communication or interaction with between
13 # the program and the outside portion which could be
14 # - a user,
15 # - a front-end that talks to a user, or
16 # - another interface in another process or computer
17 class Interface
18
19 attr_accessor :history_io, :history_save, :interactive, :input, :output
20
21 unless defined?(YES)
22 YES = %w(y yes oui si yep ja)
23 NO = %w(n no non nope nein)
24 YES_OR_NO = YES + NO
25 end
26
27 def initialize(inp=nil, out=nil, opts={})
28 @histfile = nil
29 @history_io = nil
30 @history_save = false
31 @histsize = nil
32 @input = inp || STDIN
33 @interactive = false
34 @opts = opts
35 @output = out || STDOUT
36 end
37
38 # Closes all input and/or output.
39 def close
40 @input.close unless !@input || @input.closed?
41 @output.close unless !@output || @output.closed?
42 end
43
44 # Called when a dangerous action is about to be done to make sure
45 # it's okay. `prompt' is printed; user response is returned.
46 def confirm(prompt, default=false)
47 raise RuntimeError, Trepan::NotImplementedMessage
48 end
49
50 # Common routine for reporting debugger error messages.
51 def errmsg(str, prefix='** ')
52 if str.is_a?(Array)
53 str.each{|s| errmsg(s)}
54 else
55 str.split("\n").each do |s|
56 msg("%s%s" % [prefix, s])
57 end
58 end
59 end
60
61 def finalize(last_wishes=nil)
62 close
63 end
64
65 def input_eof?
66 @input.eof?
67 end
68
69 # Return true if interface is interactive.
70 def interactive?
71 # Default false and making subclasses figure out how to determine
72 # interactiveness.
73 false
74 end
75
76 # used to write to a debugger that is connected to this
77 # server; `str' written will have a newline added to it.
78 def msg(message)
79 if message.is_a?(Array)
80 message.each{|s| msg(s)}
81 else
82 message = message ? message.to_s + "\n" : ''
83 @output.write(message)
84 end
85 end
86
87 # used to write to a debugger that is connected to this
88 # server; `str' written will not have a newline added to it
89 def msg_nocr(msg)
90 @output.write(msg)
91 end
92
93 def read_command(prompt='')
94 line = readline(prompt)
95 # FIXME: Do something with history?
96 return line
97 end
98
99 def readline(prompt='')
100 @output.flush
101 @output.write(prompt) if prompt and prompt.size > 0
102 @input.readline
103 end
104 end
105 end
Something went wrong with that request. Please try again.