Skip to content

Commit 6237201

Browse files
committed
fix(prompt): display on exact line size fit
1 parent d53e0ac commit 6237201

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

examples/prompt.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ local Prompt = require("terminal.cli.prompt")
44
local pr = Prompt {
55
prompt = "Enter something: ",
66
value = "Hello, 你-好 World 🚀!",
7-
max_length = 262,
8-
position = 2,
7+
max_length = 62,
8+
-- position = 2,
99
cancellable = true,
1010
text_attr = { brightness = "high" },
1111
}

src/terminal/cli/prompt.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ function Prompt:draw()
217217
self.prompt, -- prompt
218218
function() return t.text.stack.push_seq(self.text_attr) end, -- push text attributes
219219
l, -- all lines concatenated (we formatted using padding, so should properly wrap)
220+
function()
221+
if #self.current_lines > 1 and self.current_lines[#self.current_lines]:len_char() == 0 then
222+
return "\n" -- last line is just for cursor (empty line), case not handled by the padding, insert newline
223+
end
224+
return ""
225+
end,
220226
t.text.stack.pop_seq, -- pop text attributes
221227
t.clear.eol_seq(), -- clear the rest of the last line
222228
t.cursor.position.column_seq(self.cursor_col), -- move cursor to proper column

0 commit comments

Comments
 (0)