export const scheduleTerminalFits = (deps: {
  fit: () => void;
  sendResize: () => void;
  fontsReady: Promise<unknown>;
  loadNerdFont: () => Promise<unknown>;
  raf: (cb: () => void) => void;
  isAborted: () => boolean;
}): void => {
  const refit = () => {
    if (deps.isAborted()) return;
    deps.fit();
    deps.sendResize();
  };

  const initialFit = new Promise<void>((resolve) => {
    deps.raf(() => {
      refit();
      resolve();
    });
  });

  void Promise.all([deps.fontsReady, initialFit])
    .then(refit)
    .catch(() => undefined);
  void Promise.all([deps.loadNerdFont(), initialFit])
    .then(refit)
    .catch(() => undefined);
};
