code: def _get_terminal(given_terminal: Optional[Text]):
      """Returns the terminal for local launch based on X & command availability.
  
      By order of priority it will:
      - use the provided `given_terminal`
      - default to the shell environment variable `LAUNCHPAD_LAUNCH_LOCAL_TERMINAL`
        if set
      - or select the first supported option in: Gnome, Tmux, Xterm and current
        terminal.
  
      Args:
        given_terminal: The terminal identifier to use or `None`.
  
      Returns:
        One of the legal terminal modes (a string in SEPARATE_TERMINAL_MODES) based
        on the priority described above.
      """
      if (
          given_terminal is not None
          and given_terminal not in SEPARATE_TERMINAL_MODES
      ):
          raise ValueError(
              "`terminal` got a mode that it does not "
              "understand %r. Please choose from %r."
              % (given_terminal, SEPARATE_TERMINAL_MODES)
          )
      terminal = given_terminal or os.environ.get(
          "LAUNCHPAD_LAUNCH_LOCAL_TERMINAL", None
      )
      # Set terminal to None, if the chosen terminal cannot be used because we are
      # running without X.
      if not feature_testing.has_x() and terminal in TERMINALS_FOR_X:
          logging.info(
              "Not using %s to launch, since DISPLAY is not set.",
              terminal,
          )
          terminal = None
  
      if terminal is None:
          if feature_testing.has_gnome_terminal():
              terminal = SEPARATE_TERMINAL_GNOME_TERMINAL_WINDOWS
          elif feature_testing.has_tmux():
              terminal = SEPARATE_TERMINAL_TMUX_SESSION
          elif feature_testing.has_xterm():
              terminal = SEPARATE_TERMINAL_XTERM
  
          # Examine the type of terminal and explain why it is chosen.
          if terminal is None:
              logging.info(
                  "Launching in the same console since we cannot find "
                  "gnome-terminal, tmux, or xterm."
              )
              terminal = SEPARATE_TERMINAL_CURRENT_TERMINAL
          else:
              logging.info(
                  "Launching with %s because the `terminal` launch option "
                  "is not explicitly specified. To remember your preference "
                  "(assuming tmux_session is the preferred option), either: \n"
                  "1. Pass the `terminal` launch option (e.g., "
                  '`lp.launch(program, terminal="tmux_session")`).\n'
                  "2. Set the following in your bashrc to remember your "
                  "preference:\n"
                  "    export LAUNCHPAD_LAUNCH_LOCAL_TERMINAL=tmux_session",
                  terminal,
              )
      return terminal
  
file_path: launchpad/launchpad/launch/run_locally/run_locally.py
imports: import collections
  import os
  from typing import Optional, Sequence, Text, Union
  from absl import logging
  from launchpad.launch import worker_manager
  from launchpad.launch import worker_manager_v2
  from launchpad.launch.run_locally import feature_testing
  from launchpad.launch.run_locally import launch_local_current_terminal
  from launchpad.launch.run_locally import launch_local_gnome
  from launchpad.launch.run_locally import launch_local_output_to_files
  from launchpad.launch.run_locally import launch_local_tmux
  from launchpad.launch.run_locally import launch_local_xterm
label_desc: Use image node_id 1 for calling a global function with example usage: _get_terminal(given_terminal) and returns: terminal