All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.danilopianini.plagiarismdetector.output.StandardOutput.kt Maven / Gradle / Ivy

There is a newer version: 9.0.6
Show newest version
package org.danilopianini.plagiarismdetector.output

import me.tongfei.progressbar.ProgressBar
import me.tongfei.progressbar.ProgressBarBuilder
import me.tongfei.progressbar.ProgressBarStyle
import kotlin.time.ExperimentalTime
import kotlin.time.TimeMark
import kotlin.time.TimeSource

/**
 * A standard [Output] bound to the command line.
 */
@OptIn(ExperimentalTime::class)
class StandardOutput : Output {

    private lateinit var progressBar: ProgressBar
    private var start: TimeMark = TimeSource.Monotonic.markNow()

    override fun startComparison(submissionName: String, totalComparisons: Int) {
        progressBar = ProgressBarBuilder()
            .setTaskName(submissionName)
            .setStyle(ProgressBarStyle.COLORFUL_UNICODE_BLOCK)
            .setInitialMax(totalComparisons.toLong())
            .continuousUpdate()
            .hideEta()
            .clearDisplayOnFinish()
            .build()
        start = TimeSource.Monotonic.markNow()
    }

    override fun tick() {
        progressBar.step()
    }

    override fun endComparison() {
        progressBar.close()
        logInfo("Total elapsed time: ${start.elapsedNow().inWholeSeconds}s")
    }

    override fun logInfo(message: String) = println(message)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy