Skip to content

Commit 395d66f

Browse files
committed
feat(input): add wordwrap option
1 parent cfb3359 commit 395d66f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

examples/prompt.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local pr = Prompt {
88
-- position = 2,
99
cancellable = true,
1010
text_attr = { brightness = "high" },
11+
wordwrap = true,
1112
}
1213

1314
t.initwrap(function () -- on Windows: wrap for utf8 output

src/terminal/cli/prompt.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
--
66
-- Features: Prompt, UTF8 support, async input, (to be added: secrets, scrolling and wrapping)
77
--
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.
99
--
1010
-- *Usage:*
1111
-- local prompt = Prompt {
@@ -110,6 +110,7 @@ end
110110
-- @tparam[opt=80] number opts.max_length The maximum length of the input.
111111
-- @tparam[opt] string opts.word_delimiters Word delimiters for word operations.
112112
-- @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.
113114
-- @treturn Prompt A new Prompt instance.
114115
-- @name cli.Prompt
115116
function Prompt:init(opts)
@@ -131,6 +132,7 @@ function Prompt:init(opts)
131132
self.prompt_width = width.utf8swidth(self.prompt) -- the width of the prompt in characters
132133
self.max_length = opts.max_length or 80 -- the maximum length of the input
133134
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
134136

135137
if self.value:len_char() > self.max_length then
136138
-- truncate the value if it is too long, keep cursor position
@@ -169,7 +171,7 @@ function Prompt:renew_cached_data()
169171
self.current_lines, self.cursor_row, self.cursor_col = self.value:format {
170172
width = self.screen_cols,
171173
first_width = self.screen_cols - self.prompt_width,
172-
wordwrap = false,
174+
wordwrap = self.wordwrap,
173175
pad = true,
174176
pad_last = false,
175177
no_new_cursor_line = false,

0 commit comments

Comments
 (0)