1// Package browser provides helpers to open files, readers, and urls in a browser window.
3// The choice of which browser is started is entirely client dependant.
15// Stdout is the io.Writer to which executed commands write standard output.
16var Stdout io.Writer = os.Stdout
18// Stderr is the io.Writer to which executed commands write standard error.
19var Stderr io.Writer = os.Stderr
21// OpenFile opens new browser window for the file path.
22func OpenFile(path string) error {
23 path, err := filepath.Abs(path)
27 return OpenURL("file://" + path)
30// OpenReader consumes the contents of r and presents the
31// results in a new browser window.
32func OpenReader(r io.Reader) error {
33 f, err := ioutil.TempFile("", "browser.*.html")
35 return fmt.Errorf("browser: could not create temporary file: %v", err)
37 if _, err := io.Copy(f, r); err != nil {
39 return fmt.Errorf("browser: caching temporary file failed: %v", err)
41 if err := f.Close(); err != nil {
42 return fmt.Errorf("browser: caching temporary file failed: %v", err)
44 return OpenFile(f.Name())
47// OpenURL opens a new browser window pointing to url.
48func OpenURL(url string) error {
49 return openBrowser(url)
52func runCmd(prog string, args ...string) error {
53 cmd := exec.Command(prog, args...)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list