handle history writing internally

The problem with ->WriteHistory() is that it outputs the history entires
unmodified, which for multiline entries results in them being turned
into multiple entries when you restart tdsql.

Long term we should probably reimplement ->ReadHistory() too, and use
YAML or something to be able to store multiline history safely.  (We
could detect ---\n at the top of the file for backward compatibility)