m

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-2-Clause-Views Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_HIGHLIGHT_SIZE int64 = 1024 * 1024

Files larger than this won't be highlighted

View Source
const NO_BREAK_SPACE = '\xa0'

From: https://www.compart.com/en/unicode/U+00A0

Variables

This section is empty.

Functions

func NewScrollPositionFromLineNumber added in v1.22.0

func NewScrollPositionFromLineNumber(lineNumber linenumbers.LineNumber, name string) scrollPosition

Create a new position, scrolled to the given line number

func TermcapToStyle added in v1.23.0

func TermcapToStyle(termcap string) (twin.Style, error)

func ZOpen added in v1.22.0

func ZOpen(filename string) (io.ReadCloser, string, error)

The second return value is the file name with any compression extension removed.

Types

type InputLines added in v1.8.0

type InputLines struct {
	// contains filtered or unexported fields
}

InputLines contains a number of lines from the reader, plus metadata

type Line

type Line struct {
	// contains filtered or unexported fields
}

A Line represents a line of text that can / will be paged

func NewLine

func NewLine(raw string) Line

NewLine creates a new Line from a (potentially ANSI / man page formatted) string

func (*Line) HighlightedTokens added in v1.7.0

func (line *Line) HighlightedTokens(plainTextStyle twin.Style, search *regexp.Regexp, lineNumber *linenumbers.LineNumber) textstyles.StyledRunesWithTrailer

Returns a representation of the string split into styled tokens. Any regexp matches are highlighted. A nil regexp means no highlighting.

func (*Line) Plain

func (line *Line) Plain(lineNumber *linenumbers.LineNumber) string

Plain returns a plain text representation of the initial string

type MatchRanges

type MatchRanges struct {
	Matches [][2]int
}

MatchRanges collects match indices

func (*MatchRanges) InRange

func (mr *MatchRanges) InRange(index int) bool

InRange says true if the index is part of a regexp match

type Pager

type Pager struct {

	// NewPager shows lines by default, this field can hide them
	ShowLineNumbers bool

	StatusBarStyle StatusBarOption
	ShowStatusBar  bool

	UnprintableStyle textstyles.UnprintableStyleT

	WrapLongLines bool

	// Ref: https://github.com/walles/moar/issues/113
	QuitIfOneScreen bool

	// Ref: https://github.com/walles/moar/issues/94
	ScrollLeftHint  twin.StyledRune
	ScrollRightHint twin.StyledRune

	SideScrollAmount int // Should be positive

	// If non-nil, scroll to this line number as soon as possible. Set this
	// value to LineNumberMax() to follow the end of the input (tail).
	TargetLineNumber *linenumbers.LineNumber

	// If true, pager will clear the screen on return. If false, pager will
	// clear the last line, and show the cursor.
	DeInit bool

	WithTerminalFg bool // If true, don't set linePrefix

	AfterExit func() error
	// contains filtered or unexported fields
}

Pager is the main on-screen pager

func NewPager

func NewPager(r *Reader) *Pager

NewPager creates a new Pager with default settings

func (*Pager) Page

func (p *Pager) Page() error

Page displays text in a pager.

func (*Pager) Quit

func (p *Pager) Quit()

Quit leaves the help screen or quits the pager

func (*Pager) ReprintAfterExit added in v1.8.4

func (p *Pager) ReprintAfterExit() error

After the pager has exited and the normal screen has been restored, you can call this method to print the pager contents to screen again, faking "leaving" pager contents on screen after exit.

func (*Pager) StartPaging

func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chromaFormatter *chroma.Formatter)

StartPaging brings up the pager on screen

type PagerMode added in v1.22.0

type PagerMode interface {
	// contains filtered or unexported methods
}

type PagerModeGotoLine added in v1.22.0

type PagerModeGotoLine struct {
	// contains filtered or unexported fields
}

type PagerModeJumpToMark added in v1.22.0

type PagerModeJumpToMark struct {
	// contains filtered or unexported fields
}

type PagerModeMark added in v1.22.0

type PagerModeMark struct {
	// contains filtered or unexported fields
}

type PagerModeNotFound added in v1.22.0

type PagerModeNotFound struct {
	// contains filtered or unexported fields
}

type PagerModeSearch added in v1.22.0

type PagerModeSearch struct {
	// contains filtered or unexported fields
}

type PagerModeViewing added in v1.22.0

type PagerModeViewing struct {
	// contains filtered or unexported fields
}

type Reader

type Reader struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Reader reads a file into an array of strings.

It does the reading in the background, and it returns parts of the read data upon request.

This package provides query methods for the struct, no peeking!!

func NewReaderFromFilename

func NewReaderFromFilename(filename string, formatter chroma.Formatter, options ReaderOptions) (*Reader, error)

NewReaderFromFilename creates a new file reader.

If options.Lexer is nil it will be determined from the input file name.

If options.Style is nil, you must call reader.SetStyleForHighlighting() later to get highlighting.

The Reader will try to uncompress various compressed file format, and also apply highlighting to the file using Chroma: https://github.com/alecthomas/chroma

func NewReaderFromStream

func NewReaderFromStream(name string, reader io.Reader, formatter chroma.Formatter, options ReaderOptions) *Reader

NewReaderFromStream creates a new stream reader

The name can be an empty string ("").

If non-empty, the name will be displayed by the pager in the bottom left corner to help the user keep track of what is being paged.

Note that you must call reader.SetStyleForHighlighting() after this to get highlighting.

func NewReaderFromText

func NewReaderFromText(name string, text string) *Reader

NewReaderFromText creates a Reader from a block of text.

First parameter is the name of this Reader. This name will be displayed by Moar in the bottom left corner of the screen.

Calling _wait() on this Reader will always return immediately, no asynchronous ops will be performed.

func (*Reader) AwaitFirstByte added in v1.23.8

func (reader *Reader) AwaitFirstByte()

Wait for the first line to be read.

Used for making sudo work: https://github.com/walles/moar/issues/199

func (*Reader) GetLine

func (reader *Reader) GetLine(lineNumber linenumbers.LineNumber) *Line

GetLine gets a line. If the requested line number is out of bounds, nil is returned.

func (*Reader) GetLineCount

func (reader *Reader) GetLineCount() int

GetLineCount returns the number of lines available for viewing

func (*Reader) GetLines

func (reader *Reader) GetLines(firstLine linenumbers.LineNumber, wantedLineCount int) (*InputLines, overflowState)

GetLines gets the indicated lines from the input

Overflow state will be didFit if we returned all lines we currently have, or didOverflow otherwise.

func (*Reader) PumpToStdout added in v1.23.8

func (reader *Reader) PumpToStdout()

func (*Reader) SetStyleForHighlighting added in v1.23.8

func (reader *Reader) SetStyleForHighlighting(style chroma.Style)

type ReaderOptions added in v1.28.0

type ReaderOptions struct {
	// Format JSON input
	ShouldFormat bool

	// If this is nil, you must call reader.SetStyleForHighlighting() later if
	// you want highlighting.
	Style *chroma.Style

	// If this is set, it will be used as the lexer for highlighting
	Lexer chroma.Lexer
}

type StatusBarOption added in v1.20.0

type StatusBarOption int
const (
	//revive:disable-next-line:var-naming
	STATUSBAR_STYLE_INVERSE StatusBarOption = iota
	//revive:disable-next-line:var-naming
	STATUSBAR_STYLE_PLAIN
	//revive:disable-next-line:var-naming
	STATUSBAR_STYLE_BOLD
)

Directories

Path Synopsis
This package handles styled strings.
This package handles styled strings.

Jump to

Keyboard shortcuts

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