@@ -19,6 +19,7 @@ local M = {}
1919--- @field action ? send_action terminal interaction mode (default : " focus" )
2020--- @field trim ? boolean remove leading /trailing whitespace (default : true )
2121--- @field new_line ? boolean append newline for command execution (default : true )
22+ --- @field clear ? boolean clear terminal before sending (default : false )
2223--- @field decorator ? string | fun ( text : string[] ): string[] transform text before sending
2324
2425--- @param term Terminal
@@ -30,13 +31,15 @@ function M.send(term, input, opts)
3031 local action = opts .action or " focus"
3132 local trim = opts .trim == nil or opts .trim
3233 local new_line = opts .new_line == nil or opts .new_line
34+ local clear = opts .clear or false
3335 local decorator = M ._parse_decorator (opts .decorator )
3436 if not M ._validate_selection_type (input ) then return term end
3537 local computed_input = M ._parse_input (input , term )
3638 term ._state .last_sent = vim .deepcopy (computed_input )
3739 computed_input = M ._maybe_add_new_line (computed_input , new_line )
3840 computed_input = M ._maybe_trim_input (computed_input , trim )
3941 computed_input = decorator (computed_input )
42+ M ._maybe_clear (term , clear )
4043 M ._perform_action (term , action )
4144 vim .fn .chansend (term ._state .job_id , computed_input )
4245 term :_scroll_bottom ()
@@ -50,6 +53,15 @@ function M.clear(term, action)
5053 return M .send (term , { clear }, { action = action })
5154end
5255
56+ --- @param term Terminal
57+ --- @param clear boolean
58+ --- @private
59+ function M ._maybe_clear (term , clear )
60+ if clear then
61+ M .clear (term , " start" )
62+ end
63+ end
64+
5365function M ._validate_selection_type (input )
5466 local valid_selection_types = { " single_line" , " visual_lines" , " visual_selection" , " last" }
5567 if type (input ) == " string" and not vim .tbl_contains (valid_selection_types , input ) then
0 commit comments