Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: terminal user interface * feat: bare bones interactive tui * feat: terminal user interface with bubbletea * feat: inspect mode for table results Co-authored-by: brittonhayes <brittonhayes@users.noreply.github.com>
- Loading branch information
1 parent
e5dfe46
commit b7ed81a
Showing
14 changed files
with
542 additions
and
6 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 |
---|---|---|
|
@@ -6,7 +6,6 @@ linters: | |
- godot | ||
- godox | ||
- dupl | ||
- exhaustive | ||
- funlen | ||
- gocritic | ||
- goprintffuncname | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
repos: | ||
- repo: https://github.com/golangci/golangci-lint | ||
rev: v1.44.2 | ||
rev: v1.45.0 | ||
hooks: | ||
- id: golangci-lint |
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
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
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,59 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/help" | ||
"github.com/charmbracelet/bubbles/key" | ||
tea "github.com/charmbracelet/bubbletea" | ||
) | ||
|
||
type keymap struct { | ||
Filter key.Binding | ||
Inspect key.Binding | ||
Start key.Binding | ||
Quit key.Binding | ||
Help key.Binding | ||
} | ||
|
||
func newKeyMap() keymap { | ||
k := keymap{ | ||
Inspect: key.NewBinding( | ||
key.WithKeys("i"), | ||
key.WithHelp("i", "inspect"), | ||
), | ||
Filter: key.NewBinding( | ||
key.WithKeys("f"), | ||
key.WithHelp("f", "filter"), | ||
), | ||
Start: key.NewBinding( | ||
key.WithKeys(tea.KeyEnter.String()), | ||
key.WithHelp("enter", "scan"), | ||
), | ||
Quit: key.NewBinding( | ||
key.WithKeys("ctrl+c", "q", tea.KeyEsc.String()), | ||
key.WithHelp("ctrl+c/esc/q", "quit"), | ||
), | ||
Help: key.NewBinding( | ||
key.WithKeys("?"), | ||
key.WithHelp("?", "help"), | ||
), | ||
} | ||
|
||
// Assert complies with help interface | ||
var _ help.KeyMap = k | ||
|
||
return k | ||
} | ||
|
||
// FullHelp returns keybindings for the expanded help view. It's part of the | ||
// key.Map interface. | ||
func (k keymap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.Help, k.Start, k.Inspect}, | ||
{k.Quit}, | ||
} | ||
} | ||
|
||
// ShortHelp returns keybindings for the short help view. | ||
func (k keymap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.Help, k.Start, k.Inspect, k.Quit} | ||
} |
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,118 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/brittonhayes/pillager/pkg/hunter" | ||
"github.com/brittonhayes/pillager/pkg/tui/style" | ||
"github.com/charmbracelet/bubbles/help" | ||
"github.com/charmbracelet/bubbles/spinner" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/evertras/bubble-table/table" | ||
"github.com/zricethezav/gitleaks/v8/report" | ||
"golang.org/x/term" | ||
) | ||
|
||
type model struct { | ||
keymap keymap | ||
loading loading | ||
header header | ||
body body | ||
help help.Model | ||
table table.Model | ||
|
||
hunter *hunter.Hunter | ||
results []report.Finding | ||
err error | ||
|
||
width int | ||
height int | ||
} | ||
|
||
type loading struct { | ||
active bool | ||
spinner spinner.Model | ||
} | ||
|
||
type header struct { | ||
title string | ||
subtitle string | ||
} | ||
|
||
type selected struct { | ||
visible bool | ||
text string | ||
} | ||
|
||
type body struct { | ||
toast string | ||
selected selected | ||
message string | ||
} | ||
|
||
type resultsMsg struct{ results []report.Finding } | ||
|
||
type errMsg struct{ err error } | ||
|
||
func (e errMsg) Error() string { | ||
return fmt.Sprintf("🔥 Uh oh! Well that's not good. Looks like something went wrong and the application has exited: \n\n%s\n\n%s", style.Error.Render(e.Error()), "Press [q] to quit.") | ||
} | ||
|
||
func NewModel(hunt *hunter.Hunter) model { | ||
width, height, err := term.GetSize(int(os.Stdout.Fd())) | ||
if err != nil { | ||
width = 80 | ||
height = 24 | ||
} | ||
|
||
// Create table model | ||
t := newTable(width) | ||
// Create keymap | ||
k := newKeyMap() | ||
// Create loading spinner. | ||
s := newSpinner() | ||
// Create help model | ||
h := help.New() | ||
|
||
m := model{ | ||
hunter: hunt, | ||
header: header{ | ||
title: "Pillager", | ||
subtitle: "Hunt inside the file system for valuable information", | ||
}, | ||
table: t, | ||
body: body{ | ||
message: "", | ||
}, | ||
help: h, | ||
loading: loading{ | ||
active: false, | ||
spinner: s, | ||
}, | ||
keymap: k, | ||
width: width, | ||
height: height, | ||
} | ||
|
||
return m | ||
} | ||
|
||
func (m model) Dimensions() (int, int) { | ||
return m.width, m.height | ||
} | ||
|
||
func startScan(h *hunter.Hunter) tea.Cmd { | ||
return func() tea.Msg { | ||
h.Debug = false | ||
h.Verbose = false | ||
results, err := h.Hunt() | ||
if err != nil { | ||
// There was an error making our request. Wrap the error we received | ||
// in a message and return it. | ||
return errMsg{err} | ||
} | ||
|
||
return resultsMsg{results} | ||
} | ||
} |
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,17 @@ | ||
package model | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/brittonhayes/pillager/pkg/tui/style" | ||
"github.com/charmbracelet/bubbles/spinner" | ||
) | ||
|
||
func newSpinner() spinner.Model { | ||
// Create loading spinner. | ||
s := spinner.NewModel() | ||
s.Spinner = spinner.Dot | ||
s.Style = style.Spinner | ||
s.HideFor = 250 * time.Millisecond | ||
return s | ||
} |
Oops, something went wrong.