code: def _display_completions_like_readline(
      app: Application[object], completions: list[Completion]
  ) -> asyncio.Task[None]:
      """
      Display the list of completions in columns above the prompt.
      This will ask for a confirmation if there are too many completions to fit
      on a single page and provide a paginator to walk through them.
      """
      from prompt_toolkit.formatted_text import to_formatted_text
      from prompt_toolkit.shortcuts.prompt import create_confirm_session
  
      # Get terminal dimensions.
      term_size = app.output.get_size()
      term_width = term_size.columns
      term_height = term_size.rows
  
      # Calculate amount of required columns/rows for displaying the
      # completions. (Keep in mind that completions are displayed
      # alphabetically column-wise.)
      max_compl_width = min(
          term_width,
          max(get_cwidth(c.display_text) for c in completions) + 1,
      )
      column_count = max(1, term_width // max_compl_width)
      completions_per_page = column_count * (term_height - 1)
      page_count = int(
          math.ceil(len(completions) / float(completions_per_page))
      )
      # Note: math.ceil can return float on Python2.
  
      def display(page: int) -> None:
          # Display completions.
          page_completions = completions[
              page
              * completions_per_page : (page + 1)
              * completions_per_page
          ]
  
          page_row_count = int(
              math.ceil(len(page_completions) / float(column_count))
          )
          page_columns = [
              page_completions[
                  i * page_row_count : (i + 1) * page_row_count
              ]
              for i in range(column_count)
          ]
  
          result: StyleAndTextTuples = []
  
          for r in range(page_row_count):
              for c in range(column_count):
                  try:
                      completion = page_columns[c][r]
                      style = (
                          "class:readline-like-completions.completion "
                          + (completion.style or "")
                      )
  
                      result.extend(
                          to_formatted_text(
                              completion.display, style=style
                          )
                      )
  
                      # Add padding.
                      padding = max_compl_width - get_cwidth(
                          completion.display_text
                      )
                      result.append((completion.style, " " * padding))
                  except IndexError:
                      pass
              result.append(("", "\n"))
  
          app.print_text(
              to_formatted_text(
                  result, "class:readline-like-completions"
              )
          )
  
      # User interaction through an application generator function.
      async def run_compl() -> None:
          "Coroutine."
          async with in_terminal(render_cli_done=True):
              if len(completions) > completions_per_page:
                  # Ask confirmation if it doesn't fit on the screen.
                  confirm = await create_confirm_session(
                      f"Display all {len(completions)} possibilities?",
                  ).prompt_async()
  
                  if confirm:
                      # Display pages.
                      for page in range(page_count):
                          display(page)
  
                          if page != page_count - 1:
                              # Display --MORE-- and go to the next page.
                              show_more = await _create_more_session(
                                  "--MORE--"
                              ).prompt_async()
  
                              if not show_more:
                                  return
                  else:
                      app.output.flush()
              else:
                  # Display all completions.
                  display(0)
  
      return app.create_background_task(run_compl())
  
file_path: catboost/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/completion.py
imports: from __future__ import annotations
  import asyncio
  import math
  from typing import TYPE_CHECKING
  from prompt_toolkit.application.run_in_terminal import in_terminal
  from prompt_toolkit.completion import CompleteEvent, Completion, get_common_complete_suffix
  from prompt_toolkit.formatted_text import StyleAndTextTuples
  from prompt_toolkit.key_binding.key_bindings import KeyBindings
  from prompt_toolkit.key_binding.key_processor import KeyPressEvent
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.utils import get_cwidth
label_desc: Use image node_id 3 for calling a global function with example usage: _display_completions_like_readline(app, completions) and returns: app