edit

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package edit is the single disk-writing surface in weft. It hands a page's .md file off to the user's editor and detects whether the file changed on return. No other package in the project writes to disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureFile

func EnsureFile(path string) (created bool, err error)

EnsureFile creates an empty file at path with mode 0o644 if it does not exist. Returns (true, nil) on create, (false, nil) if the file already existed, or (false, err) for any other stat/write failure (including the case where path resolves to a directory). This is the create-today-journal hook.

func SnapshotMtime

func SnapshotMtime(path string) (time.Time, error)

SnapshotMtime returns the file's modification time, or time.Time{} (the zero value) if the file does not exist. The zero return is load-bearing: t0.IsZero() means the file was absent at snapshot time, which tells the caller (the App's editCurrent) that it should create the file before handing it to the editor. A non-zero t0 means the file was on disk before the user pressed e.

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile writes data to path, creating the parent directory if it does not yet exist. It is the second deliberate write path in the project (alongside the EnsureFile bootstrap); all disk writes still funnel through package edit.

Types

type Env

type Env struct {
	Visual string // value of $VISUAL
	Editor string // value of $EDITOR
}

Env carries the configuration the editor-resolver reads. Decoupled from os.Getenv so tests can inject a fixed env without touching process state.

type Resolved

type Resolved struct {
	Binary string
}

Resolved is the editor binary to invoke with no args; the file path is appended at call time by the App.

func Resolve

func Resolve(env Env, lookPath func(string) (string, error)) (Resolved, error)

Resolve picks the first available editor in the standard chain: $VISUAL → $EDITOR → /usr/bin/vi. lookPath is injected so tests can simulate "set but missing" / "vi missing" without touching PATH.

Jump to

Keyboard shortcuts

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