-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: real pager with incremental search
Closes #51 Closes #77 Closes #105 bubbles.Viewport isn't really appropriate for a buffer that we keep appending to like this: we have to manually bookkeep a lot of state back and forth between the tui and the viewports——each time we receive a line, we send the whole-ass buffer into the viewport. Instead, let's encapsulate the viewports and the log content together into a new ui component per-stream. - adds vim-style incremental search with highlighting - scroll performance is now roughly O(window height) instead of O(buffer size) - adds "responsive design", making the ui a lot smaller in small windows - moves tui help into its own pane, accessed with 'h' or '?' - adds a bonus package, cmd/scroll, which is a tail replacement of dubious value - adds some usability features, like a confirmation before quitting Additionally, we clean up our use of color a bit, so that run looks good whether you're in dark mode or light. - make color hash adaptive - use adaptive colors everywhere - don't use backgrounds anywhere
- Loading branch information
Showing
35 changed files
with
2,091 additions
and
691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,33 +633,6 @@ SOFTWARE. | |
|
||
|
||
|
||
github.com/sahilm/[email protected] | ||
============================== | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Sahil Muthoo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
||
|
||
golang.org/x/[email protected] | ||
======================== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Scroll is a tailing pager. | ||
// | ||
// - Unlike tail, it has interactive features like | ||
// paging and incremental regex search. | ||
// | ||
// - Unlike less, it continuously tries to keep reading | ||
// more bytes from the input file. | ||
// | ||
// - Unlike less and tail, it loads the whole file into | ||
// memory before starting, which makes it perform worse | ||
// on files which are already large. | ||
// | ||
// On my machine, I start to notice perceptible latency: | ||
// - Changing search query in a file larger than a few dozen MB | ||
// - Opening a file larger than a few hundred MB | ||
// | ||
// I never notice latency in scrolling or tailing, even in | ||
// files up to 15 GB. I didn't test any files larger than that | ||
// because they take too long to open. | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/amonks/run/pkg/logview" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
program := tea.NewProgram(newScroll(), | ||
tea.WithAltScreen(), | ||
tea.WithMouseCellMotion()) | ||
|
||
filename := flag.Arg(0) | ||
|
||
sinkErr := make(chan error) | ||
sink := Sink(func(s string) { program.Send(writeMsg(s)) }) | ||
go func() { | ||
switch filename { | ||
case "-", "": | ||
sinkErr <- sink.tailStdin() | ||
default: | ||
sinkErr <- sink.tailFile(filename) | ||
} | ||
}() | ||
|
||
programErr := make(chan error) | ||
go func() { | ||
_, err := program.Run() | ||
programErr <- err | ||
}() | ||
|
||
select { | ||
case err := <-sinkErr: | ||
program.Send(tea.Quit()) | ||
<-programErr | ||
fmt.Println(err) | ||
os.Exit(1) | ||
case err := <-programErr: | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
os.Exit(0) | ||
} | ||
|
||
type ( | ||
writeMsg string | ||
) | ||
|
||
type scroll struct { | ||
logview *logview.Model | ||
} | ||
|
||
func newScroll() *scroll { | ||
return &scroll{logview.New()} | ||
} | ||
|
||
var _ tea.Model = &scroll{} | ||
|
||
func (t *scroll) Init() tea.Cmd { return t.logview.Init() } | ||
|
||
func (t *scroll) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
switch msg := msg.(type) { | ||
case tea.WindowSizeMsg: | ||
t.logview.SetDimensions(msg.Width, msg.Height) | ||
return t, nil | ||
case writeMsg: | ||
t.logview.Write(string(msg)) | ||
return t, nil | ||
} | ||
model, cmd := t.logview.Update(msg) | ||
t.logview = model.(*logview.Model) | ||
return t, cmd | ||
} | ||
|
||
func (t *scroll) View() string { return t.logview.View() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"os" | ||
"time" | ||
) | ||
|
||
type Sink func(string) | ||
|
||
func (sink Sink) tailStdin() error { | ||
sc := bufio.NewScanner(os.Stdin) | ||
defer os.Stdin.Close() | ||
for { | ||
if !sc.Scan() { | ||
if err := sc.Err(); err != nil { | ||
return err | ||
} else { | ||
sink("EOF\n") | ||
} | ||
break | ||
} | ||
sink(sc.Text() + "\n") | ||
} | ||
return nil | ||
} | ||
|
||
func (sink Sink) tailFile(filename string) error { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
reader := bufio.NewReader(file) | ||
for { | ||
bs, err := io.ReadAll(reader) | ||
if err != nil { | ||
return err | ||
} | ||
sink(string(bs)) | ||
time.Sleep(time.Millisecond * 32) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.