aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/FirmFormatters.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-18 15:59:40 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-18 17:31:39 +0100
commit68948baff37e139a2a3f88ce3b233effb55955c4 (patch)
treea7dd3128491475ede150d269df128dd7ee19a431 /src/main/kotlin/util/FirmFormatters.kt
parentfba91100cb57b4359f235bfcca352c052ec0eefb (diff)
downloadFirmament-68948baff37e139a2a3f88ce3b233effb55955c4.tar.gz
Firmament-68948baff37e139a2a3f88ce3b233effb55955c4.tar.bz2
Firmament-68948baff37e139a2a3f88ce3b233effb55955c4.zip
feat: Add repo debug information
Diffstat (limited to 'src/main/kotlin/util/FirmFormatters.kt')
-rw-r--r--src/main/kotlin/util/FirmFormatters.kt37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/kotlin/util/FirmFormatters.kt b/src/main/kotlin/util/FirmFormatters.kt
index 61644db..92fb9e5 100644
--- a/src/main/kotlin/util/FirmFormatters.kt
+++ b/src/main/kotlin/util/FirmFormatters.kt
@@ -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()
+ }
+
}