rubric/catalog/softbook.go
2026-07-27 16:45:21 +03:00

99 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package catalog
import (
"bufio"
"fmt"
"rubric/modules/softmodules"
"rubric/utils"
"strconv"
"strings"
)
var SoftBook = Book{
Key: "soft",
Aliases: []string{"sw", "software"},
Title: "Справочник по софту",
Description: "Обзоры используемого софта: Zola, Forgejo и другое",
Run: runSoftBook,
}
func runSoftBook(scanner *bufio.Scanner) {
for {
showSoftMenu()
input, ok := ReadLine(scanner)
if !ok {
return
}
if input == "" {
continue
}
if IsQuit(input) {
fmt.Printf("\n %s%sДо свидания!%s\n\n",
utils.ColorBold, utils.ColorCyan, utils.ColorReset)
return
}
if IsBack(input) {
return
}
if n, err := strconv.Atoi(input); err == nil {
if n >= 1 && n <= len(softmodules.All) {
softmodules.All[n-1].Run()
if softWaitBack(scanner) {
return
}
continue
}
fmt.Printf("\n %s%sНомер %d вне диапазона (1%d)%s\n",
utils.ColorBold, utils.ColorRed, n, len(softmodules.All), utils.ColorReset)
continue
}
if m, ok := softmodules.Find(input); ok {
m.Run()
if softWaitBack(scanner) {
return
}
continue
}
fmt.Printf("\n %s%sНе понял '%s'. Номер, ключ раздела, b — назад.%s\n",
utils.ColorBold, utils.ColorRed, input, utils.ColorReset)
}
}
// softWaitBack возвращает true если пользователь нажал b (выйти в главное меню)
func softWaitBack(scanner *bufio.Scanner) bool {
fmt.Printf("\n %s%s[Enter — назад в меню Soft, b — главное меню]%s ",
utils.ColorDim, utils.ColorCyan, utils.ColorReset)
if scanner.Scan() {
return IsBack(strings.TrimSpace(scanner.Text()))
}
return false
}
func showSoftMenu() {
utils.Header("Справочник Soft")
fmt.Printf(" %s%sРазделы:%s\n\n", utils.ColorBold, utils.ColorWhite, utils.ColorReset)
for i, m := range softmodules.All {
aliases := ""
if len(m.Aliases) > 0 {
aliases = fmt.Sprintf("%s [%s]%s",
utils.ColorDim, strings.Join(m.Aliases, ", "), utils.ColorReset)
}
fmt.Printf(" %s%s %2d.%s %s%-10s%s %s%-32s%s%s\n",
utils.ColorBold, utils.ColorCyan, i+1, utils.ColorReset,
utils.ColorYellow+utils.ColorBold, m.Key, utils.ColorReset,
utils.ColorWhite, m.Title, utils.ColorReset,
aliases,
)
fmt.Printf(" %s%s%s\n\n",
utils.ColorDim, m.Description, utils.ColorReset)
}
fmt.Printf(" %s%sРаздел (номер / ключ / b — главное меню / q — выход):%s ",
utils.ColorBold, utils.ColorGreen, utils.ColorReset)
}