diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml new file mode 100644 index 00000000..8a009bb8 --- /dev/null +++ b/.idea/caches/deviceStreaming.xml @@ -0,0 +1,1842 @@ + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 00000000..104c42f5 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 00000000..c61ea334 --- /dev/null +++ b/.idea/markdown.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 9c8e7400..7ff9e338 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index aade54c5..b836d194 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,9 @@ + +val archives = mutableListOf() + fun main(args: Array) { - println("Hello World!") -} \ No newline at end of file + archiveMenu() +} + + + diff --git a/src/main/kotlin/dataModels.kt b/src/main/kotlin/dataModels.kt new file mode 100644 index 00000000..be33ce25 --- /dev/null +++ b/src/main/kotlin/dataModels.kt @@ -0,0 +1,2 @@ +data class Note(val title: String, val text: String) +data class Archive (val name: String, val notes: MutableList = mutableListOf()) \ No newline at end of file diff --git a/src/main/kotlin/menuAndArchive.kt b/src/main/kotlin/menuAndArchive.kt new file mode 100644 index 00000000..b607b7c1 --- /dev/null +++ b/src/main/kotlin/menuAndArchive.kt @@ -0,0 +1,66 @@ +fun archiveMenu() { + while (true) { + println("\nСписок архивов:") + println("0. Создать архив") + archives.forEachIndexed { i, archive -> + println("${i + 1}. ${archive.name}") + } + println("${archives.size + 1}. Выход") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createArchive() + input != null && input in 1..archives.size -> noteMenu(archives[input - 1]) + input == archives.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} + +fun createArchive() { + println("Введите название архива:") + val name = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Название не может быть пустым") + return + } + archives.add(Archive(name)) + println("Архив '$name' создан") +} +fun createNote(archive: Archive) { + println("Введите заголовок заметки:") + val title = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Заголовок не может быть пустым") + return + } + println("Введите текст заметки:") + val text = readlnOrNull()?.takeIf { it.isNotBlank() } ?: run { + println("Текст не может быть пустым") + return + } + archive.notes.add(Note(title, text)) + println("Заметка '$title' добавлена") +} +fun noteMenu(archive: Archive) { + while (true) { + println("\nАрхив: ${archive.name}") + println("0. Создать заметку") + archive.notes.forEachIndexed { i, note -> + println("${i + 1}. ${note.title}") + } + println("${archive.notes.size + 1}. Назад") + + val input = readlnOrNull()?.toIntOrNull() + when { + input == 0 -> createNote(archive) + input != null && input in 1..archive.notes.size -> showNote(archive.notes[input - 1]) + input == archive.notes.size + 1 -> return + else -> println("Некорректный ввод") + } + } +} +fun showNote(note: Note) { + println("\n=== ${note.title} ===") + println(note.text) + println("\nНажмите Enter для возврата") + readlnOrNull() +} \ No newline at end of file