Permalink
Browse files

Add option to get_history to determine whether to retrieve the curren…

…t session or the entire history. Qt console on startup requests entire history.
  • Loading branch information...
1 parent 13e5c56 commit ead117c1ef6a295c3c82414f01a82f353de1c392 @takluyver committed Feb 15, 2011
View
@@ -185,7 +185,7 @@ def reload_history(self):
if self.shell.has_readline:
self.populate_readline_history()
- def get_history(self, index=None, raw=False, output=True):
+ def get_history(self, index=None, raw=False, output=True,this_session=True):
"""Get the history list.
Get the input and output history.
@@ -200,6 +200,9 @@ def get_history(self, index=None, raw=False, output=True):
If True, return the raw input.
output : bool
If True, then return the output as well.
+ this_session : bool
+ If True, indexing is from 1 at the start of this session.
+ If False, indexing is from 1 at the start of the whole history.
Returns
-------
@@ -213,9 +216,13 @@ def get_history(self, index=None, raw=False, output=True):
input_hist = self.input_hist_parsed
if output:
output_hist = self.output_hist
+
+ if this_session:
+ offset = self.session_offset
+ else:
+ offset = -1
n = len(input_hist)
- offset = self.session_offset
if index is None:
start=offset+1; stop=n
elif isinstance(index, int):
@@ -1277,8 +1277,8 @@ def wrapper():
self.reload_history()
return wrapper
- def get_history(self, index=None, raw=False, output=True):
- return self.history_manager.get_history(index, raw, output)
+ def get_history(self, index=None, raw=False, output=True,this_session=True):
+ return self.history_manager.get_history(index, raw, output,this_session)
#-------------------------------------------------------------------------
@@ -217,7 +217,8 @@ def _started_channels(self):
""" Reimplemented to make a history request.
"""
super(IPythonWidget, self)._started_channels()
- self.kernel_manager.xreq_channel.history(raw=True, output=False)
+ self.kernel_manager.xreq_channel.history(raw=True, output=False,
+ this_session=False)
#---------------------------------------------------------------------------
# 'ConsoleWidget' public interface
View
@@ -301,10 +301,9 @@ def object_info_request(self, ident, parent):
io.raw_print(msg)
def history_request(self, ident, parent):
- output = parent['content']['output']
- index = parent['content']['index']
- raw = parent['content']['raw']
- hist = self.shell.get_history(index=index, raw=raw, output=output)
+ # parent['content'] should contain keys "index", "raw", "output" and
+ # "this_session".
+ hist = self.shell.get_history(**parent['content'])
content = {'history' : hist}
msg = self.session.send(self.reply_socket, 'history_reply',
content, parent, ident)
@@ -281,7 +281,7 @@ def object_info(self, oname):
self._queue_request(msg)
return msg['header']['msg_id']
- def history(self, index=None, raw=False, output=True):
+ def history(self, index=None, raw=False, output=True, this_session=True):
"""Get the history list.
Parameters
@@ -294,12 +294,16 @@ def history(self, index=None, raw=False, output=True):
If True, return the raw input.
output : bool
If True, then return the output as well.
+ this_session : bool
+ If True, returns only history from the current session. Otherwise,
+ includes reloaded history from previous sessions.
Returns
-------
The msg_id of the message sent.
"""
- content = dict(index=index, raw=raw, output=output)
+ content = dict(index=index, raw=raw, output=output,
+ this_session=this_session)
msg = self.session.msg('history_request', content)
self._queue_request(msg)
return msg['header']['msg_id']

0 comments on commit ead117c

Please sign in to comment.