class_docstr: A piece of text with associated style. Segments are produced by the Console render process and
  are ultimately converted in to strings to be written to the terminal.
  
  Args:
      text (str): A piece of text.
      style (:class:`~rich.style.Style`, optional): An optional style to apply to the text.
      control (Tuple[ControlCode], optional): Optional sequence of control codes.
  
  Attributes:
      cell_length (int): The cell length of this Segment.
docstr: Adjust a line to a given width (cropping or padding as required).
  
  Args:
      segments (Iterable[Segment]): A list of segments in a single line.
      length (int): The desired width of the line.
      style (Style, optional): The style of padding if used (space on the end). Defaults to None.
      pad (bool, optional): Pad lines with spaces if they are shorter than `length`. Defaults to True.
  
  Returns:
      List[Segment]: A line of segments with the desired length.
docstr_tok: ["Adjust","a","line","to","a","given","width","(","cropping","or","padding","as","required",")",".","Args",":","segments","(","Iterable","[","Segment","]",")",":","A","list","of","segments","in","a","single","line",".","length","(","int",")",":","The","desired","width","of","the","line",".","style","(","Style",",","optional",")",":","The","style","of","padding","if","used","(","space","on","the","end",")",".","Defaults","to","None",".","pad","(","bool",",","optional",")",":","Pad","lines","with","spaces","if","they","are","shorter","than","`","length","`",".","Defaults","to","True",".","Returns",":","List","[","Segment","]",":","A","line","of","segments","with","the","desired","length","."]
code: def adjust_line_length(
      cls,
      line: List["Segment"],
      length: int,
      style: Optional[Style] = None,
      pad: bool = True,
  ) -> List["Segment"]:
      """Adjust a line to a given width (cropping or padding as required).
  
      Args:
          segments (Iterable[Segment]): A list of segments in a single line.
          length (int): The desired width of the line.
          style (Style, optional): The style of padding if used (space on the end). Defaults to None.
          pad (bool, optional): Pad lines with spaces if they are shorter than `length`. Defaults to True.
  
      Returns:
          List[Segment]: A line of segments with the desired length.
      """
      line_length = sum(segment.cell_length for segment in line)
      new_line: List[Segment]
  
      if line_length < length:
          if pad:
              new_line = line + [
                  cls(" " * (length - line_length), style)
              ]
          else:
              new_line = line[:]
      elif line_length > length:
          new_line = []
          append = new_line.append
          line_length = 0
          for segment in line:
              segment_length = segment.cell_length
              if (
                  line_length + segment_length < length
                  or segment.control
              ):
                  append(segment)
                  line_length += segment_length
              else:
                  text, segment_style, _ = segment
                  text = set_cell_size(text, length - line_length)
                  append(cls(text, segment_style))
                  break
      else:
          new_line = line[:]
      return new_line
  
imports: from enum import IntEnum
  from functools import lru_cache
  from itertools import filterfalse
  from logging import getLogger
  from operator import attrgetter
  from typing import TYPE_CHECKING, Dict, Iterable, List, NamedTuple, Optional, Sequence, Tuple, Type, Union
  from .cells import _is_single_cell_widths, cached_cell_len, cell_len, get_character_cell_size, set_cell_size
  from .repr import Result, rich_repr
  from .style import Style
label_desc: Use image node_id 12 for calling the Segment obj's underlying member method code with example usage: obj.adjust_line_length(cls, line, length, style, pad) and returns: new_line