5
5
--
6
6
-- Features: Prompt, UTF8 support, async input, (to be added: secrets, scrolling and wrapping)
7
7
--
8
- -- NOTE: you MUST `terminal.initialize` before calling this widget's `:run()` method.
8
+ -- NOTE: you MUST call `terminal.initialize` before calling this widget's `:run()` method.
9
9
--
10
10
-- *Usage:*
11
11
-- local prompt = Prompt {
110
110
-- @tparam [opt=80] number opts.max_length The maximum length of the input.
111
111
-- @tparam [opt] string opts.word_delimiters Word delimiters for word operations.
112
112
-- @tparam [opt] table opts.text_attr Text attributes for the prompt (input value only).
113
+ -- @tparam [opt=false] boolean opts.wordwrap Whether to wordwrap the input value.
113
114
-- @treturn Prompt A new Prompt instance.
114
115
-- @name cli.Prompt
115
116
function Prompt :init (opts )
@@ -131,6 +132,7 @@ function Prompt:init(opts)
131
132
self .prompt_width = width .utf8swidth (self .prompt ) -- the width of the prompt in characters
132
133
self .max_length = opts .max_length or 80 -- the maximum length of the input
133
134
self .text_attr = opts .text_attr or {} -- text attributes for the input value
135
+ self .wordwrap = not not opts .wordwrap -- whether to wordwrap the input value
134
136
135
137
if self .value :len_char () > self .max_length then
136
138
-- truncate the value if it is too long, keep cursor position
@@ -169,7 +171,7 @@ function Prompt:renew_cached_data()
169
171
self .current_lines , self .cursor_row , self .cursor_col = self .value :format {
170
172
width = self .screen_cols ,
171
173
first_width = self .screen_cols - self .prompt_width ,
172
- wordwrap = false ,
174
+ wordwrap = self . wordwrap ,
173
175
pad = true ,
174
176
pad_last = false ,
175
177
no_new_cursor_line = false ,
0 commit comments