def window_logic(state, old_state):
    """
    Window create/resize logic. The function name is not very good :(

      new_state  |   old_state   | same directions | same size |  action
    -------------|---------------|-----------------|-----------|-----------
      vertical   |    vertical   |      True       |   True    |  reuse
      vertical   |    vertical   |      True       |   False   |  resize
      vertical   |    vertical   |      False      |   True    |  close old; create
      vertical   |    vertical   |      False      |   False   |  close old; create
      vertical   |   horizontal  |      True       |   True    |  close old; create
      vertical   |   horizontal  |      True       |   False   |  close old; create
      vertical   |   horizontal  |      False      |   True    |  close old; create
      vertical   |   horizontal  |      False      |   False   |  close old; create
     horizontal  |    vertical   |      True       |   True    |  close old; create
     horizontal  |    vertical   |      True       |   False   |  close old; create
     horizontal  |    vertical   |      False      |   True    |  close old; create
     horizontal  |    vertical   |      False      |   False   |  close old; create
     horizontal  |   horizontal  |      True       |   True    |  reuse
     horizontal  |   horizontal  |      True       |   False   |  resize
     horizontal  |   horizontal  |      False      |   True    |  close old; create
     horizontal  |   horizontal  |      False      |   False   |  close old; create
    """
    old_window = vimh.window_with_buffer(old_state.buff) if old_state else None

    if not old_state or not old_window:
        window = make_pyunite_window(state, autocmd=True)

    elif ((state.options['vsplit'], state.options['direction']) ==
          (old_state.options['vsplit'], old_state.options['direction'])):
        ui.change_window(old_window, autocmd=True)
        ui.resize_window(state.options['size'] or old_state.options['size'], vsplit=state.options['vsplit'])
        window = old_window

    else:
        ui.change_window(old_window)
        # If bufhidden=wipe, buffer will dissapear when we close its window
        with ui.restore(vim.current.window), misc.scoped(state.buff.options, bufhidden='hide'):
            ui.quit_window()
        window = make_pyunite_window(state, autocmd=True)

    state.options['size'] = window.width if state.options['vsplit'] else window.height
    return window
dataset/ETHPy150Open azure-satellite/pyunite/pyunite/core.py/window_logic/original