A class to organize all history-related functionality in one place.
| 470 | |
| 471 | |
| 472 | class HistoryManager(HistoryAccessor): |
| 473 | """A class to organize all history-related functionality in one place. |
| 474 | """ |
| 475 | # Public interface |
| 476 | |
| 477 | # An instance of the IPython shell we are attached to |
| 478 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC', |
| 479 | allow_none=True) |
| 480 | # Lists to hold processed and raw history. These start with a blank entry |
| 481 | # so that we can index them starting from 1 |
| 482 | input_hist_parsed = List([""]) |
| 483 | input_hist_raw = List([""]) |
| 484 | # A list of directories visited during session |
| 485 | dir_hist = List() |
| 486 | @default('dir_hist') |
| 487 | def _dir_hist_default(self): |
| 488 | try: |
| 489 | return [os.getcwd()] |
| 490 | except OSError: |
| 491 | return [] |
| 492 | |
| 493 | # A dict of output history, keyed with ints from the shell's |
| 494 | # execution count. |
| 495 | output_hist = Dict() |
| 496 | # The text/plain repr of outputs. |
| 497 | output_hist_reprs = Dict() |
| 498 | |
| 499 | # The number of the current session in the history database |
| 500 | session_number = Integer() |
| 501 | |
| 502 | db_log_output = Bool(False, |
| 503 | help="Should the history database include output? (default: no)" |
| 504 | ).tag(config=True) |
| 505 | db_cache_size = Integer(0, |
| 506 | help="Write to database every x commands (higher values save disk access & power).\n" |
| 507 | "Values of 1 or less effectively disable caching." |
| 508 | ).tag(config=True) |
| 509 | # The input and output caches |
| 510 | db_input_cache = List() |
| 511 | db_output_cache = List() |
| 512 | |
| 513 | # History saving in separate thread |
| 514 | save_thread = Instance('IPython.core.history.HistorySavingThread', |
| 515 | allow_none=True) |
| 516 | save_flag = Instance(threading.Event, allow_none=True) |
| 517 | |
| 518 | # Private interface |
| 519 | # Variables used to store the three last inputs from the user. On each new |
| 520 | # history update, we populate the user's namespace with these, shifted as |
| 521 | # necessary. |
| 522 | _i00 = Unicode(u'') |
| 523 | _i = Unicode(u'') |
| 524 | _ii = Unicode(u'') |
| 525 | _iii = Unicode(u'') |
| 526 | |
| 527 | # A regex matching all forms of the exit command, so that we don't store |
| 528 | # them in the history (it's annoying to rewind the first entry and land on |
| 529 | # an exit call). |
no outgoing calls