Ebook mode detection is more robust now.

This patch add the robust ebook mode detection used in
the Terminal activity