Changed not to clear the screen when refresh.
Changed refresh() inline and to use fputs().
Changed to call reset_display_attrs() via atexit().