menu

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderANSIArtToLines

func RenderANSIArtToLines(text string, width, height int) []string

RenderANSIArtToLines takes ANSI art text and renders it to scrollable lines The text is rendered into a virtual buffer where cursor positioning is relative to the buffer, not the terminal screen. This allows ANSI art with absolute positioning to display correctly.

Types

type ANSICell

type ANSICell struct {
	Char  byte   // Keep as byte to preserve CP437 encoding
	Style string // ANSI escape sequence for this cell's style
}

ANSICell represents a single character cell with its attributes

type ANSIRenderer

type ANSIRenderer struct {
	Width        int
	Height       int
	Buffer       [][]ANSICell
	CursorX      int
	CursorY      int
	CurrentStyle string
}

ANSIRenderer renders ANSI art into a 2D buffer

func NewANSIRenderer

func NewANSIRenderer(width, height int) *ANSIRenderer

NewANSIRenderer creates a new renderer with given dimensions

func (*ANSIRenderer) ExtractLines

func (r *ANSIRenderer) ExtractLines() []string

ExtractLines converts the buffer into an array of strings with ANSI codes

func (*ANSIRenderer) Render

func (r *ANSIRenderer) Render(text string)

Render processes ANSI text and renders it into the buffer

type CommandRecord

type CommandRecord struct {
	Keys         string `json:"KEYS"`                    // Input key(s) to trigger command (space-separated)
	Command      string `json:"CMD"`                     // Command string (e.g., GOTO:MENU, RUN:PROG, LOGOFF)
	ACS          string `json:"ACS"`                     // Access Control String
	Hidden       bool   `json:"HIDDEN"`                  // Whether the command is hidden (H flag)
	AutoRun      string `json:"AUTORUN,omitempty"`       // Type of auto-run (e.g., "ONCE_PER_SESSION")
	NodeActivity string `json:"NODE_ACTIVITY,omitempty"` // Descriptive activity text for Who's Online
}

CommandRecord holds the definition of a single command from a .CFG file.

func LoadCommands

func LoadCommands(menuName string, configPath string) ([]CommandRecord, error)

LoadCommands reads a .CFG file (assumed JSON) for the given menu name.

func (*CommandRecord) GetHidden

func (cr *CommandRecord) GetHidden() bool

GetHidden is a helper method to safely access the Hidden field. (Kept for potential future use, though direct access is fine)

type DoorCtx

type DoorCtx struct {
	Executor         *MenuExecutor
	Session          ssh.Session
	Terminal         *term.Terminal
	User             doorUserInfo
	NodeNumber       int
	SessionStartTime time.Time
	OutputMode       ansi.OutputMode
	Config           config.DoorConfig
	DoorName         string
	// Pre-computed values
	NodeNumStr  string
	PortStr     string
	TimeLeftMin int
	TimeLeftStr string
	BaudStr     string
	UserIDStr   string
	Subs        map[string]string
}

DoorCtx is the actual context used throughout door_handler.go.

type IPLockoutChecker

type IPLockoutChecker interface {
	IsIPLockedOut(ip string) (bool, time.Time, int)
	RecordFailedLoginAttempt(ip string) bool
	ClearFailedLoginAttempts(ip string)
}

IPLockoutChecker defines the interface for IP-based authentication lockout. This allows the menu system to check and record failed login attempts without depending on the specific implementation in main.

type LightbarOption

type LightbarOption struct {
	X, Y           int    // Screen coordinates
	Text           string // Display text
	HotKey         string // Command hotkey
	ReturnValue    string // Return value (often same as hotkey, but can differ)
	HighlightColor int    // Color code when highlighted
	RegularColor   int    // Color code when not highlighted
}

LightbarOption represents a single option in a lightbar menu

type MenuExecutor struct {
	ConfigPath      string                        // DEPRECATED: Use MenuSetPath + "/cfg" or RootConfigPath
	AssetsPath      string                        // DEPRECATED: Use MenuSetPath + "/ansi" or RootAssetsPath
	MenuSetPath     string                        // NEW: Path to the active menu set (e.g., "menus/v3")
	RootConfigPath  string                        // NEW: Path to global configs (e.g., "configs")
	RootAssetsPath  string                        // NEW: Path to global assets (e.g., "assets")
	RunRegistry     map[string]RunnableFunc       // Map RUN: targets to functions (Use local RunnableFunc)
	DoorRegistry    map[string]config.DoorConfig  // Map DOOR: targets to configurations
	OneLiners       []string                      // Loaded oneliners (Consider if these should be menu-set specific)
	LoadedStrings   config.StringsConfig          // Loaded global strings configuration
	Theme           config.ThemeConfig            // Loaded theme configuration
	ServerCfg       config.ServerConfig           // Server configuration (NEW)
	MessageMgr      *message.MessageManager       // <-- ADDED FIELD
	FileMgr         *file.FileManager             // <-- ADDED FIELD: File manager instance
	ConferenceMgr   *conference.ConferenceManager // Conference grouping manager
	IPLockoutCheck  IPLockoutChecker              // IP-based authentication lockout checker
	LoginSequence   []config.LoginItem            // Configurable login sequence from login.json
	SessionRegistry *session.SessionRegistry      // Session registry for who's online
	ChatRoom        *chat.ChatRoom                // Global teleconference chat room
	Protocols       []transfer.ProtocolConfig     // Loaded transfer protocol configurations
	// contains filtered or unexported fields
}

MenuExecutor handles the loading and execution of ViSiON/2 menus.

func NewExecutor

func NewExecutor(menuSetPath, rootConfigPath, rootAssetsPath string, oneLiners []string, doorRegistry map[string]config.DoorConfig, loadedStrings config.StringsConfig, theme config.ThemeConfig, serverCfg config.ServerConfig, msgMgr *message.MessageManager, fileMgr *file.FileManager, confMgr *conference.ConferenceManager, ipLockoutCheck IPLockoutChecker, loginSequence []config.LoginItem, sessionRegistry *session.SessionRegistry, chatRoom *chat.ChatRoom, protocols []transfer.ProtocolConfig) *MenuExecutor

NewExecutor creates a new MenuExecutor.

func (e *MenuExecutor) GetDoorConfig(name string) (config.DoorConfig, bool)

GetDoorConfig atomically retrieves a door configuration.

func (e *MenuExecutor) GetLoginSequence() []config.LoginItem

GetLoginSequence atomically retrieves the login sequence.

func (e *MenuExecutor) GetServerConfig() config.ServerConfig

GetServerConfig atomically retrieves the server configuration.

func (e *MenuExecutor) GetStrings() config.StringsConfig

GetStrings atomically retrieves the strings configuration.

func (e *MenuExecutor) GetTheme() config.ThemeConfig

GetTheme atomically retrieves the theme configuration.

func (e *MenuExecutor) PromptYesNo(s ssh.Session, terminal *term.Terminal, promptText string, outputMode ansi.OutputMode, nodeNumber int, termWidth int, termHeight int, defaultYes bool) (bool, error)

PromptYesNo is the canonical Yes/No prompt entrypoint for menu flows. defaultYes controls which option is pre-selected (true = Yes, false = No). Keep all call sites routed here so prompt behavior can be changed in one place.

func (e *MenuExecutor) Run(s ssh.Session, terminal *term.Terminal, userManager *user.UserMgr, currentUser *user.User, startMenu string, nodeNumber int, sessionStartTime time.Time, autoRunLog types.AutoRunTracker, outputMode ansi.OutputMode, currentAreaName string, termWidth int, termHeight int) (string, *user.User, error)

Run executes the menu logic for a given starting menu name. Reverted s parameter back to ssh.Session Added outputMode parameter Added currentAreaName parameter

func (e *MenuExecutor) RunLoginSequence(s ssh.Session, terminal *term.Terminal, userManager *user.UserMgr, currentUser *user.User, nodeNumber int, sessionStartTime time.Time, outputMode ansi.OutputMode, termWidth int, termHeight int) (string, error)

RunLoginSequence is the exported entry point for running the login sequence from main.go. Returns the next menu name to enter (e.g., "MAIN") or "LOGOFF".

func (e *MenuExecutor) RunMatrixScreen(
	s ssh.Session,
	terminal *term.Terminal,
	userManager *user.UserMgr,
	nodeNumber int,
	outputMode ansi.OutputMode,
	termWidth int,
	termHeight int,
) (string, error)

RunMatrixScreen displays the pre-login matrix menu and returns the selected action. Actions: "LOGIN", "NEWUSER", "CHECKACCESS", "DISCONNECT" Called from main.go sessionHandler before the login loop for telnet users. Uses standard .BAR/.CFG menu files (PDMATRIX.BAR, PDMATRIX.CFG) for configuration.

func (e *MenuExecutor) SetDoorRegistry(doors map[string]config.DoorConfig)

SetDoorRegistry atomically updates the door registry.

func (e *MenuExecutor) SetLoginSequence(sequence []config.LoginItem)

SetLoginSequence atomically updates the login sequence.

func (e *MenuExecutor) SetServerConfig(serverCfg config.ServerConfig)

SetServerConfig atomically updates the server configuration.

func (e *MenuExecutor) SetStrings(strings config.StringsConfig)

SetStrings atomically updates the strings configuration.

func (e *MenuExecutor) SetTheme(theme config.ThemeConfig)

SetTheme atomically updates the theme configuration.

type MenuRecord struct {
	// Fields expected from JSON .MNU
	ClrScrBefore bool   `json:"CLR"`
	ClsScrBefore bool   `json:"CLS"`
	UsePrompt    bool   `json:"USEPROMPT"`
	Prompt1      string `json:"PROMPT1"`
	Prompt2      string `json:"PROMPT2"`
	Fallback     string `json:"FALLBACK"`
	ACS          string `json:"ACS"`
	Password     string `json:"PASS"`
}

MenuRecord adapted for JSON parsing of .MNU files. Assumes JSON keys match the tags.

func LoadMenu

func LoadMenu(menuName string, configPath string) (*MenuRecord, error)

LoadMenu reads a .MNU file (assumed JSON) for the given menu name.

func (mr *MenuRecord) GetClrScrBefore() bool

Getters for boolean fields (using the JSON bool types directly)

func (mr *MenuRecord) GetUsePrompt() bool

type MessageHeaderTemplate

type MessageHeaderTemplate struct {
	Number      int    // Template number (e.g., 1, 2, 15)
	Filename    string // Full filename (e.g., "MSGHDR.15.ans")
	DisplayName string // Human-readable name (e.g., "Header Style 15")
}

MessageHeaderTemplate represents a discovered message header template file.

type MessageListEntry

type MessageListEntry struct {
	MsgNum    int
	Subject   string
	From      string
	To        string
	IsPrivate bool
	IsRead    bool // Based on JAM lastread pointer
}

MessageListEntry represents a single message in the list view

type MessageListState

type MessageListState struct {
	AreaID        int
	TotalMessages int
	Entries       []MessageListEntry
	CurrentPage   int
	ItemsPerPage  int
	SelectedIndex int // Index within current page (0-based)
	LastRead      int
}

MessageListState manages the list display and navigation

type MsgLightbarOption

type MsgLightbarOption struct {
	Label   string // Display text including padding, e.g. " Next "
	HotKey  byte   // Single-char hotkey, e.g. 'N'
	LoColor int    // Override unselected color (0 = use default loColor)
}

MsgLightbarOption defines an option in the message reader lightbar.

type PlaceholderMatch

type PlaceholderMatch struct {
	Code      string         // Single letter (T, F, S, etc.)
	Width     int            // 0 = no width constraint
	AutoWidth bool           // true = use auto-calculated width from context
	Align     ansi.Alignment // AlignLeft (default), AlignRight, AlignCenter
	FullMatch string         // Complete matched text "@T###@"
	StartPos  int            // Byte offset in template
	EndPos    int            // End byte offset
}

PlaceholderMatch represents a parsed placeholder from a template.

type RunnableFunc

type RunnableFunc func(e *MenuExecutor, s ssh.Session, terminal *term.Terminal, userManager *user.UserMgr, currentUser *user.User, nodeNumber int, sessionStartTime time.Time, args string, outputMode ansi.OutputMode, termWidth int, termHeight int) (authenticatedUser *user.User, nextAction string, err error)

RunnableFunc defines the signature for functions executable via RUN: Returns: authenticatedUser, nextAction (e.g., "GOTO:MENU"), err

type ScanConfig

type ScanConfig struct {
	ScanDate       int64 // -1 = new only, 0 = all, >0 = unix timestamp
	SearchTo       string
	SearchFrom     string
	RangeStart     int
	RangeEnd       int
	UpdatePointers bool
	WhichAreas     int // 1=tagged/marked, 2=all in conference, 3=current only
	Aborted        bool
}

ScanConfig holds the scan parameters configured by GetScanType.

Jump to

Keyboard shortcuts

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