Class: Fatty::SearchSession
- Defined in:
- lib/fatty/session/search_session.rb
Constant Summary collapse
- DEFAULT_SEARCH_HISTORY_FILE =
File.("~/.fatty_search_history")
- DEFAULT_SEARCH_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.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Attributes inherited from Session
#counter, #id, #keymap, #terminal
Instance Method Summary collapse
-
#initialize(direction: :backward, regex: false, history: nil, prefix: nil) ⇒ SearchSession
constructor
A new instance of SearchSession.
-
#update(command) ⇒ Object
Session Prototcol.
- #view ⇒ Object
Methods inherited from Session
#close, #handle_resize, #init, #persist!, #renderer, #screen, #tick
Methods included from Actionable
Constructor Details
#initialize(direction: :backward, regex: false, history: nil, prefix: nil) ⇒ SearchSession
Returns a new instance of SearchSession.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fatty/session/search_session.rb', line 12 def initialize(direction: :backward, regex: false, history: nil, prefix: nil) super(keymap: Keymaps.emacs) @direction = direction.to_sym @regex = !!regex prompt = search_prompt(direction: @direction, regex: @regex) search_session = self @field = Fatty::InputField.new( prompt: prompt, history: history, history_kind: -> { search_session.regex ? :search_regex : :search_string }, history_ctx: -> { { kind: :search, regex: search_session.regex } }, ) text = prefix.to_s @field.buffer.replace(text) unless text.empty? end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
7 8 9 |
# File 'lib/fatty/session/search_session.rb', line 7 def direction @direction end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/fatty/session/search_session.rb', line 7 def field @field end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
7 8 9 |
# File 'lib/fatty/session/search_session.rb', line 7 def regex @regex end |
Instance Method Details
#update(command) ⇒ Object
Session Prototcol
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fatty/session/search_session.rb', line 32 def update(command) commands = case command.action when :terminal_paste field.act_on(:paste, command.payload.fetch(:text, ""), env: action_env(event: nil)) [] when :key ev = command.payload.fetch(:event) action, args = resolve_action(ev) if action normalize_action_result(apply_action(action, args, event: ev)) else [] end else [] end Array(commands) end |
#view ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fatty/session/search_session.rb', line 52 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 |