Skip to content

Commit

Permalink
Implement CLI themes for project messages
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj-hrivnak committed Jul 22, 2024
1 parent 54f2f57 commit dc4b6ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package teksturepako.pakku.api.projects

enum class UpdateStrategy(name: String, val short: String)
enum class UpdateStrategy(serialName: String)
{
LATEST("latest", "^"),
SAME_LATEST("same_latest", "★^"), // TODO: To be implemented
NONE("none", "✖^")
LATEST("latest"),
SAME_LATEST("same_latest"), // TODO: To be implemented
NONE("none")
}
5 changes: 3 additions & 2 deletions src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Ls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class Ls : CliktCommand("List projects")
cell(project.getFlavoredSlug())

val name = if (newProjects != null) runBlocking {
project.getFlavoredUpdateMsg(newProjects.await()) + project.getFlavoredName(nameMaxLengthOpt)
project.getFlavoredUpdateMsg(terminal.theme, newProjects.await()) +
project.getFlavoredName(terminal.theme, nameMaxLengthOpt)
}
else " " + project.getFlavoredName(nameMaxLengthOpt)
else " " + project.getFlavoredName(terminal.theme, nameMaxLengthOpt)

cell(name)

Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/teksturepako/pakku/cli/cmd/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Status: CliktCommand("Get status of your modpack")
{
terminal.println(grid {
currentProjects.filter { updatedProjects containsProject it }.map { project ->
row(project.getFlavoredSlug(), project.getFlavoredName())
row(project.getFlavoredSlug(), project.getFlavoredName(terminal.theme))

val updatedProject = updatedProjects.find { it isAlmostTheSameAs project }
updatedProject?.run {
Expand Down
9 changes: 9 additions & 0 deletions src/commonMain/kotlin/teksturepako/pakku/cli/ui/CliThemes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ object CliThemes
{
val Default: Theme = Theme(Theme.Default) {
strings["pakku.prefix"] = "❯❯❯"
strings["pakku.warning_sign"] = ""

strings["pakku.update_strategy.latest"] = "^"
strings["pakku.update_strategy.same_latest"] = "★^"
strings["pakku.update_strategy.none"] = "✖^"
}

val Ascii: Theme = Theme(this.Default) {
strings["pakku.prefix"] = ">>>"
strings["pakku.warning_sign"] = "!"

strings["pakku.update_strategy.same_latest"] = "*^"
strings["pakku.update_strategy.none"] = "x^"

strings["list.number.separator"] = "."
strings["list.bullet.text"] = "*"
Expand Down
23 changes: 10 additions & 13 deletions src/commonMain/kotlin/teksturepako/pakku/cli/ui/ProjectMsg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package teksturepako.pakku.cli.ui

import com.github.ajalt.mordant.rendering.TextColors.*
import com.github.ajalt.mordant.rendering.TextStyle
import com.github.ajalt.mordant.rendering.Theme
import teksturepako.pakku.api.data.allEqual
import teksturepako.pakku.api.platforms.Multiplatform
import teksturepako.pakku.api.platforms.Platform
import teksturepako.pakku.api.projects.Project
import teksturepako.pakku.api.projects.UpdateStrategy
import teksturepako.pakku.api.projects.containsProject

fun Project.getFlavoredName(maxLength: Int? = null): String?
fun Project.getFlavoredName(theme: Theme, maxLength: Int? = null): String?
{
val name = this.name.values.firstOrNull()?.let {
if (maxLength != null && it.length > maxLength)
Expand All @@ -26,29 +27,25 @@ fun Project.getFlavoredName(maxLength: Int? = null): String?
{
if (this.hasNoFiles())
{
TextStyle(bgColor = white, color = red)("$name")
TextStyle(bgColor = white, color = red)("${theme.string("pakku.warning_sign", "!")}$name")
}
else
{
TextStyle(bgColor = white, color = black)("$name")
TextStyle(bgColor = white, color = black)("${theme.string("pakku.warning_sign", "!")}$name")
}
}
}
}

fun Project.getFlavoredUpdateMsg(updatedProjects: MutableSet<Project>): String = when (this.updateStrategy)
fun Project.getFlavoredUpdateMsg(theme: Theme, updatedProjects: MutableSet<Project>): String = when (this.updateStrategy)
{
UpdateStrategy.LATEST ->
UpdateStrategy.LATEST ->
{
if (updatedProjects containsProject this)
{
blue(this.updateStrategy.short)
}
else brightGreen(this.updateStrategy.short)
val symbol = theme.string("pakku.update_strategy.latest", "^")
if (updatedProjects containsProject this) blue(symbol) else brightGreen(symbol)
}

UpdateStrategy.NONE -> red(this.updateStrategy.short)
else -> cyan(this.updateStrategy.short)
UpdateStrategy.SAME_LATEST -> cyan(theme.string("pakku.update_strategy.same_latest", "*^"))
UpdateStrategy.NONE -> red(theme.string("pakku.update_strategy.none", "x^"))
}

fun Project.getFlavoredSlug(): String
Expand Down

0 comments on commit dc4b6ee

Please sign in to comment.