Documentation
¶
Overview ¶
Package textedit provides helpers for making changes to line-oriented text files. This is especially targeted at "shell rc" files like `~/.bashrc` or `~/.zshrc`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Editor ¶
type Editor interface {
// Next is called after each input line is read. If err is non-nil, the edit
// operation will fail. Otherwise any lines in output will be emitted. This
// must include the input line if it should be copied to the output.
Next(line string) (output iter.Seq[string], err error)
// EOF is called after all input lines have been processed through Next. Its
// return will be processed the same way as Next.
EOF() (output iter.Seq[string], err error)
}
func AppendLine ¶
AppendLine adds the given line to the end of the file if it is not already present. It will also insert it in place of any of the given oldLines (optional).
It will panic if the line or any of the oldLines are empty after trimming leading & trailing whitespace.
func SpliceRange ¶
Splice a range of lines marked by the start and end lines. Panics if len(lines) < 3, i.e. must have start & end markers and at least one "content" line, or if the start or end markers are empty after trimming leading & trailing whitespace.
Matching the start and end markers is done after trimming leading & trailing whitespace from both the sought & observed lines.