Help us shape the future of Go! Take the 2026 Go Developer Survey

files

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package files maps course content to local paths, downloads it, and opens it.

Index

Constants

View Source
const DefaultEditor = "vi"

DefaultEditor is used when $EDITOR is unset.

Variables

This section is empty.

Functions

func CourseDir

func CourseDir(root string, c d2l.Course) string

CourseDir is the folder of a course's files under root.

func DirNames

func DirNames(m *d2l.Module) map[int]string

DirNames picks the local folder name of each submodule of m, keyed by ModuleID, with the same rule as Names.

func Download

func Download(ctx context.Context, c *d2l.Client, orgUnit int, t d2l.Topic, dest string) (skipped bool, err error)

Download fetches a File topic to dest unless it is already Fresh.

func DownloadAttachment

func DownloadAttachment(ctx context.Context, c *d2l.Client, orgUnit, newsID int, a d2l.Attachment, dir string) (string, error)

DownloadAttachment saves an announcement attachment into dir and returns its path.

func FileName

func FileName(t d2l.Topic) string

FileName picks the local name for a File topic: the name from its URL, falling back to the title.

func Fresh

func Fresh(dest string, t d2l.Topic) bool

Fresh reports whether dest exists and is not older than the topic. Download stamps files with the topic's LastModifiedDate, so an equal mtime means unchanged.

func ModuleDir

func ModuleDir(root string, c d2l.Course, levels []*d2l.Module) string

ModuleDir is the folder of the last module in levels. levels[0] is the TOC root and each later module is a child of the one before it.

func Names

func Names(m *d2l.Module) map[int]string

Names picks the local name of each File topic directly in m, keyed by TopicID. When names clash, ignoring case, the topic with the lowest ID keeps the name and the others get " (TopicID)" before the extension. IDs only grow, so adding or reordering topics never renames an existing file.

func Sanitize

func Sanitize(s string) string

Sanitize makes s safe as a single path component.

func ShellCommand

func ShellCommand(command, arg string) *exec.Cmd

ShellCommand runs a user-configured command with arg appended as "$1", so commands with their own arguments (`zathura --fork`, `code --wait`) work and arg is never parsed by the shell.

func StartDetached

func StartDetached(cmd *exec.Cmd) error

StartDetached runs a non-terminal opener in its own session so it outlives the TUI and doesn't scribble on the screen. It waits up to openerGrace and reports a non-zero exit in that time with the first line of stderr.

Types

type Entry

type Entry struct {
	Path  []string // module titles, outermost first
	Topic d2l.Topic
	Dest  string // empty unless Topic.IsFile()
}

Entry is a topic with the module titles leading to it and, for a File topic, where it is stored.

func Entries

func Entries(m *d2l.Module, dir string, prefix []string) []Entry

Entries returns every topic under m, depth first, in display order. dir is m's folder and prefix its module titles.

type Opener

type Opener struct {
	Cmd *exec.Cmd
	// Terminal means the command needs the TTY; the TUI must suspend for it.
	Terminal bool
}

Opener is a command that opens a file or URL.

func OpenerFor

func OpenerFor(cfg *config.Config, target string) Opener

OpenerFor picks the command for target (a local path or a URL) from the config's extension maps, falling back to the system opener.

Jump to

Keyboard shortcuts

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