tui

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// General styles
	AppStyle = lipgloss.NewStyle().
				Margin(1, 2)

	// Header styles
	HeaderStyle = lipgloss.NewStyle().
				Background(primaryColor).
				Foreground(textColor).
				Bold(true).
				Padding(0, 1).
				MarginBottom(1)

	// Banner style
	BannerStyle = lipgloss.NewStyle().
				Foreground(primaryColor).
				Bold(true)

	// Title styles
	TitleStyle = lipgloss.NewStyle().
				Foreground(primaryColor).
				Bold(true).
				MarginBottom(1)

	SubtitleStyle = lipgloss.NewStyle().
					Foreground(secondaryColor).
					Bold(true)

	// Box styles
	BoxStyle = lipgloss.NewStyle().
				BorderStyle(lipgloss.RoundedBorder()).
				BorderForeground(primaryColor).
				Padding(1)

	// Input styles
	InputLabelStyle = lipgloss.NewStyle().
					Foreground(secondaryColor).
					Bold(true)

	// Message styles
	ErrorStyle = lipgloss.NewStyle().
				Foreground(errorColor).
				BorderStyle(lipgloss.RoundedBorder()).
				BorderForeground(errorColor).
				Padding(1)

	SuccessStyle = lipgloss.NewStyle().
					Foreground(successColor).
					BorderStyle(lipgloss.RoundedBorder()).
					BorderForeground(successColor).
					Padding(1)

	WarningStyle = lipgloss.NewStyle().
					Foreground(warningColor).
					BorderStyle(lipgloss.RoundedBorder()).
					BorderForeground(warningColor).
					Padding(1)

	InfoStyle = lipgloss.NewStyle().
				Foreground(infoColor).
				BorderStyle(lipgloss.RoundedBorder()).
				BorderForeground(infoColor).
				Padding(1)

	// Help style
	HelpStyle = lipgloss.NewStyle().
				Foreground(mutedColor)

	// Menu styles
	MenuTitleStyle = lipgloss.NewStyle().
					Background(primaryColor).
					Foreground(textColor).
					Padding(0, 1)

	// Spinner styles
	SpinnerStyle = lipgloss.NewStyle().
					Foreground(primaryColor).
					Bold(true)

	// Command output style
	CommandOutputStyle = lipgloss.NewStyle().
						BorderStyle(lipgloss.RoundedBorder()).
						BorderForeground(primaryColor).
						Padding(1)

	// Loading indicator style
	LoadingStyle = lipgloss.NewStyle().
					Foreground(secondaryColor).
					Bold(true)
	// Process list styles
	ProcessListStyle = lipgloss.NewStyle().
						BorderStyle(lipgloss.RoundedBorder()).
						BorderForeground(primaryColor).
						Padding(1)

	ProcessHeaderStyle = lipgloss.NewStyle().
						Foreground(secondaryColor).
						Bold(true)

	ProcessSelectedStyle = lipgloss.NewStyle().
							Foreground(primaryColor).
							Bold(true)

	// Footer styles
	FooterStyle = lipgloss.NewStyle().
				Foreground(mutedColor)

	ListStyle = list.DefaultItemStyles{
		NormalTitle:   lipgloss.NewStyle().Foreground(lipgloss.Color("#F7CD82")),
		NormalDesc:    lipgloss.NewStyle().Foreground(lipgloss.Color("#5B584F")),
		SelectedTitle: lipgloss.NewStyle().Foreground(lipgloss.Color("#F2F1EF")).Bold(true),
		SelectedDesc:  lipgloss.NewStyle().Foreground(lipgloss.Color("#E0D5AD")),
	}

	// Table styles
	TableHeaderStyle = lipgloss.NewStyle().
						Foreground(primaryColor).
						Bold(true)

	TableBorderStyle = lipgloss.NewStyle().
						Foreground(mutedColor)

	TableRowStyle = lipgloss.NewStyle().
					Foreground(textColor)

	TableSelectedRowStyle = lipgloss.NewStyle().
							Foreground(primaryColor).
							Bold(true)
)
View Source
var ExploitTableData []ExploitProcess
View Source
var Keys = keyMap{
	Up: key.NewBinding(
		key.WithKeys("up", "k"),
		key.WithHelp("↑/k", "move up"),
	),
	Down: key.NewBinding(
		key.WithKeys("down", "j"),
		key.WithHelp("↓/j", "move down"),
	),
	Enter: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "select"),
	),
	Quit: key.NewBinding(
		key.WithKeys("q", "ctrl+c"),
		key.WithHelp("q", "quit"),
	),
	Back: key.NewBinding(
		key.WithKeys("esc"),
		key.WithHelp("esc", "back"),
	),
	Tab: key.NewBinding(
		key.WithKeys("tab"),
		key.WithHelp("tab", "next input"),
	),
	Submit: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "submit"),
	),
	NextInput: key.NewBinding(
		key.WithKeys("tab"),
		key.WithHelp("tab", "next input"),
	),
	PrevInput: key.NewBinding(
		key.WithKeys("shift+tab"),
		key.WithHelp("shift+tab", "previous input"),
	),
}

Keys defines the keybindings

Functions

func CreateForm

func CreateForm(command string) ([]textinput.Model, []string)

CreateForm creates input fields for a specific command

func DimmedStyle

func DimmedStyle(text string) string

DimmedStyle returns a dimmed version of the given text

func ErrorText

func ErrorText(text string) string

ErrorText returns an error-styled version of the given text

func GetSelectedItem

func GetSelectedItem(menu list.Model) (menuItem, bool)

GetSelectedItem returns the selected item from the given menu

func HighlightStyle

func HighlightStyle(text string) string

HighlightStyle returns a highlighted version of the given text

func InfoText

func InfoText(text string) string

InfoText returns an info-styled version of the given text

func InitializeMenus

func InitializeMenus() (list.Model, list.Model, list.Model)

InitializeMenus initializes all the menus for the TUI

func IsDirectCommand

func IsDirectCommand(command string) bool

IsDirectCommand checks if the command can be executed directly without input

func IsNavigationCommand

func IsNavigationCommand(command string) bool

IsNavigationCommand checks if the command is a navigation command

func NavigateForm(inputs []textinput.Model, currentFocus int, direction int) int

NavigateForm handles navigation within forms

func RequiresInput

func RequiresInput(command string) bool

RequiresInput checks if the command requires user input

func StartTUI

func StartTUI(banner string) error

StartTUI launches the TUI application

func SuccessText

func SuccessText(text string) string

SuccessText returns a success-styled version of the given text

func UpdateFormInputs

func UpdateFormInputs(inputs []textinput.Model, focusIndex int, msg tea.Msg) ([]textinput.Model, tea.Cmd)

UpdateFormInputs updates form inputs with a tea.Msg

func UpdateMenuSize

func UpdateMenuSize(mainMenu, configMenu, exploitMenu *list.Model, width, height int)

UpdateMenuSize updates the size of all menus

func ValidateForm

func ValidateForm(command string, inputs []textinput.Model) error

ValidateForm validates form inputs for a specific command

func WarningText

func WarningText(text string) string

WarningText returns a warning-styled version of the given text

Types

type CommandHandler

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

CommandHandler manages command execution and handling

func NewCommandHandler

func NewCommandHandler() *CommandHandler

NewCommandHandler creates a new command handler

func (*CommandHandler) HandleCommand

func (h *CommandHandler) HandleCommand(command string, formData *FormData) tea.Cmd

HandleCommand processes a command and returns appropriate tea.Cmd

func (*CommandHandler) HandleNavigation

func (*CommandHandler) HandleNavigation(command string, model *Model) (*Model, tea.Cmd)

HandleNavigation processes navigation commands

func (*CommandHandler) ProcessFormSubmission

func (h *CommandHandler) ProcessFormSubmission(model *Model) (*Model, tea.Cmd)

ProcessFormSubmission handles form submission

func (*CommandHandler) SetupFormForCommand

func (h *CommandHandler) SetupFormForCommand(model *Model, command string)

SetupFormForCommand prepares form inputs for a specific command

type CommandOutput

type CommandOutput struct {
	Output string
	Error  error
}

CommandOutput represents the result of a command execution

type CommandRunner

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

CommandRunner handles the execution of commands for the TUI

func NewCommandRunner

func NewCommandRunner() *CommandRunner

NewCommandRunner creates a new command runner

func (*CommandRunner) CloseExploitOutput

func (r *CommandRunner) CloseExploitOutput()

CloseExploitOutput closes the exploit output channel

func (*CommandRunner) ExecuteCommand

func (*CommandRunner) ExecuteCommand(command string, args ...string) (string, error)

ExecuteCommand executes a generic shell command and returns its output

func (*CommandRunner) ExecuteConfigCommand

func (*CommandRunner) ExecuteConfigCommand(subcommand string) (string, error)

ExecuteConfigCommand executes configuration-related commands

func (*CommandRunner) ExecuteConfigUpdate

func (*CommandRunner) ExecuteConfigUpdate(host, port, username string, useHTTPS bool) (string, error)

ExecuteConfigUpdate handles the config update command

func (*CommandRunner) ExecuteExploitCommand

func (*CommandRunner) ExecuteExploitCommand(subcommand string) (string, error)

ExecuteExploitCommand executes exploit-related commands

func (*CommandRunner) ExecuteExploitCreate

func (*CommandRunner) ExecuteExploitCreate(name string) (string, error)

ExecuteExploitCreate handles creating an exploit template

func (*CommandRunner) ExecuteExploitRemove

func (*CommandRunner) ExecuteExploitRemove(name string) (string, error)

ExecuteExploitRemove handles removing an exploit template

func (*CommandRunner) ExecuteExploitRun

func (r *CommandRunner) ExecuteExploitRun(
	exploitPath, servicePort string,
	tickTime, threadCount string,
) (string, error)

func (*CommandRunner) ExecuteExploitStop

func (*CommandRunner) ExecuteExploitStop(pid string) (string, error)

ExecuteExploitStop handles stopping a running exploit

func (*CommandRunner) ExecuteExploitTest

func (r *CommandRunner) ExecuteExploitTest(
	exploitPath, servicePort string,
	tickTime, threadCount string,
) (string, error)

func (*CommandRunner) ExecuteLogin

func (*CommandRunner) ExecuteLogin(password, host, username string, port uint16, https bool) (string, error)

ExecuteLogin handles the login command

func (*CommandRunner) GetCurrentExploitPID

func (r *CommandRunner) GetCurrentExploitPID() int

GetCurrentExploitPID returns the PID of the currently running exploit

func (*CommandRunner) GetExploitOutputCmd

func (r *CommandRunner) GetExploitOutputCmd() tea.Cmd

GetExploitOutputCmd returns a tea.Cmd that streams exploit output

func (*CommandRunner) GetRunningExploits

func (*CommandRunner) GetRunningExploits() ([]ExploitProcess, error)

GetRunningExploits returns a list of running exploit processes

type ExploitOutput

type ExploitOutput struct {
	Content string
	Error   error
	PID     int
}

ExploitOutput represents output from a running exploit

type ExploitProcess

type ExploitProcess struct {
	ID   int
	Name string
	PID  int
}

ExploitProcess represents a running exploit process

type FormData

type FormData struct {
	Fields map[string]string
}

FormData represents form input data

func GetFormData

func GetFormData(inputs []textinput.Model, labels []string) FormData

GetFormData extracts data from form inputs

type Model

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

Model is the main TUI model

func New

func New(banner string) Model

New creates a new TUI model

func (*Model) AppendCommandOutput

func (m *Model) AppendCommandOutput(output string)

AppendCommandOutput appends to the existing command output

func (*Model) ClearError

func (m *Model) ClearError()

ClearError clears any error message

func (*Model) GetActiveView

func (m *Model) GetActiveView() string

GetActiveView returns the current active view

func (Model) GetExploitStreamCmd

func (m Model) GetExploitStreamCmd() tea.Cmd

GetExploitStreamCmd returns a command that periodically checks for exploit output

func (*Model) GetSelectedExploitFromTable

func (m *Model) GetSelectedExploitFromTable() *ExploitProcess

GetSelectedExploitFromTable returns the exploit process from the selected table row

func (*Model) GetSelectedProcess

func (m *Model) GetSelectedProcess() *ExploitProcess

GetSelectedProcess returns the currently selected exploit process

func (*Model) GetSelectedTableRow

func (m *Model) GetSelectedTableRow() table.Row

GetSelectedTableRow returns the currently selected table row

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the TUI

func (*Model) IsInputMode

func (m *Model) IsInputMode() bool

IsInputMode returns true if the model is in input mode

func (*Model) IsLoading

func (m *Model) IsLoading() bool

IsLoading returns true if the model is in loading state

func (*Model) IsProcessListVisible

func (m *Model) IsProcessListVisible() bool

IsProcessListVisible returns whether the process list is visible

func (*Model) IsRunningCommand

func (m *Model) IsRunningCommand() bool

IsRunningCommand returns true if a command is currently running

func (*Model) SelectNextProcess

func (m *Model) SelectNextProcess()

SelectNextProcess selects the next process in the list

func (*Model) SelectPreviousProcess

func (m *Model) SelectPreviousProcess()

SelectPreviousProcess selects the previous process in the list

func (*Model) SetActiveView

func (m *Model) SetActiveView(view string)

SetActiveView sets the active view

func (*Model) SetCommandOutput

func (m *Model) SetCommandOutput(output string)

SetCommandOutput sets the command output

func (*Model) SetError

func (m *Model) SetError(err error)

SetError sets an error message for the model

func (*Model) SetExploitProcesses

func (m *Model) SetExploitProcesses(processes []ExploitProcess)

SetExploitProcesses sets the list of running exploit processes

func (*Model) SetInputMode

func (m *Model) SetInputMode(state bool)

SetInputMode sets the input mode state

func (*Model) SetLoading

func (m *Model) SetLoading(state bool)

SetLoading sets the loading state

func (*Model) SetProcessListVisible

func (m *Model) SetProcessListVisible(visible bool)

SetProcessListVisible shows or hides the process selection list

func (*Model) SetRunningCommand

func (m *Model) SetRunningCommand(state bool)

SetRunningCommand sets the running command state

func (Model) SetupExploitTableCmd

func (m Model) SetupExploitTableCmd() tea.Cmd

SetupExploitTableCmd returns a command to update the exploit table with data

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles TUI state updates

func (Model) View

func (m Model) View() string

View renders the TUI

type TableUpdateMsg

type TableUpdateMsg struct {
	Rows []table.Row
	Show bool
}

TableUpdateMsg is a message to update the table data

type ViewRenderer

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

ViewRenderer handles all rendering operations for the TUI

func NewViewRenderer

func NewViewRenderer() *ViewRenderer

NewViewRenderer creates a new view renderer

func (*ViewRenderer) RenderView

func (r *ViewRenderer) RenderView(m *Model) string

RenderView renders the main view based on the model state

func (*ViewRenderer) SetSize

func (r *ViewRenderer) SetSize(width, height int)

SetSize updates the renderer's dimensions

Jump to

Keyboard shortcuts

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