code: def format_terminal_row(headers, example_row):
      
  
      def format_column(col):
          if isinstance(col, str):
              return '{{:{w}.{w}}}'
          return '{{:<{w}}}'
  
      widths = [max(len(h), len(str(d))) for h, d in zip(headers, example_row)]
  
      # Truncate last column to fit terminal width
      original_last_width = widths[-1]
      if sys.stdout.isatty():
          widths[-1] = max(
              len(headers[-1]),
              # console width - width of other columns and gutters - 3 for '...'
              tty.width() - sum(w + 2 for w in widths[0:-1]) - 3)
  
      # Build format string
      cols = [format_column(c).format(w=w) for c, w in zip(example_row, widths)]
      format_string = '  '.join(cols)
      if original_last_width > widths[-1]:
          format_string += '...'
  
      return format_string
docs: Uses headers and a row of example data to generate a format string
      for printing a single row of data.
  
      Args:
          headers (tuple of strings): The headers for each column of data
          example_row (tuple): A representative tuple of strings or ints
  
      Returns
          string: A format string with a size for each column