I have a function in python that the user can run, which can be exit by sending ctrl-c. I want to display a timer on this function, to show how long it was running for, followed by a few static messages. My current implementation of this involves a combination of 33[A
, 33[K
and r
characters. Already works in normal cases.
My issue is that these characters tell the terminal how many physical lines to move up. In case the update string is multiple lines long (suppose they minimized or split panes in tmux) this will cause issues. Is there any way to count the length of the printed strings? I can use os module to get width of terminal, but don’t know how to convert that into lines (preferably for a general string which may contain any ascii characters.
I already looked at curses but this seems geared towards applications needing to rewrite the whole terminal screen. I just want to append to any previous history the terminal might have had.
P.S. I would highly prefer to keep external dependencies as limited as possible. I mean to use this code easily on any containers. Standard Library is of course available.
12