@njvack @b0rk In Unix there are parts of the kernel, called "device drivers", that handle device I/O. In this case it's the "terminal driver". The terminal driver gets control when a process issues a `read()` or `write()` call on a file descriptor that has been opened to a device. Also, when the hardware I/O bus signals an I/O interrupt, the kernel transfers control to the appropriate driver the handle the interrupt.
When you type a character on a terminal, there is an I/O interrupt and the kernel asks the terminal driver to handle it. Normally, the driver just copies the character into a per-device buffer, waiting for the next read() call from the user process that has the terminal open. If the character was a control-W, though, the driver instead erases characters out of that buffer back to the last whitespace. Later, when the user process does `read()` to ask the driver for the contents of the buffer, the erased characters will be gone as if they had never been typed.
The driver may also send some delete characters back to the terminal to cause it to backspace and delete the erased word. (Normally, the terminal is in "no echo" mode which means it doesn't display what you type on it, instead it only displays whatever the terminal driver sends back.) If the driver knows you're on a non-backspacing terminal it may send something else to try to indicate that the word was deleted.
This is all in what's called "cooked" mode. Unix terminal devices also have a "raw" mode where the driver just copies stuff into the buffer with no processing. Tools like readline put the terminal into raw mode.