You can use instr
to read the text currently in the window, then erase it with clrtoeol
, and addstr
to put the text in the new location. (Add w
and/or mv
prefixes as needed).
Note that a real text editor doing an "insert newline" will not just be operating on screen lines. It will operate on a logical line in the file buffer, potentially affecting multiple screen lines (if the line in the file is big enough to wrap). If you don't keep your own logical line structure separate from what you're displaying on screen, you aren't really doing a text-editor-like job.