Truncating nvim_echo to avoid prompt

I’m using vim.api.nvim_echo to output some text for a plugin I’m writing, and I’m trying to avoid the Press ENTER or type command to continue prompt.

Here’s an example that triggers that prompt:

:lua vim.api.nvim_echo({ { string.rep("A", 200) } }, false, {})

I’ve tried using the window width to truncate the result. Even though the message now fits on one line, I’m still seeing the prompt.

:lua vim.api.nvim_echo({ { string.sub(string.rep("A", 200), 1, vim.fn.winwidth(0) - 1) } }, false, {})

In my Vim instance, it seems the magic number of 103 is what’s needed to prevent this prompt from being displayed. Is there a way that I can programmatically determine what value is needed to truncate my string to avoid the prompt? Or, better yet, is there a way I can avoid the prompt entirely while using vim.api.nvim_echo?

I tested a bunch and came to the conclusion that

string.sub(string.rep("A", 1000), 1, vim.fn.winwidth(0) - 12)

never promoted even after changing the terminal font size.

vim.v.echospace can be used.