class AbstractTerminal implements Terminal {

    private final List<TerminalResizeListener> resizeListeners;
    private TerminalSize lastKnownSize;

    protected AbstractTerminal() {
        this.resizeListeners = new ArrayList<>();
        this.lastKnownSize = null;
    }

    @Override
    public void addResizeListener(TerminalResizeListener listener) {
        if (listener != null) {
            resizeListeners.add(listener);
        }
    }

    @Override
    public void removeResizeListener(TerminalResizeListener listener) {
        if (listener != null) {
            resizeListeners.remove(listener);
        }
    }

    /**
     * Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It
     * will trigger all resize listeners, but only if the size has changed from before.
     *
     * @param columns Number of columns in the new size
     * @param rows Number of rows in the new size
     */
    protected synchronized void onResized(int columns, int rows) {
        onResized(new TerminalSize(columns, rows));
    }

    /**
     * Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It
     * will trigger all resize listeners, but only if the size has changed from before.
     *
     * @param newSize Last discovered terminal size
     */
    protected synchronized void onResized(TerminalSize newSize) {<FILL_FUNCTION_BODY>}

    @Override
    public TextGraphics newTextGraphics() throws IOException {
        return new TerminalTextGraphics(this);
    }
}

        if (lastKnownSize == null || !lastKnownSize.equals(newSize)) {
            lastKnownSize = newSize;
            for (TerminalResizeListener resizeListener : resizeListeners) {
                resizeListener.onResized(this, lastKnownSize);
            }
        }
    
<no_super_class>