Is it possible to highlight (set a background colour) for the whole line of the prompt in zsh? In my emacs config I have the line on which the cursor sits a slightly different colour to the window background, which is a great visual aid. I'm wondering whether it's possible to do the same in my terminal/zsh prompt, so that it effectivly "draws a line" under everthing that's been run.

I've tried setting PROMPT='%{$bg[grey]%}# ' in my .zshrc but the highlight only extends as far as I type, not to the edge of the terminal.

You can do anything you want with the prompt line* - the problematic aspect is getting it to undo it afterward. I assume you don't want every single line that has ever had a prompt on it displayed in your hilight colors.

It'd almost be easier to delete the line afterward, but then you don't have your command. Maybe delete the prompt then echo the command (with a pseudo-prompt like $). You could have the prompt begin with an ANSI cursor save sequence ESC [s, then in a precmd restore it ESC [u and clear everything after the cursor ESC [0J, then echo the command (I don't recall how to get the command from inside precmd).

*This is an incomplete answer, I don't know how to make it hilight the command in a different background color.

(If you change "\n" to "\r", it should underline the current line, but that doesn't seem to work. I guess zsh erases the current line when printing the prompt, which is what lead me to the first solution.)