Files
nexus/internal/models/defaults.go
T
andy c98ace2396 Add GitHub connection type — repo viewer with org grouping and auto-refresh
New protocol type 'github' for browsing repositories via the GitHub REST API.
Creates a non-terminal panel showing repos grouped by owner/org, sorted by
last commit date (newest first), with search filtering and auto-refresh.

Backend:
- ProtocolGitHub constant and GitHubConfig/GitHubRepo model structs
- New internal/githubclient package (REST API, pagination, token validation)
- Session manager connectGitHub() with periodic refresh goroutine
- API surface: RefreshGitHubRepos() for on-demand refresh
- Token stored via existing credential infrastructure (keychain/vault)

Frontend:
- GitHub tab in profile editor with API URL and token storage fields
- New github.js viewer component (grouped repos, badges, language dots)
- github.css with charcoal-themed repo cards and org headers
- Protocol colour tokens, tab badge, sidebar indicator for GitHub
- Event wiring for session:github:repos and session:github:error
- Cleanup on tab close

Supports GitHub Enterprise via configurable API base URL.
2026-04-16 00:00:00 +01:00

112 lines
2.8 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
)
// Default port numbers for each protocol.
const (
DefaultSSHPort = 22
DefaultTelnetPort = 23
DefaultRAWPort = 23
DefaultGitHubPort = 443
)
// Default timeout values (in seconds).
const (
DefaultConnectTimeout = 30
DefaultReadTimeout = 0 // no timeout
)
// Default terminal rendering settings.
const (
DefaultScrollback = 10000
DefaultFontSize = 14
DefaultFontFamily = "JetBrains Mono, Menlo, Monaco, Consolas, monospace"
DefaultCursorStyle = "block"
DefaultTerminalType = "xterm-256color"
)
// Default SSH keepalive settings.
const (
DefaultKeepaliveInterval = 30
DefaultKeepaliveCountMax = 3
)
// DefaultAppPreferences returns sensible default application preferences.
func DefaultAppPreferences() AppPreferences {
return AppPreferences{
Theme: "dark",
DefaultProtocol: string(ProtocolSSH),
ConfirmOnClose: true,
ConfirmOnDisconnect: true,
ShowStatusBar: true,
SidebarWidth: 280,
DefaultFontFamily: DefaultFontFamily,
DefaultFontSize: DefaultFontSize,
DefaultScrollback: DefaultScrollback,
DefaultCursorStyle: DefaultCursorStyle,
}
}
// NewProfile creates a new Profile with sensible defaults for the given protocol.
func NewProfile(protocol Protocol) Profile {
now := time.Now()
p := Profile{
ID: uuid.New().String(),
Protocol: protocol,
Tags: []string{},
ConnectTimeout: DefaultConnectTimeout,
ReadTimeout: DefaultReadTimeout,
TerminalFontFamily: DefaultFontFamily,
TerminalFontSize: DefaultFontSize,
TerminalScrollback: DefaultScrollback,
TerminalCursorStyle: DefaultCursorStyle,
CreatedAt: now,
UpdatedAt: now,
}
switch protocol {
case ProtocolSSH:
p.Port = DefaultSSHPort
p.SSH = &SSHConfig{
AuthMethods: []string{"publickey", "password", "keyboard-interactive"},
SecretMode: SecretModeSaved,
KeySecretMode: SecretModeSaved,
HostKeyPolicy: HostKeyAsk,
TerminalType: DefaultTerminalType,
KeepaliveInterval: DefaultKeepaliveInterval,
KeepaliveCountMax: DefaultKeepaliveCountMax,
JumpHosts: []JumpHost{},
EnvVars: map[string]string{},
}
case ProtocolTelnet:
p.Port = DefaultTelnetPort
p.Telnet = &TelnetConfig{
LocalEcho: false,
LineEnding: LineEndingCRLF,
TerminalType: DefaultTerminalType,
Encoding: "utf-8",
}
case ProtocolRAW:
p.Port = DefaultRAWPort
p.RAW = &RAWConfig{
LineEnding: LineEndingCRLF,
Encoding: "utf-8",
PayloadPresets: []PayloadPreset{},
}
case ProtocolGitHub:
p.Port = DefaultGitHubPort
p.Host = "github.com"
p.GitHub = &GitHubConfig{
BaseURL: "https://api.github.com",
SecretMode: SecretModeSaved,
RefreshIntervalSecs: 300,
}
}
return p
}