Skip to main content

Crate scissors

Crate scissors 

Source
Expand description

Editor-based content approval, git-commit style.

Opens content in the user’s editor, lets them edit or approve it, and returns the bytes above the scissors line. Modelled on git’s commit.cleanup=scissors convention.

Input is UTF-8 text only: non-UTF-8 bytes surface as an I/O error before anything is written.

Structs§

Options
Optional knobs for approve_in_editor and approve_file_in_place.

Enums§

FileError
Errors from approve_file_in_place. On every error the target file is left exactly as it was: editing happens in a sidecar that is discarded on failure.
FileOutcome
Outcome of an in-place file approval. The approved content is in the file itself; on abort the file is left untouched.
Outcome
Result of a stdin-mode approval round-trip.
ScissorsError
Errors from approve_in_editor. The failure cases preserve the draft file and report its path so the user can recover their work.

Constants§

SCISSORS
The git scissors separator. build_draft ends the footer with this exact line; strip_scissors cuts at its last occurrence.

Functions§

approve_file_in_place
Open path in the user’s editor, edited in place. The caller owns path: this never creates or deletes it.
approve_in_editor
Open content in the user’s editor and return the approved bytes.
resolve_editor
Resolve the editor command, honouring $VISUAL > $EDITOR > vi. Returns the command split into program + args (e.g. ["code", "--wait"]).
strip_scissors
Return everything above the last scissors line, trimmed. If there is no scissors line, return the whole input trimmed. Cutting at the last occurrence (the footer is always appended last) preserves a body that itself contains a scissors line, instead of silently discarding everything below it.