Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupLogs(retentionCount int)
- func ConfigureDebug(dir string)
- func ConfigureDialer(dialer *net.Dialer, customAddr string)
- func ConvertBytesToHumanReadable(bytes int64) string
- func CopyFile(src, dst string) error
- func CopyRedirectHeaders(dst, src *http.Request)
- func Debug(format string, args ...any)
- func DetermineFilename(rawurl string, resp *http.Response) (string, io.Reader, error)
- func EnsureAbsPath(path string) string
- func IsLoggingEnabled() bool
- func IsWindowsAbsPath(p string) bool
- func MapWindowsPathToDefaultDir(requestPath, defaultDir string) (string, bool)
- func Notify(title, message string)
- func OpenBrowser(url string) error
- func OpenContainingFolder(path string) error
- func OpenFile(path string) error
- func ReadURLsFromFile(filepath string) ([]string, error)
- func Run(executable string, args []string, env []string) error
- func Truncate(s string, limit int) string
- func TruncateFilename(name string) string
- func TruncateMiddle(s string, limit int) string
- func TruncateTwoLines(s string, width int) string
- func WrapText(text string, width int) string
Constants ¶
const MaxFilenameLength = 240
const NotificationAppName = "Surge"
Variables ¶
var SuppressNotifications bool
SuppressNotifications can be set to true to prevent desktop notifications. Tests should set this to true via TestMain or init() to avoid notification spam.
Functions ¶
func CleanupLogs ¶
func CleanupLogs(retentionCount int)
CleanupLogs removes old log files, keeping only the most recent retentionCount files
func ConfigureDebug ¶
func ConfigureDebug(dir string)
ConfigureDebug sets the directory for debug logs
func ConfigureDialer ¶ added in v0.8.0
ConfigureDialer modifies the provided net.Dialer to route all DNS lookups through the specified custom DNS server address. customAddr should include the port, e.g., "1.1.1.1:53".
func ConvertBytesToHumanReadable ¶
ConvertBytesToHumanReadable converts a given number of bytes into a human-readable format (e.g., KB, MB, GB).
func CopyRedirectHeaders ¶
CopyRedirectHeaders preserves all headers for same-origin redirects but strips sensitive headers (cookies, auth) for cross-domain redirects.
func DetermineFilename ¶
DetermineFilename extracts the filename from a URL and HTTP response, applying various heuristics. It returns the determined filename, a new io.Reader that includes any sniffed header bytes, and an error.
func EnsureAbsPath ¶
EnsureAbsPath takes a clean path and forces it to be absolute. If it fails to get absolute path (rare), it checks if it's already absolute, otherwise relies on the input.
func IsLoggingEnabled ¶ added in v0.7.7
func IsLoggingEnabled() bool
IsLoggingEnabled returns true if debug logging is configured This allows callers to skip expensive argument evaluation
func IsWindowsAbsPath ¶ added in v0.8.1
IsWindowsAbsPath reports whether p looks like a Windows absolute path even when running on a non-Windows host (for example inside Docker on Linux).
func MapWindowsPathToDefaultDir ¶ added in v0.8.1
MapWindowsPathToDefaultDir projects a Windows absolute client path onto a server-side default download directory by preserving only the suffix beneath the matching root folder name. Example:
C:/Users/me/Downloads/subdir -> /downloads/subdir
func OpenBrowser ¶ added in v0.8.0
OpenBrowser opens a URL in the system's default web browser.
func OpenContainingFolder ¶
OpenContainingFolder opens the containing folder of a file in the system's default file explorer.
func ReadURLsFromFile ¶
ReadURLsFromFile reads URLs from a file. Accepts one URL per line or whitespace-separated URLs, and ignores comments. Trailing-slash-only variants are treated as the same URL so batch imports behave consistently across CLI and TUI entry points.
func Run ¶ added in v0.8.4
Run executes an executable with the given arguments and environment. On Unix-like systems, it replaces the current process using syscall.Exec. On Windows, it starts a new process and exits the current one.
func Truncate ¶ added in v0.8.3
Truncate truncates a string to a maximum visual width and adds an ellipsis if needed.
func TruncateFilename ¶ added in v0.8.1
TruncateFilename ensures a filename does not exceed MaxFilenameLength while preserving the extension and being UTF-8 safe.
func TruncateMiddle ¶ added in v0.8.4
TruncateMiddle truncates a string in the middle to a maximum visual width. It is ANSI-aware.
func TruncateTwoLines ¶ added in v0.8.4
TruncateTwoLines middle-truncates a string to fit in at most 2 lines of a given width. It uses character-based wrapping (ignoring word boundaries) to maximize space usage.
Types ¶
This section is empty.