@NotNull
  private TerminalArrangementState calcArrangementState(@NotNull ToolWindow terminalToolWindow) {
    TerminalArrangementState arrangementState = new TerminalArrangementState();
    ContentManager contentManager = terminalToolWindow.getContentManager();
    for (Content content : contentManager.getContents()) {
      AbstractTerminalRunner<?> runner = TerminalToolWindowManager.getRunnerByContent(content);
      if (runner == null || !runner.isTerminalSessionPersistent()) {
        continue;
      }
      TerminalWidget terminalWidget = TerminalToolWindowManager.findWidgetByContent(content);
      if (terminalWidget == null) continue;
      TerminalTabState tabState = new TerminalTabState();
      tabState.myTabName = content.getTabName();
      tabState.myShellCommand = terminalWidget.getShellCommand();
      tabState.myIsUserDefinedTabTitle = tabState.myTabName.equals(terminalWidget.getTerminalTitle().getUserDefinedTitle());
      tabState.myWorkingDirectory = myWorkingDirectoryManager.getWorkingDirectory(content);
      JBTerminalWidget jbTerminalWidget = JBTerminalWidget.asJediTermWidget(terminalWidget);
      ShellTerminalWidget shellTerminalWidget = ObjectUtils.tryCast(jbTerminalWidget, ShellTerminalWidget.class);
      tabState.myCommandHistoryFileName = TerminalCommandHistoryManager.getFilename(
        shellTerminalWidget != null ? shellTerminalWidget.getCommandHistoryFilePath() : null
      );
      arrangementState.myTabStates.add(tabState);
    }
    Content selectedContent = contentManager.getSelectedContent();
    arrangementState.mySelectedTabIndex = selectedContent == null ? -1 : contentManager.getIndexOfContent(selectedContent);
    return arrangementState;
  }
@NotNull
  private TerminalArrangementState calcArrangementState(@NotNull ToolWindow terminalToolWindow)