Class: Fatty::PromptSession
- Inherits:
-
ModalSession
- Object
- Session
- ModalSession
- Fatty::PromptSession
- Defined in:
- lib/fatty/session/prompt_session.rb
Constant Summary collapse
- PROMPT_POPUP_MAX_WIDTH =
120- PROMPT_POPUP_MIN_WIDTH =
20- PROMPT_POPUP_MARGIN =
2
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Attributes inherited from ModalSession
Attributes inherited from Session
Instance Method Summary collapse
- #id ⇒ Object
-
#init(terminal:) ⇒ Object
Session Protocol.
-
#initialize(initial: "", prompt: "> ", title: "Prompt", message: nil, kind: nil, history_ctx: nil, history_path: :default, history: nil, save_history: true) ⇒ PromptSession
constructor
A new instance of PromptSession.
-
#state ⇒ Object
Other public API methods.
- #update(command) ⇒ Object
- #view ⇒ Object
Methods inherited from ModalSession
Methods inherited from Session
#close, #handle_resize, #persist!, #renderer, #screen, #tick
Methods included from Actionable
Constructor Details
#initialize(initial: "", prompt: "> ", title: "Prompt", message: nil, kind: nil, history_ctx: nil, history_path: :default, history: nil, save_history: true) ⇒ PromptSession
Returns a new instance of PromptSession.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fatty/session/prompt_session.rb', line 13 def initialize(initial: "", prompt: "> ", title: "Prompt", message: nil, kind: nil, history_ctx: nil, history_path: :default, history: nil, save_history: true) super(keymap: Keymaps.emacs) @title = title&.to_s @message = &.to_s @kind = kind&.to_sym @save_history = !!save_history @history = history || Fatty::History.for_path(history_path) @field = Fatty::InputField.new( prompt: prompt, history_kind: :prompt, history: @history, history_ctx: history_ctx, ) @field.buffer.replace(initial.to_s) @field.buffer.bol @win = nil end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/fatty/session/prompt_session.rb', line 5 def field @field end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
5 6 7 |
# File 'lib/fatty/session/prompt_session.rb', line 5 def history @history end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/fatty/session/prompt_session.rb', line 5 def @message end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/fatty/session/prompt_session.rb', line 5 def title @title end |
Instance Method Details
#id ⇒ Object
11 |
# File 'lib/fatty/session/prompt_session.rb', line 11 def id = :prompt |
#init(terminal:) ⇒ Object
Session Protocol
36 37 38 39 40 |
# File 'lib/fatty/session/prompt_session.rb', line 36 def init(terminal:) super rebuild_windows! [] end |
#state ⇒ Object
Other public API methods
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/fatty/session/prompt_session.rb', line 111 def state [ title.to_s.dup.freeze, .to_s.dup.freeze, field.prompt_text.to_s.dup.freeze, field.buffer.text.to_s.dup.freeze, field.buffer.cursor, field.buffer.virtual_suffix.to_s.dup.freeze, renderer.screen.rows, renderer.screen.cols, ] end |
#update(command) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fatty/session/prompt_session.rb', line 42 def update(command) commands = case command.action 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 when :terminal_paste field.act_on(:paste, command.payload.fetch(:text, ""), env: action_env(event: nil)) [] else [] end Array(commands) end |
#view ⇒ Object
62 63 64 65 66 |
# File 'lib/fatty/session/prompt_session.rb', line 62 def view return unless @win renderer.render_prompt_popup(session: self) end |