Though TUIs have its place, this totally destroys the ability for text processing used a lot on Unix platforms where a more simple output would suffice. For some applications like this it might be better to go for a non-terminal GUI anyway.
You can check if stdout is a tty: if it's not, you output raw text. GNU ls does this: by default it outputs in a multiple column layout, but when piped, it outputs one file per line.