From b3e3c7ba1ed2871d11ada77c0a95a9522345b516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D1=80=D0=B8=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D0=A1?= =?UTF-8?q?=D0=B0=D1=84=D1=80=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sat, 19 Sep 2026 22:28:11 +0000 Subject: [PATCH] Delete internal/repl/history.go --- internal/repl/history.go | 106 --------------------------------------- 1 file changed, 106 deletions(-) delete mode 100644 internal/repl/history.go diff --git a/internal/repl/history.go b/internal/repl/history.go deleted file mode 100644 index 275a1e7..0000000 --- a/internal/repl/history.go +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2026 Safronov Grigorii - * - * Licensed under the CDDL, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * https://opensource.org/licenses/CDDL-1.0 - */ - -// Файл: internal/repl/history.go -// Назначение: Управление историей команд REPL - -package repl - -import ( - "bufio" - "os" - "path/filepath" -) - -// History управляет историей команд -type History struct { - entries []string - maxSize int - filePath string -} - -// NewHistory создаёт новый объект истории -func NewHistory(maxSize int) *History { - homeDir, _ := os.UserHomeDir() - filePath := filepath.Join(homeDir, ".futriis_history") - - return &History{ - entries: make([]string, 0, maxSize), - maxSize: maxSize, - filePath: filePath, - } -} - -// Add добавляет команду в историю -func (h *History) Add(cmd string) error { - // Не добавляем дубликаты подряд - if len(h.entries) > 0 && h.entries[len(h.entries)-1] == cmd { - return nil - } - - h.entries = append(h.entries, cmd) - - // Ограничиваем размер истории - if len(h.entries) > h.maxSize { - h.entries = h.entries[len(h.entries)-h.maxSize:] - } - - return nil -} - -// Load загружает историю из файла -func (h *History) Load() error { - file, err := os.Open(h.filePath) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - defer file.Close() - - scanner := bufio.NewScanner(file) - for scanner.Scan() { - cmd := scanner.Text() - if cmd != "" { - h.entries = append(h.entries, cmd) - } - } - - // Ограничиваем размер - if len(h.entries) > h.maxSize { - h.entries = h.entries[len(h.entries)-h.maxSize:] - } - - return scanner.Err() -} - -// Save сохраняет историю в файл -func (h *History) Save() error { - file, err := os.Create(h.filePath) - if err != nil { - return err - } - defer file.Close() - - writer := bufio.NewWriter(file) - for _, cmd := range h.entries { - if _, err := writer.WriteString(cmd + "\n"); err != nil { - return err - } - } - - return writer.Flush() -} - -// GetEntries возвращает все записи истории -func (h *History) GetEntries() []string { - return h.entries -}