Refactor conversion between string and curses attribute.

  Since that cuts down on duplication.