ops

package
v0.0.0-...-e284415 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ops — path utilities shared across file operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartJob

func StartJob(job *Job, srcProv, dstProv provider.Provider) tea.Cmd

StartJob returns a tea.Cmd that runs the job in a goroutine and sends a final JobDoneMsg when done. Progress is polled separately via TickProgress.

func TickProgress

func TickProgress(job *Job) tea.Cmd

TickProgress returns a Cmd that snapshots progress for the given job and sends a ProgressMsg. The app calls this on a ticker.

func UniquePath

func UniquePath(dir, name string) string

UniquePath returns a path in dir that doesn't collide with any existing entry. Given "dir" and "base.txt", if dir/base.txt already exists it returns dir/base copy.txt, dir/base copy 2.txt, … up to 999.

Extension is preserved, which keeps macOS and GUI file-managers happy. "base" alone (no extension) becomes "base copy", "base copy 2", etc.

Only the local filesystem is checked; callers using non-local providers should pass a Stat wrapper or substitute their own existence check via UniquePathWith.

func UniquePathWith

func UniquePathWith(dir, name string, exists func(string) bool) string

UniquePathWith is UniquePath with a caller-supplied "exists" predicate so it can be used with remote providers.

Types

type CloseQueueMsg

type CloseQueueMsg struct{}

CloseQueueMsg is sent when the user dismisses the job queue overlay.

type DeleteConfirmedMsg

type DeleteConfirmedMsg struct {
	Path     string
	Provider provider.Provider
}

DeleteConfirmedMsg is sent by the pane when the user confirms deletion.

type Job

type Job struct {
	ID         int
	Kind       JobKind
	Src        string
	Dst        string // empty for delete
	Status     JobStatus
	Progress   float64 // 0.0–1.0
	BytesDone  int64
	BytesTotal int64
	Speed      float64 // bytes/sec, rolling average
	ETA        time.Duration
	Err        error
	StartTime  time.Time
	// contains filtered or unexported fields
}

Job represents a single background file operation.

type JobDoneMsg

type JobDoneMsg struct {
	JobID int
	Err   error
}

JobDoneMsg is sent when a job completes (success or error).

type JobKind

type JobKind string

JobKind identifies what kind of file operation a job performs.

const (
	KindCopy   JobKind = "Copy"
	KindMove   JobKind = "Move"
	KindDelete JobKind = "Delete"
	KindTrash  JobKind = "Trash"
)

type JobStatus

type JobStatus string

JobStatus describes the lifecycle state of a job.

const (
	StatusPending JobStatus = "pending"
	StatusRunning JobStatus = "running"
	StatusDone    JobStatus = "done"
	StatusError   JobStatus = "error"
	StatusPaused  JobStatus = "paused"
)

type ProgressMsg

type ProgressMsg struct {
	JobID int
	Done  int64
	Total int64
	Speed float64
	ETA   time.Duration
}

ProgressMsg is sent periodically by a running job.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue manages a list of background file-operation jobs.

func NewQueue

func NewQueue() *Queue

NewQueue creates an empty Queue.

func (*Queue) Add

func (q *Queue) Add(kind JobKind, src, dst string) *Job

Add creates a new job and appends it to the queue (not yet started).

func (*Queue) CancelJob

func (q *Queue) CancelJob(id int)

CancelJob signals the job's goroutine to stop.

func (*Queue) ClearDone

func (q *Queue) ClearDone()

ClearDone removes all jobs with StatusDone or StatusError from the queue.

func (*Queue) Get

func (q *Queue) Get(id int) (*Job, bool)

Get returns the job with the given ID.

func (*Queue) Jobs

func (q *Queue) Jobs() []*Job

Jobs returns a snapshot of all jobs (caller must not mutate elements).

func (*Queue) PauseJob

func (q *Queue) PauseJob(id int)

PauseJob marks the job as paused so its goroutine will sleep between chunks.

func (*Queue) ResumeJob

func (q *Queue) ResumeJob(id int)

ResumeJob clears the paused flag so the job goroutine continues.

func (*Queue) Running

func (q *Queue) Running() []*Job

Running returns all jobs currently in StatusRunning.

type QueueModel

type QueueModel struct {
	Width  int
	Height int
	Theme  *theme.Theme
	Queue  *Queue
	// contains filtered or unexported fields
}

QueueModel is the Bubbletea overlay model for the job queue.

func NewQueueModel

func NewQueueModel(q *Queue, t *theme.Theme) *QueueModel

NewQueueModel creates a new QueueModel.

func (*QueueModel) Update

func (m *QueueModel) Update(msg tea.Msg) (*QueueModel, tea.Cmd)

Update handles key events for the queue overlay.

func (*QueueModel) View

func (m *QueueModel) View() string

View renders the job queue overlay.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL