gmir

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 9 Imported by: 0

README

gmir is a reader for gmi files (of the Gemini protocol). Its goal is to make reading gmi files more pleasant than with a pager like less, while also offering link selection.

Features include word wrapping, syntax highlighting, jumping to headings through a table of contents and more.

The link selection feature is intended to make gmir well suited as the pager for Gemini browsers like acdw/bollux, chambln/gmi or blmayer/astro. Unlike with less, following links is possible without dropping back to a command prompt first. Once a link is selected, gmir quits and prints its URL to the standard output.

screenshot of gmir

Installation

You can find precompiled binaries at the releases page. If you prefer to install from source, execute this:

go install github.com/codesoap/gmir/cmd/gmir@latest

The gmir binary is now located at ~/go/bin/gmir. If you use Go version 1.15 or older, use go get instead.

Usage

$ gmir -h
Usage:
gmir [-u] [-t TITLE] [FILE]
If FILE is not given, standard input is read.

Options:
-u  Hide URLs of links by default
-t  Set a title that is displayed in the bar.

Key bindings:
Up, k     : Scroll up one line
Down, j   : Scroll down one line
Right, l  : Scroll right one column; reset with Esc
u         : Scroll up half a page
d         : Scroll down half a page
Page up, b: Scroll up a full page
Page down,
f, Space  : Scroll down a full page
g         : Go to the top
G         : Go to the bottom
h         : Go to next heading
H         : Go to previous heading
t         : Show table of contents
/         : Start search
?         : Start reverse search
n         : Go to next search match
p         : Go to previous search match
0-9       : Select link or table of contents entry
Esc       : Clear input and right scroll or exit table of contents
v         : Hide link URLs
V         : Show link URLs
q         : Quit

TODO

Here are some ideas on what could be added in the future, in no particular order:

  • Add key bindings for going back, forward and reloading a page.

Documentation

Index

Constants

View Source
const (
	Regular       = Mode(iota)
	Search        // Typing a search term.
	ReverseSearch // Typing a search term for reverse search.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode int

type View

type View struct {

	// Number of columns to shift the content to the left. Useful for
	// viewing preformatted text, that is wider than the screen. The
	// shifting will be limited by the widest preformatted line in lines.
	ColOffset int

	Mode          Mode
	Searchterm    string         // The search term while it is being typed.
	Cursor        int            // Index of first byte of cursored rune in Searchterm. May be up to len(Searchterm).
	Searchpattern *regexp.Regexp // The active search pattern.

	// If not "", this info is displayed in the bar. Useful for infos like
	// "Invalid search pattern" or "No match found".
	Info string
	// contains filtered or unexported fields
}

A View represents the whole state related to a document, including its content and scroll position.

func NewView

func NewView(in io.Reader, title string) (View, error)

func (*View) AddDigitToSelector added in v0.3.0

func (v *View) AddDigitToSelector(digit int)

AddDigitToSelector adds a single digit to the end of v.selector.

func (*View) ClearSelector added in v0.3.0

func (v *View) ClearSelector()

ClearSelector sets v.selector to an empty string.

func (View) Draw

func (v View) Draw(screen tcell.Screen)

Draw draws the given view to screen. The screen is separated like this:

   7cols    11cols     10cols          18cols
┌───────┬───────────┬──────────┬──────────────────┐
│ left  │ selectors │ rendered │    right space   │
│ space │           │ gmi      │                  │
│       │           │          │                  │
├───────┴───────────┴──────────┴──────────────────┤
│ bar                                             │
└─────────────────────────────────────────────────┘

The rendered gmi aims to be a width that is comfortable to read. The right space may be intruded by preformatted lines. The selector column will always be wide enough to fit the largest selector in the document.

func (*View) FixLineOffset

func (v *View) FixLineOffset(screen tcell.Screen)

FixLineOffset fixes v.lineOffset to ensure it does not go over the amount of actually available wrapped lines. Use after screen resize or any other event that changes the amount of wraps for a line.

func (*View) HideURLs added in v0.3.0

func (v *View) HideURLs()

HideURLs disables the display of URLs for link lines.

func (View) IsEmpty added in v0.3.0

func (v View) IsEmpty() bool

func (View) LinkURL

func (v View) LinkURL() string

LinkURL returns the URL for v.selector.

func (*View) Scroll

func (v *View) Scroll(screen tcell.Screen, lines int)

Scroll scrolls up or down the given amount of (wrapped) lines. Scrolls up, if lines is negative. Never scrolls past the top or bottom line.

func (*View) ScrollDownToNextSearchMatch

func (v *View) ScrollDownToNextSearchMatch(screen tcell.Screen) bool

ScrollDownToSearchMatch scrolls to the next line, that matches v.Searchpattern.

Returns false, if none of the lines after the current one matches v.Searchpattern.

func (*View) ScrollDownToSearchMatch

func (v *View) ScrollDownToSearchMatch(screen tcell.Screen) bool

ScrollDownToSearchMatch scrolls to the next line, that matches v.Searchpattern. If the current line matches v.Searchpattern, nothing is done.

Returns false, if neither the current line nor any line after matches v.Searchpattern.

func (*View) ScrollToBottom

func (v *View) ScrollToBottom(screen tcell.Screen)

ScrollToBottom scrolls to the last line.

func (*View) ScrollToNextHeading

func (v *View) ScrollToNextHeading(screen tcell.Screen)

ScrollToNextHeading scrolls to the first line of the next heading.

func (*View) ScrollToNthHeading added in v0.3.0

func (v *View) ScrollToNthHeading(screen tcell.Screen, n int)

ScrollToNthHeading scrolls to the first line of the nth heading.

func (*View) ScrollToPrevHeading

func (v *View) ScrollToPrevHeading(screen tcell.Screen)

ScrollToPrevHeading scrolls to the first line of the previous heading.

func (*View) ScrollToTop

func (v *View) ScrollToTop(screen tcell.Screen)

ScrollToTop scrolls to the first line.

func (*View) ScrollUpToNextSearchMatch

func (v *View) ScrollUpToNextSearchMatch(screen tcell.Screen) bool

ScrollUpToSearchMatch scrolls to the previous line, that matches v.Searchpattern.

Returns false, if none of the lines after the current one matches v.Searchpattern.

func (*View) ScrollUpToSearchMatch

func (v *View) ScrollUpToSearchMatch(screen tcell.Screen) bool

ScrollUpToSearchMatch scrolls to the previous line, that matches v.Searchpattern. If the current line matches v.Searchpattern, nothing is done.

Returns false, if neither the current line nor any line after matches v.Searchpattern.

func (View) SelectorIndex added in v0.3.0

func (v View) SelectorIndex() int

SelectorNumber returns the currently selected index.

func (View) SelectorIsValid added in v0.3.0

func (v View) SelectorIsValid() bool

SelectorIsValid returns true, if the selector is complete and resolves to a valid selectable.

func (*View) ShowURLs added in v0.3.0

func (v *View) ShowURLs()

ShowURLs enables the display of URLs for link lines.

func (View) TOCView added in v0.3.0

func (v View) TOCView() View

TOCView returns a copy of v only containing headings and with selectable set to heading. This copy is suitable for use as a table of contents.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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