Documentation ¶
Index ¶
- Constants
- func AutocompleteDirectory(path string) ([]string, error)
- func GlobMatch(pattern, name string) bool
- func ListDir(ctx context.Context, root string, options ListDirOptions) []string
- func RelativePath(p string, baseDir string) string
- func RelativePathCwd(p string) string
- func ValidateCreate(path string) error
- type Checksummer
- type ListDirOptions
- type Timeline
- type TimelineState
- type Watcher
- func Load(path string, watcherPollInterval time.Duration) (*text.Tree, *Watcher, error)
- func NewEmptyWatcher() *Watcher
- func NewWatcherForExistingFile(pollInterval time.Duration, path string, lastModified time.Time, size int64, ...) *Watcher
- func NewWatcherForNewFile(pollInterval time.Duration, path string) *Watcher
- func Save(path string, tree *text.Tree, watcherPollInterval time.Duration) (*Watcher, error)
Constants ¶
const DefaultPollInterval = time.Second
Variables ¶
This section is empty.
Functions ¶
func AutocompleteDirectory ¶ added in v1.3.0
AutocompleteDirectory autocompletes the last subdirectory in a path.
func GlobMatch ¶ added in v0.2.0
GlobMatch checks if a path matches a glob pattern. A "*" in the pattern is a wildcard that matches part of a component in a path. A "**" in a component of the pattern is a wildcard that matches components of the path. For example, the pattern "**/*.go" matches "foo/bar/baz.go" The algorithm is based on the backtracking approach described in https://research.swtch.com/glob
func ListDir ¶ added in v0.2.0
func ListDir(ctx context.Context, root string, options ListDirOptions) []string
ListDir lists every file in a root directory and its subdirectories. The returned paths are relative to the root directory. The order of the returned paths is non-deterministic. Symbolic links are not followed. If an error occurs while accessing a directory, ListDir will skip that directory and log the error.
func RelativePath ¶
RelativePath converts an absolute path to a path relative to a base directory. If the conversion fails, the absolute path will be returned instead.
func RelativePathCwd ¶
RelativePathCwd converts an absolute path to a path relative to the current working directory. If the conversion fails, the absolute path will be returned instead.
func ValidateCreate ¶ added in v1.3.0
ValidateCreate checks whether the user can (probably) create a file at a path. This is meant to catch common issues (non-existent directory, file already exists) but isn't 100% accurate. In particular, another process could modify the filesystem after the check, or the user might not have permission to create the file.
Types ¶
type Checksummer ¶
type Checksummer struct {
// contains filtered or unexported fields
}
Checksummer calculates an MD5 checksum.
func NewChecksummer ¶
func NewChecksummer() *Checksummer
func (*Checksummer) Checksum ¶
func (c *Checksummer) Checksum() string
Checksum returns the MD5 checksum as a base16 string.
type ListDirOptions ¶ added in v0.7.0
type Timeline ¶
type Timeline struct {
// contains filtered or unexported fields
}
Timeline represents the history of files loaded in the editor. It provides the ability to move forward or backward through loaded files.
func (*Timeline) PeekBackward ¶
func (t *Timeline) PeekBackward() TimelineState
PeekBackward returns the state immediately before the current state.
func (*Timeline) PeekForward ¶
func (t *Timeline) PeekForward() TimelineState
PeekForward returns the state immediately after the current state.
func (*Timeline) TransitionBackwardFrom ¶
func (t *Timeline) TransitionBackwardFrom(fromState TimelineState)
TransitionBackwardFrom moves the timeline backward to the previous state.
func (*Timeline) TransitionForwardFrom ¶
func (t *Timeline) TransitionForwardFrom(fromState TimelineState)
TransitionForwardFrom moves the timeline forward to the next state.
func (*Timeline) TransitionFrom ¶
func (t *Timeline) TransitionFrom(fromState TimelineState)
TransitionFrom moves the timeline forward from the given state and invalidates any future states in the timeline. This happens when the user loads a new document in the editor.
type TimelineState ¶
TimelineState represents the state of a file loaded in the editor before or after a transition in the timeline.
func (TimelineState) Empty ¶
func (s TimelineState) Empty() bool
Empty checks whether the timeline state is empty. An empty state represents the beginning or end of the timeline.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher checks if a file's contents have changed.
func Load ¶
Load reads a file from disk and starts a watcher to detect changes. This will remove the POSIX end-of-file indicator (line feed at end of file).
func NewEmptyWatcher ¶
func NewEmptyWatcher() *Watcher
NewEmptyWatcher returns a watcher that has an empty path and never triggers.
func NewWatcherForExistingFile ¶ added in v1.3.0
func NewWatcherForExistingFile(pollInterval time.Duration, path string, lastModified time.Time, size int64, checksum string) *Watcher
NewWatcherForExistingFile returns a watcher for a file that exists on disk. lastModified is the time the file was last modified, as reported when the file was loaded. size is the size in bytes of the file when it was loaded. checksum is an MD5 hash of the file's contents when it was loaded.
func NewWatcherForNewFile ¶ added in v1.3.0
NewWatcherForNewFile returns a watcher for a file that does not yet exist on disk.
func Save ¶
Save writes the text to disk and starts a new watcher to detect subsequent changes. This adds the POSIX end-of-file indicator (line feed at the end of the file).
func (*Watcher) ChangedChan ¶
func (w *Watcher) ChangedChan() chan struct{}
ChangedChan returns a channel that receives a message when the file's contents change. This can produce false negatives if an error occurs accessing the file (for example, if file permissions changed). The channel will receive at most one message. This method is thread-safe.
func (*Watcher) CheckFileContentsChanged ¶ added in v0.4.0
CheckFileContentsChanged checks whether the file's checksum has changed. If the file no longer exists, this will return an error.
func (*Watcher) CheckFileMovedOrDeleted ¶ added in v1.3.0
CheckFileMovedOrDeleted checks whether the file used to exist at the path but has since been moved or deleted.