1
1
mirror of https://github.com/walles/moar.git synced 2024-11-09 17:40:09 +03:00
Moar is a pager. It's designed to just do the right thing without any configuration.
Go to file
2024-01-03 10:40:49 -07:00
.github/workflows Bump CI version of golangci-lint 2024-01-01 13:43:39 +01:00
m Clean up the Reader type 2024-01-03 14:37:34 +01:00
releases Move historical releases into their own directory 2020-12-30 18:43:25 +01:00
sample-files Add terminal hyperlinks example 2023-05-01 15:11:22 +02:00
scripts Try Linux-friendlier mktemp 2022-04-18 19:12:25 +02:00
twin Use the "select" mouse mode on WezTerm 2024-01-03 10:40:49 -07:00
.dockerignore Enable running tests in 32 bit mode 2023-07-08 09:53:11 +02:00
.gitignore Test case for #166 2023-12-01 06:57:08 +01:00
.golangci.yaml Enable revive for unused parameters check 2024-01-01 13:30:25 +01:00
.whitesource Reboot in Go 2019-06-08 22:12:52 +02:00
build.sh Get line numbers style from Chroma style 2023-12-19 09:06:11 +01:00
Dockerfile-test-386 Enable running tests in 32 bit mode 2023-07-08 09:53:11 +02:00
go.mod Drop redundant dependency 2023-12-20 18:28:07 +01:00
go.sum Drop redundant dependency 2023-12-20 18:28:07 +01:00
install.sh Add two comments 2019-07-08 08:58:53 +02:00
LICENSE Reboot in Go 2019-06-08 22:12:52 +02:00
moar_test.go Fix speling error 2023-03-02 07:06:10 +01:00
moar.1 Add --lang to the man page 2024-01-02 16:14:19 +01:00
moar.go Highlight streams if we know the language 2024-01-03 10:41:53 +01:00
moar.sh Make moar.sh runnable from any directory 2020-11-07 13:57:50 +01:00
MOUSE.md Use "select" as a term for selecting text 2023-12-19 09:20:02 +01:00
README.md Auto configure mouse settings in more terminals 2023-12-16 18:59:58 +01:00
release.sh Automate Homebrew packaging 2023-09-15 22:30:23 +02:00
screenshot.png Update screenshot 2021-05-22 15:59:26 +02:00
test.sh Accept +1234 argument in any place 2023-09-29 22:42:41 +02:00

Linux CI Windows CI

Moar is a pager. It reads and displays UTF-8 encoded text from files or pipelines.

moar is designed to just do the right thing without any configuration:

Moar displaying its own source code

The intention is that Moar should be trivial to get into if you have previously been using Less. If you come from Less and find Moar confusing or hard to migrate to, please report it!

Doing the right thing includes:

  • Syntax highlight source code by default using Chroma
  • Search is incremental / find-as-you-type just like in Chrome or Emacs
  • Search becomes case sensitive if you add any UPPER CASE characters to your search terms, just like in Emacs
  • Regexp search if your search string is a valid regexp
  • Supports displaying ANSI color coded texts (like the output from git diff | riff for example)
  • Supports UTF-8 input and output
  • Automatic decompression when viewing compressed text files (.gz, .bz2, .xz)
  • The position in the file is always shown
  • Supports word wrapping (on actual word boundaries) if requested using --wrap or by pressing w
  • Follows output as long as you are on the last line, just like tail -f
  • Renders terminal hyperlinks properly
  • Mouse Scrolling works out of the box (but look here for tradeoffs)

For compatibility reasons, moar uses the formats declared in these environment variables if present:

For configurability reasons, moar reads extra command line options from the MOAR environment variable.

Moar is used as the default pager by:

  • px / ptop, ps and top for human beings
  • riff, a diff filter highlighting which line parts have changed

Installing

Using Homebrew

brew install moar

Then whenever you want to upgrade to the latest release:

brew upgrade

Using MacPorts

sudo port install moar

More info here.

Using Gentoo

emerge --ask --verbose sys-apps/moar

More info here.

Using Arch Linux

yay -S moar

More info here.

Manual Install

  1. Download moar for your platform from https://github.com/walles/moar/releases/latest
  2. chmod a+x moar-*-*-*
  3. sudo mv moar-*-*-* /usr/local/bin/moar

And now you can just invoke moar from the prompt!

Try moar --help to see options.

If a binary for your platform is not available, please file a ticket or contact johan.walles@gmail.com.

Debian / Ubuntu

A Request for Packaging is open, please help!

Configuring

Do moar --help for an up to date list of options.

Environment variable MOAR can be used to set default options.

For example:

export MOAR='--statusbar=bold --no-linenumbers'

Setting moar as your default pager

Set it as your default pager by adding...

export PAGER=/usr/local/bin/moar

... to your .bashrc.

Issues

Issues are tracked here, or you can send questions to johan.walles@gmail.com.

Packaging

If you package moar, do include the man page in your package.

Embedding

Here's one way to embed moar in your app:

package main

import (
	"bytes"
	"fmt"

	"github.com/walles/moar/m"
)

func main() {
	buf := new(bytes.Buffer)
	for range [99]struct{}{} {
		fmt.Fprintln(buf, "Moar")
	}

	err := m.NewPager(m.NewReaderFromStream("Moar", buf)).Page()
	if err != nil {
		// Handle paging problems
		panic(err)
	}
}

m.Reader can also be initialized using NewReaderFromText() or NewReaderFromFilename().

Developing

You need the go tools.

Run tests:

./test.sh

To run tests in 32 bit mode, either do GOARCH=386 ./test.sh if you're on Linux, or docker build . -f Dockerfile-test-386 (tested on macOS).

Run microbenchmarks:

go test -benchmem -run='^$' -bench=. . ./...

Profiling BenchmarkPlainTextSearch(). Try replacing -alloc_objects with -alloc_space or change the -focus function:

go test -memprofilerate 1 -memprofile profile.out -benchmem -run='^$' -bench '^BenchmarkPlainTextSearch$' github.com/walles/moar/m && go tool pprof -alloc_objects -focus findFirstHit -relative_percentages -web profile.out

Build + run:

./moar.sh ...

Install (into /usr/local/bin) from source:

./install.sh

Making a new Release

Make sure that screenshot.png matches moar's current UI. If it doesn't, scale a window to 81x16 characters and make a new one.

Execute release.sh and follow instructions.

TODO

  • Searching for something above us should wrap the search.

  • Enable exiting using ^c (without restoring the screen).

  • Start at a certain line if run as moar file.txt:42

  • Handle search hits to the right of the right screen edge. Searching forwards should move first right, then to the left edge and down. Searching backwards should move first left, then up and to the right edge (if needed for showing search hits).

  • Support viewing multiple files by pushing them in reverse order on the view stack.

  • Incremental search using ^s and ^r like in Emacs

  • Retain the search string when pressing / to search a second time.

Done

  • Add > markers at the end of lines being cut because they are too long

  • Doing moar on an arbitrary binary (like /bin/ls) should put all line-continuation markers at the rightmost column. This really means our truncation code must work even with things like tabs and various control characters.

  • Make sure search hits are highlighted even when we have to scroll right to see them

  • Change out-of-file visualization to writing --- after the end of the file and leaving the rest of the screen blank.

  • Exit search on pressing up / down / pageup / pagedown keys and scroll. I attempted to do that spontaneously, so it's probably a good idea.

  • Remedy all FIXMEs in this README file

  • Release the go version as the new moar, replacing the previous Ruby implementation

  • Add licensing information (same as for the Ruby branch)

  • Make sure git grep output gets highlighted properly.

  • Handle all kinds of line endings.

  • Make sure version information is printed if there are warnings.

  • Add spinners while file is still loading

  • Make tail -f /dev/null exit properly, fix https://github.com/walles/moar/issues/7.

  • Showing unicode search hits should highlight the correct chars

  • Word wrap text rather than character wrap it.

  • Arrow keys up / down while in line wrapping mode should scroll by screen line, not by input file line.

  • Define 'g' to prompt for a line number to go to.