Files
ratatoskr-go/internal/ui/commands.go
ki.sagidullin ef812bb3d7
Some checks failed
CI / test (push) Failing after 1m14s
CI / build-and-package (amd64, linux) (push) Failing after 59s
CI / build-and-package (amd64, windows) (push) Successful in 30s
feat(ui): кнопка «Перезапустить» — полный аналог /retry N
2026-08-22 00:32:06 +05:00

53 lines
2.2 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 ui
import "fmt"
// Commands — отображение действий UI в текстовые команды канала.
//
// UI — это chat.Channel, поэтому все действия пользователя (кнопки, ввод)
// превращаются в текстовые сообщения, которые уходят в Router → Core. Это
// сохраняет единый путь команд (спец 12.2): никаких прямых вызовов Core из
// виджетов — только текст через канал.
type Commands struct {
// Submit отправляет текст пользователя в канал (обычно — window.Submit).
Submit func(text string)
}
// NewCommands создаёт Commands с отправкой через fn.
func NewCommands(fn func(text string)) *Commands {
if fn == nil {
fn = func(string) {}
}
return &Commands{Submit: fn}
}
// Start — новая задача (/start).
func (c *Commands) Start() { c.Submit("/start") }
// Cancel — отмена текущей задачи (/cancel).
func (c *Commands) Cancel() { c.Submit("/cancel") }
// Skip — пропустить сбор, сформировать черновик (/skip).
func (c *Commands) Skip() { c.Submit("/skip") }
// Retry — перезапустить задачу N (/retry N): полный аналог Telegram-команды.
// id <= 0 — no-op (кнопка «Перезапустить» на свободной вкладке неактивна).
func (c *Commands) Retry(id int64) {
if id <= 0 {
return
}
c.Submit(fmt.Sprintf("/retry %d", id))
}
// Status — запросить статус задачи N (/status N).
func (c *Commands) Status(id int64) { c.Submit(fmt.Sprintf("/status %d", id)) }
// Continue — продолжить задачу N (/continue N).
func (c *Commands) Continue(id int64) { c.Submit(fmt.Sprintf("/continue %d", id)) }
// Approve — одобрить черновик («создавай»).
func (c *Commands) Approve() { c.Submit("создавай") }
// SendText — обычное сообщение пользователя (ввод в поле).
func (c *Commands) SendText(text string) { c.Submit(text) }