Search code examples
pythonc++terminalconsole

Is there go up line character? (Opposite of \n)


I would like to overwrite something on a line above in a serial console. Is there a character that allows me to move up?


Solution

  • Most terminals understand ANSI escape codes. The relevant codes for this use case:

    • "\033[F" – move cursor to the beginning of the previous line
    • "\033[A" – move cursor up one line

    Example (Python):

    print("\033[FMy text overwriting the previous line.")