feat: Add repo debug information
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
package moe.nea.firmament.util
|
||||
|
||||
import com.google.common.math.IntMath.pow
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.fileSize
|
||||
import kotlin.io.path.isDirectory
|
||||
import kotlin.io.path.isReadable
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.listDirectoryEntries
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import net.minecraft.text.Text
|
||||
|
||||
object FirmFormatters {
|
||||
fun formatCommas(int: Int, segments: Int = 3): String = formatCommas(int.toLong(), segments)
|
||||
@@ -62,4 +70,33 @@ object FirmFormatters {
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun debugPath(path: Path): Text {
|
||||
if (!path.exists()) {
|
||||
return tr("firmament.path.missing", "$path (missing)").red()
|
||||
}
|
||||
if (!path.isReadable()) {
|
||||
return tr("firmament.path.unreadable", "$path (unreadable)").red()
|
||||
}
|
||||
if (path.isRegularFile()) {
|
||||
return tr("firmament.path.regular",
|
||||
"$path (exists ${formatFileSize(path.fileSize())})").lime()
|
||||
}
|
||||
if (path.isDirectory()) {
|
||||
return tr("firmament.path.directory", "$path (${path.listDirectoryEntries().size} entries)").darkGreen()
|
||||
}
|
||||
return tr("firmament.path.unknown", "$path (unknown)").purple()
|
||||
}
|
||||
|
||||
fun formatFileSize(fileSizeInBytes: Long): String {
|
||||
return "${fileSizeInBytes / 1024} KiB"
|
||||
}
|
||||
|
||||
fun formatBool(
|
||||
boolean: Boolean,
|
||||
trueIsGood: Boolean = true,
|
||||
): Text {
|
||||
val text = Text.literal(boolean.toString())
|
||||
return if (boolean == trueIsGood) text.lime() else text.red()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ fun MutableText.blue() = withColor(Formatting.BLUE)
|
||||
fun MutableText.aqua() = withColor(Formatting.AQUA)
|
||||
fun MutableText.lime() = withColor(Formatting.GREEN)
|
||||
fun MutableText.darkGreen() = withColor(Formatting.DARK_GREEN)
|
||||
fun MutableText.purple() = withColor(Formatting.DARK_PURPLE)
|
||||
fun MutableText.pink() = withColor(Formatting.LIGHT_PURPLE)
|
||||
fun MutableText.yellow() = withColor(Formatting.YELLOW)
|
||||
fun MutableText.grey() = withColor(Formatting.GRAY)
|
||||
fun MutableText.red() = withColor(Formatting.RED)
|
||||
@@ -165,6 +167,6 @@ fun Text.transformEachRecursively(function: (Text) -> Text): Text {
|
||||
}
|
||||
}
|
||||
|
||||
fun tr(key: String, default: String): Text = error("Compiler plugin did not run.")
|
||||
fun trResolved(key: String, vararg args: Any) = Text.translatable(key, *args)
|
||||
fun tr(key: String, default: String): MutableText = error("Compiler plugin did not run.")
|
||||
fun trResolved(key: String, vararg args: Any): MutableText = Text.stringifiedTranslatable(key, *args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user