I think you could simply this to `if prompt.strip().endswith(b':'):` here (at least, that works for me), since the first condition is probably never matched. `br"\\x1b<"` is the sequence `\\`, `x`, `1`, `b`, `<`, while you probably meant `b"\\x1b<"`, which is `ESC`, `<`. Anyway, when I change `br"\\x1b<"` to `b"\\x1b<"`, it doesn't work anymore.