save and store terminal state