001/*
002 * JDrupes Builder
003 * Copyright (C) 2026 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.api;
020
021import java.io.PrintWriter;
022import java.io.Writer;
023
024/// An interface to a status line that can be used by [ResourceProvider]s
025/// to indicate progress during the execution of
026/// [ResourceProviderSpi#provide(ResourceRequest)].
027///
028public interface StatusLine extends AutoCloseable {
029
030    /// An implementation that does nothing.
031    StatusLine NOOP_STATUS_LINE = new StatusLine() {
032
033        private final PrintWriter toVoid = new PrintWriter(Writer.nullWriter());
034
035        @Override
036        public void update(String text, Object... args) {
037            // Does nothing
038        }
039
040        @Override
041        public PrintWriter writer(String prefix) {
042            return toVoid;
043        }
044
045        @Override
046        public void close() {
047            // Does nothing
048        }
049    };
050
051    /// Update the text in the status line. If argumnts are given, `text`
052    /// is interpreted as a format string for []String#format] with the
053    /// given arguments.
054    ///
055    /// @param text the text
056    /// @param args the arguments
057    ///
058    void update(String text, Object... args);
059
060    /// Returns a writer to the status line. This writer can be used to
061    /// append text to the status line. Closing the writer will not close
062    /// the status line.
063    /// 
064    /// If a prefix is given, it will be printed at the beginning of the
065    /// status line.
066    ///
067    /// @param prefix the prefix
068    /// @return the prints the writer
069    ///
070    PrintWriter writer(String prefix);
071
072    /// Deallocate the line for outputs from the current thread.
073    ///
074    @Override
075    void close();
076
077}