mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 15:14:38 +00:00
47c2b6bed9
* Init attempt at tui with bubble tea. Co-authored-by: mcastorina <m.castorina93@gmail.com> * Add starting and source selection options Co-authored-by: mcastorina <m.castorina93@gmail.com> * Rewrite models into a state machine * Update source descriptions * Make subpages implement tea.Model * Rename page0 and page1 to be more descriptive * Adjust styling and adding color consts Co-authored-by: mcastorina <m.castorina93@gmail.com> * Add helper generic function to call Update and type cast * Setup plumbing for source configuration page * Use CLI introspection for source configuration (WIP) * Experiment with table view * Replace table with form fields Co-authored-by: mcastorina <m.castorina93@gmail.com> * Change 🔒 to 💸 * Copy components from soft-serve Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Copy styles from soft-serve Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Copy common from soft-serve Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Refactor into pages This is still a WIP, but the main structure is there. Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Trying out selector for wizard intro Co-authored-by: mcastorina <m.castorina93@gmail.com> * Use selector with custom View Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Change Item to be an enum Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Add link pages Co-authored-by: mcastorina <m.castorina93@gmail.com> * Update source select to use selector Co-authored-by: mcastorina <m.castorina93@gmail.com> * Delete source configure page and add blank tabs Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Add tab placeholder pages for configurationi Co-authored-by: mcastorina <m.castorina93@gmail.com> * Added headers and style to each tab Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Update with new sources * Remove kingpin attribute from SourceItem * Add basic form field and source structuring * Hookup git form fields with an underlying textinput component Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Update forms for git and github Co-authored-by: mcastorina <m.castorina93@gmail.com> * Add labels per text input * Add sources and adjust styling * add basic trufflehog configuration page * Add skip button to textinputs component * Emit and handle textinputs skip/submit button commands * Don't quit when q is pressed on the sourceConfigurePage * Build trufflehog command based on source config vals Co-authored-by: mcastorina <m.castorina93@gmail.com> * Build flags based on truffle config inputs * Update summary section * Add generated truffle fields Co-authored-by: mcastorina <m.castorina93@gmail.com> * update summary to correctly print info * Go back a page when escape key is pressed * WIP run page list Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Allow running trufflehog from the run page Co-authored-by: hxnyk <8292703+hxnyk@users.noreply.github.com> * Add option to view help docs Co-authored-by: mcastorina <m.castorina93@gmail.com> * comment out unused styles and remove unused types * Capitalize H in TruffleHog * remove unneeded fmt.Sprintf --------- Co-authored-by: mcastorina <m.castorina93@gmail.com>
97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
package viewport
|
|
|
|
import (
|
|
"github.com/charmbracelet/bubbles/viewport"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/trufflesecurity/trufflehog/v3/pkg/tui/common"
|
|
)
|
|
|
|
// Viewport represents a viewport component.
|
|
type Viewport struct {
|
|
common common.Common
|
|
*viewport.Model
|
|
}
|
|
|
|
// New returns a new Viewport.
|
|
func New(c common.Common) *Viewport {
|
|
vp := viewport.New(c.Width, c.Height)
|
|
vp.MouseWheelEnabled = true
|
|
return &Viewport{
|
|
common: c,
|
|
Model: &vp,
|
|
}
|
|
}
|
|
|
|
// SetSize implements common.Component.
|
|
func (v *Viewport) SetSize(width, height int) {
|
|
v.common.SetSize(width, height)
|
|
v.Model.Width = width
|
|
v.Model.Height = height
|
|
}
|
|
|
|
// Init implements tea.Model.
|
|
func (v *Viewport) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
// Update implements tea.Model.
|
|
func (v *Viewport) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
vp, cmd := v.Model.Update(msg)
|
|
v.Model = &vp
|
|
return v, cmd
|
|
}
|
|
|
|
// View implements tea.Model.
|
|
func (v *Viewport) View() string {
|
|
return v.Model.View()
|
|
}
|
|
|
|
// SetContent sets the viewport's content.
|
|
func (v *Viewport) SetContent(content string) {
|
|
v.Model.SetContent(content)
|
|
}
|
|
|
|
// GotoTop moves the viewport to the top of the log.
|
|
func (v *Viewport) GotoTop() {
|
|
v.Model.GotoTop()
|
|
}
|
|
|
|
// GotoBottom moves the viewport to the bottom of the log.
|
|
func (v *Viewport) GotoBottom() {
|
|
v.Model.GotoBottom()
|
|
}
|
|
|
|
// HalfViewDown moves the viewport down by half the viewport height.
|
|
func (v *Viewport) HalfViewDown() {
|
|
v.Model.HalfViewDown()
|
|
}
|
|
|
|
// HalfViewUp moves the viewport up by half the viewport height.
|
|
func (v *Viewport) HalfViewUp() {
|
|
v.Model.HalfViewUp()
|
|
}
|
|
|
|
// ViewUp moves the viewport up by a page.
|
|
func (v *Viewport) ViewUp() []string {
|
|
return v.Model.ViewUp()
|
|
}
|
|
|
|
// ViewDown moves the viewport down by a page.
|
|
func (v *Viewport) ViewDown() []string {
|
|
return v.Model.ViewDown()
|
|
}
|
|
|
|
// LineUp moves the viewport up by the given number of lines.
|
|
func (v *Viewport) LineUp(n int) []string {
|
|
return v.Model.LineUp(n)
|
|
}
|
|
|
|
// LineDown moves the viewport down by the given number of lines.
|
|
func (v *Viewport) LineDown(n int) []string {
|
|
return v.Model.LineDown(n)
|
|
}
|
|
|
|
// ScrollPercent returns the viewport's scroll percentage.
|
|
func (v *Viewport) ScrollPercent() float64 {
|
|
return v.Model.ScrollPercent()
|
|
}
|