browser

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: BSD-2-Clause Imports: 7 Imported by: 64

README

browser

Helpers to open URLs, readers, or files in the system default web browser.

This fork adds:

  • OpenReader error wrapping;
  • ErrNotFound error wrapping on BSD;
  • Go 1.21 support.

Usage

import "github.com/cli/browser"

err = browser.OpenURL(url)
err = browser.OpenFile(path)
err = browser.OpenReader(reader)

Documentation

Overview

Package browser provides helpers to open files, readers, and urls in a browser window.

The choice of which browser is started is entirely client dependent.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Stderr io.Writer = os.Stderr

Stderr is the io.Writer to which executed commands write standard error.

View Source
var Stdout io.Writer = os.Stdout

Stdout is the io.Writer to which executed commands write standard output.

Functions

func OpenFile

func OpenFile(path string) error

OpenFile opens new browser window for the file path.

Example
_ = OpenFile("index.html")
Output:

func OpenReader

func OpenReader(r io.Reader) error

OpenReader consumes the contents of r and presents the results in a new browser window.

Example
// https://github.com/rust-lang/rust/issues/13871
const quote = `There was a night when winds from unknown spaces
whirled us irresistibly into limitless vacum beyond all thought and entity.
Perceptions of the most maddeningly untransmissible sort thronged upon us;
perceptions of infinity which at the time convulsed us with joy, yet which
are now partly lost to my memory and partly incapable of presentation to others.`
r := strings.NewReader(quote)
_ = OpenReader(r)
Output:

func OpenURL

func OpenURL(url string) error

OpenURL opens a new browser window pointing to url.

Example
const url = "http://golang.org/"
_ = OpenURL(url)
Output:

Types

This section is empty.

Directories

Path Synopsis
examples
Open
Open is a simple example of the github.com/pkg/browser package.
Open is a simple example of the github.com/pkg/browser package.

Jump to

Keyboard shortcuts

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