code: def get_code_num(s: str) -> Optional[int]:
      
      if ';' in s:
          # Extended fore/back codes.
          numberstr = s.rpartition(';')[-1][:-1]
      else:
          # Fore, back, style, codes.
          numberstr = s.rpartition('[')[-1][:-1]
  
      num = try_parse_int(
          numberstr,
          default=None,
          minimum=0,
          maximum=255
      )
      if num is None:
          raise InvalidEscapeCode(numberstr)
      return num
docs: Get code number from an escape code.
          Raises InvalidEscapeCode if an invalid number is found.