Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

### Changed

- Load chat names directly in the backup chat selector, with streamed results,
account-scoped caching, stop/reload controls, and manual chat entry.
- Show Since and Until date/time filters in the main backup forms.
- Label TUI export formats as JSON, HTML, and Both to match the CLI options.
- Simplify TUI forms with task-specific settings, wide text editors, direct
typing and paste, Tab navigation, visible choice controls and inline errors.
- Place editable values and compact, scrollable selectors beside their argument
labels, with independent wheel scrolling and preserved multi-selections.
- Keep selected multi-select names visible, distinguish checkboxes from single
choices, and provide a selected-only view and Add-item editor for custom lists.
- Support the full multi-select flow with mouse clicks, keep scrolled checkboxes
in place, avoid skipping options in small lists, and add a clickable Add action.
- Use Enter to toggle highlighted multi-select items and Left Arrow to accept
the choices and close the list, including chat category selection.
- Render backup measurements with animated Bubbles progress bars and skip
reprocessing unchanged task output while waiting for worker updates.
- Require Go 1.26 or newer for the Bubble Tea v2 terminal interface.
- Open the interactive workspace when `ta` runs without arguments in a terminal;
piped invocations and `ta --help` continue to display command help.
Expand All @@ -13,6 +29,15 @@

### Added

- Calendar pickers for Since and Until, with mouse selection, month navigation,
Today and Clear controls, and manual timestamp entry.
- File and folder choosers for TUI path fields, with native macOS Open/Save
dialogs, multiple-file selection, and a terminal browser for remote sessions
and systems without a graphical chooser. Manual path entry stays available.
- Searchable TUI dropdowns and inline multi-select lists for saved accounts, media, chat
categories and account sections. Check multiple chats or accounts in browser
results. Multi-account backups run as a queue with isolated output folders,
per-account progress and retained results, including failures and cancellation.
- `ta tui`: a responsive Bubble Tea workspace covering public commands and their
options, including installed extensions. Includes quick-start presets,
command and option search, common/advanced forms, inline validation, command
Expand Down
13 changes: 10 additions & 3 deletions cmd/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func newBackupProgress(output io.Writer) *backupProgress {
width = columns
}
}
lines := p.lines(time.Now(), width)
lines, status := p.frame(time.Now(), width)
if terminal && os.Getenv("TA_TUI_CHILD") == "1" {
taskui.WriteProgress(output, lines)
taskui.WriteStatus(output, status)
return
}
if terminal {
Expand Down Expand Up @@ -175,6 +175,11 @@ func (p *backupProgress) finish(err error) {
}

func (p *backupProgress) lines(now time.Time, width int) []string {
lines, _ := p.frame(now, width)
return lines
}

func (p *backupProgress) frame(now time.Time, width int) ([]string, taskui.Progress) {
p.mu.Lock()
defer p.mu.Unlock()
paint := func(color text.Color, value string) string {
Expand Down Expand Up @@ -275,7 +280,9 @@ func (p *backupProgress) lines(now time.Time, width int) []string {
paint(labelColor, runewidth.Truncate(label, limit, "…")),
text.Snip(bar, limit, "…"),
text.Snip(metrics, limit, "…"),
}
}, taskui.Progress{Label: label, Detail: size, Summary: metrics,
Percent: percent / 100, Determinate: p.plan.Ready || p.finished,
CompletedFiles: p.completeFiles, TotalFiles: p.plan.Files}
}

func formatProgressBytes(bytes int64) string {
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New() *cobra.Command {
}
root.PersistentFlags().Lookup("ns").Usage = "saved Telegram login; concurrent terminals need separate namespaces (the same account is supported); list with ta accounts"
root.AddCommand(NewArchive(), NewStats(), NewRender(), NewSchedule(), NewAccount(), NewSync(), NewCron(), NewAccounts(), NewVersion(), newSessionRecover(), NewTUI())
annotateTUIChoices(root)
viper.SetEnvPrefix("TA")
bindProductEnvironment(root)
brandCommands(root)
Expand Down
30 changes: 29 additions & 1 deletion cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package cmd

import (
"context"
"encoding/csv"
"fmt"
"maps"
"os"
"strings"

tea "charm.land/bubbletea/v2"
"github.com/mo1ein/TelegramArchive/consts"
"github.com/mo1ein/TelegramArchive/internal/tui"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -33,7 +37,31 @@ func runTUI(cmd *cobra.Command, _ []string) error {
root.InitDefaultCompletionCmd()
taskCtx, cancel := context.WithCancel(cmd.Context())
defer cancel()
model := tui.New(tui.Catalog(root), inheritedArguments(cmd), viper.GetString("ns"), taskCtx)
storage := maps.Clone(viper.GetStringMapString("storage"))
if _, configured := productSetting("STORAGE"); !configured && !cmd.Flags().Changed("storage") {
storage = defaultProductStorage(consts.HomeDir)
}
model := tui.New(tui.Catalog(root), inheritedArguments(cmd), viper.GetString("ns"), taskCtx,
tui.WithAccountLoader(func(ctx context.Context, override string) ([]string, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
options := maps.Clone(storage)
if override != "" {
values, err := csv.NewReader(strings.NewReader(override)).Read()
if err != nil {
return nil, err
}
for _, value := range values {
key, setting, ok := strings.Cut(value, "=")
if !ok {
return nil, fmt.Errorf("storage settings need key=value pairs")
}
options[key] = setting
}
}
return tuiSavedAccounts(options)
}))
_, err := tea.NewProgram(model, tea.WithContext(cmd.Context()), tea.WithInput(cmd.InOrStdin()), tea.WithOutput(cmd.OutOrStdout())).Run()
return err
}
Expand Down
97 changes: 97 additions & 0 deletions cmd/tui_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cmd

import (
"encoding/json"
"fmt"
"io"
"os"
"slices"
"strings"
"time"

"github.com/mo1ein/TelegramArchive/internal/archive"
transport "github.com/mo1ein/TelegramArchive/internal/telegram"
"github.com/spf13/cobra"
"go.etcd.io/bbolt"
)

func annotateTUIChoices(root *cobra.Command) {
options := map[string][]string{
"media": append([]string{"all", "none"}, archive.MediaKinds...),
"types": transport.ChatTypes,
"include": append([]string{"all"}, transport.AccountKinds...),
"account-include": append([]string{"all"}, transport.AccountKinds...),
}
for _, path := range []string{"archive", "account", "sync", "cron add"} {
command, _, err := root.Find(strings.Fields(path))
if err != nil {
continue
}
for name, values := range options {
if flag := command.Flags().Lookup(name); flag != nil {
if flag.Annotations == nil {
flag.Annotations = map[string][]string{}
}
flag.Annotations["ta:choices"] = slices.Clone(values)
}
}
}
}

// Discover names locally without authorizing a Telegram connection or opening
// any per-account session. Legacy databases are opened read-only and briefly.
func tuiSavedAccounts(options map[string]string) ([]string, error) {
path := options["path"]
if path == "" {
return nil, fmt.Errorf("session storage has no path")
}
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, err
}
var names []string
switch options["type"] {
case "bolt":
entries, err := os.ReadDir(path)
if err != nil {
return nil, err
}
for _, entry := range entries {
if entry.Type().IsRegular() && !strings.HasPrefix(entry.Name(), ".") {
names = append(names, entry.Name())
}
}
case "file":
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var values map[string]json.RawMessage
if err := json.NewDecoder(io.LimitReader(file, 32<<20)).Decode(&values); err != nil {
return nil, fmt.Errorf("read saved account names: %w", err)
}
for name := range values {
names = append(names, name)
}
case "legacy":
db, err := bbolt.Open(path, 0600, &bbolt.Options{ReadOnly: true, Timeout: 150 * time.Millisecond})
if err != nil {
return nil, fmt.Errorf("read saved account names: %w", err)
}
defer db.Close()
if err := db.View(func(tx *bbolt.Tx) error {
return tx.ForEach(func(name []byte, _ *bbolt.Bucket) error {
names = append(names, string(name))
return nil
})
}); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported session storage %q", options["type"])
}
slices.Sort(names)
return slices.Compact(names), nil
}
Loading
Loading