sysopen

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sysopen decides which files are not for a text editor, and hands those to the operating system's own application: a PDF to the document viewer, a song to the music player, a photo to the image viewer.

It knows nothing of buffers or prompts. Whether to ask first, and what to remember, is the editor's business; this package answers "is it text?" and does "open it the way the desktop would".

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("no system app to open files with")

ErrUnavailable is wrapped by the errors Available and Open return when the system has no way to open a file for the user.

Functions

func Available

func Available() error

Available reports why files cannot be handed to the system, or nil when they can. It is cheap enough to ask before offering the choice at all.

func Ext

func Ext(path string) string

Ext returns path's extension, lower-cased and without the dot: the key the editor remembers a choice under. A file with none gives "".

func IsText

func IsText(path string) (bool, error)

IsText reports whether the regular file at path is text worth opening in an editor.

A known binary extension says no without reading. Otherwise the first sniffLen bytes decide: any NUL byte means binary, since text almost never holds one; and so does a sample that is more than a tenth invalid UTF-8. The tolerance is what lets a Latin-1 file with a few accented letters through as text, while compressed or encoded data - where invalid sequences run to about half - is caught. An empty file is text: it is what a new file looks like.

func Open

func Open(path string, failed func(error)) error

Open starts the system's app on path and returns without waiting for it.

The app is detached: its output goes nowhere near nem's terminal, and it lives on after nem exits. If the opener fails soon after starting, failed is called - from another goroutine, so it must not touch editor state directly.

The opener's messages are discarded rather than captured. Captured through a pipe, the viewer it starts would inherit that pipe: the goroutine would then wait on the viewer, not the opener, and once nem closed its end the viewer's next log line would kill it with SIGPIPE. The exit status is enough to say that opening failed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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