Skip to content

feat(timeout): Add --timeout-elapsed for seamless dialog chaining#1

Closed
mg-dev25 wants to merge 1 commit intomasterfrom
feat/timeout-elapsed
Closed

feat(timeout): Add --timeout-elapsed for seamless dialog chaining#1
mg-dev25 wants to merge 1 commit intomasterfrom
feat/timeout-elapsed

Conversation

@mg-dev25
Copy link

@mg-dev25 mg-dev25 commented Dec 4, 2025

PR: Add --timeout-elapsed for Seamless Dialog Chaining

Summary

This PR introduces a --timeout-elapsed option that allows yad dialogs to continue a shared timeout from a specified elapsed point. When chaining multiple dialogs in a script, this enables the progress bar to visually continue rather than restart at 100%.

Problem

When chaining yad dialogs with timeouts, each dialog restarts its progress bar from the beginning. For scripts that need a single timeout budget across multiple dialogs, this creates a jarring user experience where the progress appears to "reset" at each transition.

Solution

Add --timeout-elapsed=SECONDS to specify how much time has already passed. The progress bar and remaining time label initialize at the correct position.

Example:

#!/bin/bash
TIMEOUT=30

# Dialog 1 - starts at 100%
yad --text="Step 1" --timeout=$TIMEOUT --timeout-indicator=bottom
ELAPSED=$((TIMEOUT - remaining))  # Track elapsed time

# Dialog 2 - continues from where Dialog 1 left off
yad --text="Step 2" --timeout=$TIMEOUT --timeout-elapsed=$ELAPSED --timeout-indicator=bottom

Changes

File Change
src/yad.h Add timeout_elapsed field to YadData struct
src/option.c Register --timeout-elapsed option, initialize to 0
src/main.c Update timeout_cb and create_dialog to use elapsed value

Implementation Details

Timer callback (timeout_cb):

  • Uses a static initialized flag to set the starting count once
  • Initializes count to timeout_elapsed + 1 instead of hardcoded 1

Progress bar initialization (create_dialog):

  • Calculates initial fraction as (timeout - elapsed) / timeout
  • Sets the progress bar and text label to show remaining time correctly

Safety checks:

  • Only applies elapsed offset when 0 < elapsed < timeout
  • Prevents negative values or division by zero

Testing

Visual tests confirm correct behavior:

Test Settings Result
Normal --timeout=10 Bar starts at 100%
50% elapsed --timeout=10 --timeout-elapsed=5 Bar starts at 50%
80% elapsed --timeout=10 --timeout-elapsed=8 Bar starts at 20%

Backward Compatibility

Fully backward compatible. Without --timeout-elapsed, behavior is identical to before (count starts at 1, progress starts at 100%).

Related

  • Addresses use case for progress bar continuation in multi-dialog scripts
  • Complements existing --timeout and --timeout-indicator options

Adds a new --timeout-elapsed flag that allows progress bar continuation
across chained dialogs by specifying how much time has already elapsed.

Changes:
- Add timeout_elapsed field to YadData struct (yad.h)
- Register --timeout-elapsed CLI option (option.c)
- Update timeout_cb to initialize from elapsed value (main.c)
- Calculate initial progress bar fraction from elapsed time
- Update remaining time label to account for elapsed time

Usage:
  # First dialog
  yad --timeout=30 --timeout-indicator=bottom

  # Second dialog continuing same timeout (10s elapsed)
  yad --timeout=30 --timeout-elapsed=10 --timeout-indicator=bottom

The progress bar and remaining time label will start at the correct
position based on the elapsed time, enabling smooth visual continuity
when chaining multiple yad dialogs with a shared timeout budget.
@mg-dev25
Copy link
Author

mg-dev25 commented Dec 4, 2025

Closing in favor of upstream PR: v1cont#320

@mg-dev25 mg-dev25 closed this Dec 4, 2025
@mg-dev25 mg-dev25 deleted the feat/timeout-elapsed branch December 7, 2025 10:52
@mg-dev25 mg-dev25 restored the feat/timeout-elapsed branch December 7, 2025 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant