def one_screen? str
    cols, lines = `tput cols`.to_i, `tput lines`.to_i
    (str.count("\n") + 2) <= lines && # count last line and prompt
      str.gsub(/\e\[[^m]*m/, '').size <= cols * lines
  end
def one_screen? str
    cols, lines = `tput cols`.to_i, `tput lines`.to_i
    (str.count("\n") + 2) <= lines && # count last line and prompt
      str.gsub(/\e\[[^m]*m/, '').size <= cols * lines
  end
`less -F` can't cat the output, so we need to detect by ourselves.
 `less -X` would mess up the buffers, so it's not desired, either.