monke flip. (ditched exitProcess, now we using fucking callbacks)
This commit is contained in:
Generated
+6
@@ -1,10 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="2.1.20" />
|
||||
<option name="version" value="2.0.21" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+3
@@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
|
||||
+8
-14
@@ -48,23 +48,18 @@ fun main(args: Array<String>) {
|
||||
* @param invoker инвокер команд
|
||||
*/
|
||||
fun runRepl(inputManager: InputManager, invoker: CommandInvoker) {
|
||||
var isRunning: Boolean = true
|
||||
var isRunning = true
|
||||
|
||||
// exitProcess мне нравился больше
|
||||
invoker.register(ExitCommand { isRunning = false })
|
||||
|
||||
while (isRunning) {
|
||||
|
||||
|
||||
val line = inputManager.readLine()
|
||||
|
||||
// EOF — завершаем без сохранения
|
||||
if (line == null) {
|
||||
println("\nНу ладно.")
|
||||
isRunning = false
|
||||
continue
|
||||
}
|
||||
|
||||
val line = inputManager.readLine() ?: break
|
||||
if (line.isBlank()) continue
|
||||
|
||||
invoker.execute(line)
|
||||
}
|
||||
|
||||
println("\nНу ладно.")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +88,6 @@ fun registerCommands(
|
||||
ClearCommand(manager),
|
||||
SaveCommand(manager, fileManager),
|
||||
ExecuteScriptCommand(invoker),
|
||||
ExitCommand(),
|
||||
AddIfMaxCommand(manager, inputManager),
|
||||
AddIfMinCommand(manager, inputManager),
|
||||
HistoryCommand(invoker),
|
||||
|
||||
@@ -28,7 +28,6 @@ class ExecuteScriptCommand(private val invoker: CommandInvoker) : Command {
|
||||
println("Чтение скрипта '$filePath'...")
|
||||
val queue = CommandQueue()
|
||||
queue.loadFromScript(filePath)
|
||||
println("Команды в очереди: ${queue.peek()}") // временно
|
||||
|
||||
if (queue.isEmpty()) {
|
||||
println("Текст Скриптонита пустой или не найден.")
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package commands
|
||||
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Завершает программу без сохранения.
|
||||
* Завершает программу без сохранения. Теперь это Callback
|
||||
*/
|
||||
class ExitCommand : Command {
|
||||
class ExitCommand(private val onExit: () -> Unit) : Command {
|
||||
override val name = "exit"
|
||||
override val description = "завершить программу (без сохранения)"
|
||||
override val description = "завершить программу"
|
||||
|
||||
override fun execute(args: List<String>) {
|
||||
println("Завершение работы.")
|
||||
exitProcess(0) //nizya
|
||||
println("До свидания!")
|
||||
onExit()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ class CommandQueue {
|
||||
|
||||
visitedScripts.add(filePath)
|
||||
|
||||
// Лениво читаю файл, пока Сканер не вернет null, т.е. файл закончится
|
||||
Scanner(file, Charsets.UTF_8).use { scanner ->
|
||||
generateSequence { if (scanner.hasNextLine()) scanner.nextLine() else null }
|
||||
.map { it.trim() }
|
||||
|
||||
Reference in New Issue
Block a user