Class: Fatty::ISearchSession
- Defined in:
- lib/fatty/session/isearch_session.rb
Constant Summary collapse
- DEFAULT_ISEARCH_HISTORY_FILE =
File.("~/.fatty_search_history")
- DEFAULT_ISEARCH_HISTORY_MAX =
200
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#last_pattern ⇒ Object
readonly
Returns the value of attribute last_pattern.
Attributes inherited from Session
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(direction: :forward, last_pattern: nil, history: nil) ⇒ ISearchSession
constructor
A new instance of ISearchSession.
-
#update(command) ⇒ Object
Session Protocol.
- #view ⇒ Object
Methods inherited from Session
#close, #handle_resize, #init, #persist!, #renderer, #screen, #tick
Methods included from Actionable
Constructor Details
#initialize(direction: :forward, last_pattern: nil, history: nil) ⇒ ISearchSession
Returns a new instance of ISearchSession.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fatty/session/isearch_session.rb', line 14 def initialize(direction: :forward, last_pattern: nil, history: nil) super(keymap: Keymaps.emacs) @direction = direction.to_sym @failed = false @last_text = nil @last_pattern = last_pattern.to_s @field = Fatty::InputField.new( prompt: Prompt.new { isearch_prompt }, history: history, history_kind: :search_string, history_ctx: { kind: :search, regex: false }, ) end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
7 8 9 |
# File 'lib/fatty/session/isearch_session.rb', line 7 def direction @direction end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/fatty/session/isearch_session.rb', line 7 def field @field end |
#last_pattern ⇒ Object (readonly)
Returns the value of attribute last_pattern.
7 8 9 |
# File 'lib/fatty/session/isearch_session.rb', line 7 def last_pattern @last_pattern end |
Instance Method Details
#id ⇒ Object
9 |
# File 'lib/fatty/session/isearch_session.rb', line 9 def id = :isearch |
#update(command) ⇒ Object
Session Protocol
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fatty/session/isearch_session.rb', line 32 def update(command) log_update(command) commands = case command.action when :key ev = command.payload.fetch(:event) action, args = resolve_action(ev) if action apply_action(action, args, event: ev) else [] end when :terminal_paste env = action_env(event: nil) @field.act_on( :paste, command.payload.fetch(:text, ""), env: env, ) @field.sync_virtual_suffix! maybe_preview! when :isearch_set_failed @failed = !!command.payload[:failed] @field.prompt = isearch_prompt [] else [] end Array(commands) end |
#view ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/fatty/session/isearch_session.rb', line 63 def view row = screen.output_rect.rows - 1 renderer.show_cursor renderer.render_pager_field(@field, row: row, role: :search_input) renderer.restore_output_cursor(@field, row: row) end |