> ## Documentation Index
> Fetch the complete documentation index at: https://ziva.zeleza.ru/llms.txt
> Use this file to discover all available pages before exploring further.

# API Functions

> Complete reference for global API functions of the Ziva library for configuration, optimization and advanced usage

# API Functions

Ziva provides a rich set of global functions for configuring library behavior, optimizing performance, and advanced usage.

<Info>
  These functions complement the core library components and allow fine-tuning Ziva behavior for your specific application requirements.
</Info>

## Auto-configuration

### AutoConfigure()

Automatically configures Ziva for optimal performance on the current system.

```go theme={null}
func main() {
    // Recommended to call at the beginning of the program
    ziva.AutoConfigure()

    // Your application code
    queue := ziva.NewQueue("Application Name")
}
```

This function:

* Analyzes available system memory
* Detects processor architecture
* Optimizes settings for embedded systems
* Configures caching and buffering

### DisableCompletionDelay()

Turns off the default completion delay that keeps the last task on screen for a short moment.

```go theme={null}
func init() {
    // For CI pipelines or scripted runs we don't need the pause
    ziva.DisableCompletionDelay()
}
```

Use it when you prefer immediate transitions between tasks or when running automated tests where every extra millisecond matters.

### Is64Bit()

Determines system architecture for optimal algorithm selection.

```go theme={null}
if ziva.Is64Bit() {
    // Use algorithms for 64-bit systems
    fmt.Println("64-bit architecture")
} else {
    // Optimizations for 32-bit systems
    fmt.Println("32-bit architecture")
}
```

## Performance Utilities

### RepeatEfficient(s string, count int) string

Creates a string by efficiently repeating the base string.

```go theme={null}
// Create a separator of 50 "-" characters
separator := ziva.RepeatEfficient("-", 50)
fmt.Println(separator)

// Indentation for formatting
indent := ziva.RepeatEfficient(" ", 4)
```

### JoinEfficient(parts \[]string, separator string) string

Joins strings with minimal memory allocations.

```go theme={null}
items := []string{"apple", "banana", "cherry"}
result := ziva.JoinEfficient(items, ", ")
// Result: "apple, banana, cherry"
```

### FastConcat(parts ...string) string

Fast concatenation of arbitrary number of strings.

```go theme={null}
message := ziva.FastConcat(
    "User ", username,
    " performed ", action,
    " at ", timestamp,
)
```

### CleanWhitespaceEfficient(s string) string

Cleans string from excessive whitespace characters.

```go theme={null}
text := "  Too    many\t\tspaces\n\nand\nlines  "
clean := ziva.CleanWhitespaceEfficient(text)
// Result: "Too many spaces and lines"
```

## Color Management

### SetErrorColor(errorsColor, statusColor lipgloss.TerminalColor)

Configures color scheme for error display.

```go theme={null}
import "github.com/charmbracelet/lipgloss"

// Red errors with yellow statuses
ziva.SetErrorColor(
    lipgloss.Color("#FF0000"), // red for error text
    lipgloss.Color("#FFFF00"), // yellow for statuses
)
```

### ResetErrorColors()

Resets error colors to default values.

```go theme={null}
// After experimenting with colors
ziva.ResetErrorColors()
```

### SetExitMenuItemStyle(style lipgloss.Style)

Changes the style used to render localized “Exit” menu items in list tasks. By default Ziva highlights the action with a cyan bold style (`ziva.MenuActionDefaultStyle()`).

```go theme={null}
// Make the exit item look like a regular menu row
ziva.SetExitMenuItemStyle(ziva.MenuItemDefaultStyle())

// Or keep the highlight but adjust the color
altExit := ziva.MenuActionDefaultStyle().Foreground(lipgloss.Color("#FFB000"))
ziva.SetExitMenuItemStyle(altExit)
```

### SetBackMenuItemStyle(style lipgloss.Style)

Changes the style used to render localized “Back” menu items in list tasks. Uses the same highlighted style as the exit action by default.

```go theme={null}
// Turn the "Back" item into a neutral entry
ziva.SetBackMenuItemStyle(ziva.MenuItemDefaultStyle())

// Restore the highlight later
ziva.ResetBackMenuItemStyle()
```

### ResetExitMenuItemStyle()

Restores the default highlight for “Exit” items.

```go theme={null}
ziva.ResetExitMenuItemStyle()
```

### ResetBackMenuItemStyle()

Restores the default highlight for “Back” items.

```go theme={null}
ziva.ResetBackMenuItemStyle()
```

### MenuActionDefaultStyle() lipgloss.Style

Returns the cyan bold style used for special menu actions.

```go theme={null}
// Reuse the default highlight for a custom shortcut
task.WithSelectAll("Enable all", "Disable all", ziva.MenuActionDefaultStyle())
```

### MenuItemDefaultStyle() lipgloss.Style

Returns the neutral style that matches regular menu items.

```go theme={null}
// Align a special entry with standard items
task.WithSelectAll("Enable all", "Disable all", ziva.MenuItemDefaultStyle())
```

### EnableEmbeddedMode()

Enables embedded system mode with simplified color palette.

```go theme={null}
// For routers, IoT devices
ziva.EnableEmbeddedMode()
```

### EnableASCIIMode()

Switches to ASCII mode for legacy terminals.

```go theme={null}
// For terminals without Unicode support
ziva.EnableASCIIMode()
```

### IsEmbeddedColorMode() bool

Checks if embedded system mode is enabled.

```go theme={null}
if ziva.IsEmbeddedColorMode() {
    fmt.Println("Running in embedded system mode")
}
```

## Advanced Validators

### NewPasswordValidator(minLength int) Validator

Creates validator for password complexity checking.

```go theme={null}
// Password minimum 8 characters
passwordValidator := ziva.NewPasswordValidator(8)

input := ziva.NewInputTask("Password", "Enter password:").
    WithInputType(ziva.InputTypePassword).
    WithValidator(passwordValidator)
```

### NewEmailValidator() Validator

Email address validator according to RFC standards.

```go theme={null}
emailValidator := ziva.NewEmailValidator()

email := ziva.NewInputTask("Email", "Enter email:").
    WithInputType(ziva.InputTypeEmail).
    WithValidator(emailValidator)
```

### NewIPValidator(allowIPv4, allowIPv6 bool) Validator

Configurable IP address validator.

```go theme={null}
// IPv4 only
ipv4Validator := ziva.NewIPValidator(true, false)

// IPv6 only
ipv6Validator := ziva.NewIPValidator(false, true)

// Any IP
anyIPValidator := ziva.NewIPValidator(true, true)
```

### NewIPv4Validator() / NewIPv6Validator() Validator

Specialized validators for specific IP versions.

```go theme={null}
ipv4 := ziva.NewIPv4Validator()
ipv6 := ziva.NewIPv6Validator()
```

### NewDomainValidator() Validator

Domain name validator.

```go theme={null}
domainValidator := ziva.NewDomainValidator()

domain := ziva.NewInputTask("Domain", "Enter domain:").
    WithValidator(domainValidator)
```

### NewTextValidator(minLen, maxLen int) Validator

Text validator with length constraints.

```go theme={null}
// 3 to 50 characters
textValidator := ziva.NewTextValidator(3, 50)

// Minimum only (no maximum limit)
minValidator := ziva.NewTextValidator(5, 0)

// Maximum only (no minimum limit)
maxValidator := ziva.NewTextValidator(0, 100)
```

## Memory Optimization

### InternString(s string) string

String interning for memory efficiency.

```go theme={null}
// For frequently repeated strings in UI
label1 := ziva.InternString("Done")
label2 := ziva.InternString("Done") // References same object
```

### GetCacheStats() (size, capacity int)

Get statistics of interned string cache.

```go theme={null}
size, capacity := ziva.GetCacheStats()
fmt.Printf("Cache: %d/%d strings\n", size, capacity)
```

### ClearInternCache()

Clear interned string cache.

```go theme={null}
// Periodic cleanup in long-running applications
ziva.ClearInternCache()
```

## Layout Utilities

### CalculateLayoutWidth(screenWidth int) int

Calculates optimal layout width.

```go theme={null}
screenWidth := 120
layoutWidth := ziva.CalculateLayoutWidth(screenWidth)

// Use in custom UI
queue := ziva.NewQueue("Application")
// layout will be optimized for calculated width
```

## Combined Examples

### Embedded System Setup

```go theme={null}
func setupForEmbedded() {
    // Auto-configuration for optimization
    ziva.AutoConfigure()

    // Embedded system mode
    ziva.EnableEmbeddedMode()

    // For very old terminals
    if needASCII {
        ziva.EnableASCIIMode()
    }

    // Memory monitoring
    size, capacity := ziva.GetCacheStats()
    if size > capacity*0.8 {
        ziva.ClearInternCache()
    }
}
```

### Form Validation Setup

```go theme={null}
func createRegistrationForm() {
    queue := ziva.NewQueue("Registration")

    // Email with validation
    email := ziva.NewInputTask("Email", "Your email:").
        WithValidator(ziva.NewEmailValidator())

    // Password with security requirements
    password := ziva.NewInputTask("Password", "Password (min. 8 chars):").
        WithInputType(ziva.InputTypePassword).
        WithValidator(ziva.NewPasswordValidator(8))

    // Username with constraints
    username := ziva.NewInputTask("Username", "Username:").
        WithValidator(ziva.NewTextValidator(3, 20))

    queue.AddTasks(email, password, username)
}
```

### Performance Data Processing

```go theme={null}
func processLargeDataset(items []string) string {
    // Use efficient functions for string operations
    var results []string

    for _, item := range items {
        // Data cleaning
        cleaned := ziva.CleanWhitespaceEfficient(item)

        // Interning for memory efficiency
        interned := ziva.InternString(cleaned)

        results = append(results, interned)
    }

    // Efficient result joining
    return ziva.JoinEfficient(results, "\n")
}
```

<Tip>
  All these functions are designed for maximum performance and can be used in high-load applications without performance degradation.
</Tip>

<Warning>
  Functions `EnableEmbeddedMode()` and `EnableASCIIMode()` change global library state. It's recommended to call them only once at the beginning of the program.
</Warning>
