> ## 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.

# YesNoTask

> Binary choice task between two options

# YesNoTask

`YesNoTask` provides an interface for choosing between two options: "Yes" and "No". This is the simplest task type in Ziva, perfect for confirmations and binary decisions.

## Creating a Task

```go theme={null}
task := ziva.NewYesNoTask("Title", "Question for user?")
```

## Main Methods

### Creating with Settings

```go theme={null}
task := ziva.NewYesNoTask("Confirmation", "Continue installation?").
    WithDefaultItem("Yes").                          // default value
    WithTimeout(10*time.Second, "No").               // timeout with fallback
    WithCustomLabels("Continue", "Cancel")           // custom labels
```

### Getting Results

```go theme={null}
// After task execution
option := task.GetSelectedOption() // ziva.YesNoOption
isYes := task.IsYes()              // bool
isNo := task.IsNo()                // bool
```

## Options and Constants

```go theme={null}
// Available options
const (
    YesOption = ziva.YesOption  // "Yes"
    NoOption  = ziva.NoOption   // "No"
)

// Check specific option
if task.GetSelectedOption() == ziva.YesOption {
    fmt.Println("User chose 'Yes'")
}
```

## Default Configuration

### Default Selection

```go theme={null}
// By string
task.WithDefaultItem("Yes")
task.WithDefaultItem("No")

// By constant
task.WithDefaultItem(ziva.YesOption)
task.WithDefaultItem(ziva.NoOption)

// By bool (true = Yes, false = No)
task.WithDefaultItem(true)
task.WithDefaultItem(false)
```

## Timeouts

```go theme={null}
// Timeout with automatic "Yes" selection
task.WithTimeout(5*time.Second, "Yes")

// Timeout with automatic "No" selection
task.WithTimeout(3*time.Second, ziva.NoOption)

// Timeout with bool value
task.WithTimeout(10*time.Second, true) // true = Yes
```

## Custom Labels

By default "Yes" and "No" are used, but you can configure custom labels:

```go theme={null}
// Custom labels
task.WithCustomLabels("Continue", "Cancel")
task.WithCustomLabels("Accept", "Decline")
task.WithCustomLabels("Enable", "Disable")
task.WithCustomLabels("✓ Yes", "✗ No")
```

## Result Line Output

When a task finishes, Ziva shows an extra line with the chosen answer. Hide it when you need a tighter layout:

```go theme={null}
task.WithoutResultLine() // suppress the trailing “Yes/No” line
```

## Treating "No" as Success

By default a "No" answer is recorded as a soft error so the queue summary can highlight the refusal. If you prefer to treat "No" as a successful outcome, enable the helper:

```go theme={null}
task.WithNoAsError() // “No” no longer contributes an error to the summary

if task.IsNo() {
    // handle the choice while keeping the queue statistics positive
}
```

## Usage Examples

### Simple Confirmation

```go theme={null}
func confirmAction() bool {
    task := ziva.NewYesNoTask(
        "Confirmation",
        "Are you sure you want to delete the file?",
    )

    queue := ziva.NewQueue("File Deletion")
    queue.AddTasks(task)
    queue.Run()

    return task.IsYes()
}
```

### Confirmation with Timeout

```go theme={null}
func confirmWithTimeout() bool {
    task := ziva.NewYesNoTask(
        "Auto-continue",
        "Continue in 5 seconds?",
    ).WithTimeout(5*time.Second, "Yes")

    queue := ziva.NewQueue("Demo")
    queue.AddTasks(task)
    queue.Run()

    return task.IsYes()
}
```

### Custom Options

```go theme={null}
func enableFeature() bool {
    task := ziva.NewYesNoTask(
        "Feature Setup",
        "Enable experimental feature?",
    ).WithCustomLabels("Enable", "Keep disabled").
      WithDefaultItem("Keep disabled")

    queue := ziva.NewQueue("Configuration")
    queue.AddTasks(task)
    queue.Run()

    return task.IsYes()
}
```

## See Also

* [SingleSelectTask](/en/components/singleselect-task) - for multiple option selection
* [InputTask](/en/components/input-task) - for arbitrary text input
* [Examples](/en/examples/basic-usage) - practical usage examples
