{str {state {}}} {
    if {$state eq ""} {
      array set f [empty_formatting]
    } else {
      array set f $state
    }
    set f(c) [set f(o) 0]
    switch -- [string index $str 0] [list \
      \003 {
        regexp {^\003((\d*)(,(\d*))?)?} $str {} a b {} c
        if {$a eq ""} {
          set f(fg) [set f(bg) -1]
          set f(c) 1
        }
        if {!($b eq "")} {
          set f(fg) $b
        }
        if {!($c eq "")} {
          set f(bg) $c
        }
      } \002 {
        set f(b) [expr !$f(b)]
      } \037 {
        set f(u) [expr !$f(u)]
      } \026 {
        set f(r) [expr !$f(r)]
      } \017 {
        set f(o) 1
      }]
    array get f
  }