Skip to content

Commit ac548e1

Browse files
Indicate if current location is in the project folder #111
1 parent b2dbf58 commit ac548e1

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/kotlin/com/haulmont/cuba/cli/ShellCli.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import com.beust.jcommander.MissingCommandException
2020
import com.beust.jcommander.ParameterException
2121
import com.google.common.eventbus.EventBus
2222
import com.haulmont.cuba.cli.commands.*
23+
import com.haulmont.cuba.cli.cubaplugin.model.ProjectModel
24+
import com.haulmont.cuba.cli.cubaplugin.model.ProjectStructure
2325
import com.haulmont.cuba.cli.event.AfterCommandExecutionEvent
2426
import com.haulmont.cuba.cli.event.BeforeCommandExecutionEvent
2527
import com.haulmont.cuba.cli.event.ErrorEvent
28+
import org.fusesource.jansi.Ansi
2629
import org.jline.builtins.Completers
2730
import org.jline.builtins.Completers.TreeCompleter.Node
2831
import org.jline.builtins.Completers.TreeCompleter.node
@@ -82,7 +85,7 @@ class ShellCli(private val commandsRegistry: CommandsRegistry) : Cli {
8285

8386
(lineReader as? LineReaderImpl)?.completer = createCommandsCompleter(commandsRegistry)
8487

85-
val line = lineReader.readLine(PROMPT).also {
88+
val line = lineReader.readLine(buildPrompt()).also {
8689
it != null || return
8790
}.takeIf {
8891
it.isNotBlank()
@@ -117,6 +120,15 @@ class ShellCli(private val commandsRegistry: CommandsRegistry) : Cli {
117120
}
118121
}
119122

123+
private fun buildPrompt(): String = try {
124+
val projectNameGreen = Ansi.ansi()
125+
.fgGreen().render(ProjectModel(ProjectStructure()).name).fgDefault()
126+
.toString()
127+
"($projectNameGreen) $PROMPT"
128+
} catch (e: Exception) {
129+
PROMPT
130+
}
131+
120132
private fun evalCommand(command: CliCommand) {
121133
bus.post(BeforeCommandExecutionEvent(command))
122134
try {

0 commit comments

Comments
 (0)