Class: Rex::Ui::Text::Shell::HistoryManager
- Inherits:
-
Object
- Object
- Rex::Ui::Text::Shell::HistoryManager
- Defined in:
- lib/rex/ui/text/shell/history_manager.rb
Constant Summary collapse
- MAX_HISTORY =
2000
Instance Method Summary collapse
- #_close ⇒ Object
- #_contexts ⇒ Object
- #_debug=(value) ⇒ Object
-
#flush ⇒ Object
Flush the contents of the write queue to disk.
-
#initialize ⇒ HistoryManager
constructor
A new instance of HistoryManager.
- #inspect ⇒ Object
-
#with_context(history_file: nil, name: nil, input_library: nil, &block) ⇒ nil
Create a new history command context when executing the given block.
Constructor Details
#initialize ⇒ HistoryManager
Returns a new instance of HistoryManager.
14 15 16 17 18 19 20 21 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 14 def initialize @contexts = [] @debug = false # Values dequeued before work is started @write_queue = ::Queue.new # Values dequeued after work is completed @remaining_work = ::Queue.new end |
Instance Method Details
#_close ⇒ Object
64 65 66 67 68 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 64 def _close event = { type: :close } @write_queue << event @remaining_work << event end |
#_contexts ⇒ Object
56 57 58 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 56 def _contexts @contexts end |
#_debug=(value) ⇒ Object
60 61 62 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 60 def _debug=(value) @debug = value end |
#flush ⇒ Object
Flush the contents of the write queue to disk. Blocks synchronously.
44 45 46 47 48 49 50 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 44 def flush until @write_queue.empty? && @remaining_work.empty? sleep 0.1 end nil end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 52 def inspect "#<HistoryManager stack size: #{@contexts.length}>" end |
#with_context(history_file: nil, name: nil, input_library: nil, &block) ⇒ nil
Create a new history command context when executing the given block
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rex/ui/text/shell/history_manager.rb', line 30 def with_context(history_file: nil, name: nil, input_library: nil, &block) # Default to Readline for backwards compatibility. push_context(history_file: history_file, name: name, input_library: input_library || :readline) begin block.call ensure pop_context end nil end |