monke flip. (ditched exitProcess, now we using fucking callbacks)

This commit is contained in:
2026-03-20 21:11:53 +03:00
parent 60ca2d38f9
commit b69c6cd0dc
7 changed files with 24 additions and 23 deletions
+8 -14
View File
@@ -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("Текст Скриптонита пустой или не найден.")
+5 -7
View File
@@ -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()
}
}
+1
View File
@@ -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() }