Skip to content

Add transparent background mode and HH:MM:SS timer display#66

Open
NoamFav wants to merge 7 commits intoklange:masterfrom
NoamFav:master
Open

Add transparent background mode and HH:MM:SS timer display#66
NoamFav wants to merge 7 commits intoklange:masterfrom
NoamFav:master

Conversation

@NoamFav
Copy link
Copy Markdown

@NoamFav NoamFav commented Nov 25, 2025

Add transparent background mode and HH:MM:SS timer display

Summary

This PR builds on #65 by @naivecynics, adding an optional transparent background mode to nyancat, upgrading the timer display from seconds to HH:MM:SS format, and applying minor code formatting improvements. All changes are backward-compatible, with new behavior activated via command-line flags.

Changes

1. Transparent background mode (-T, --transparent)

Implements the transparent background feature originally proposed in #65, allowing nyancat to render without a solid background color.

Implementation:

  • Adds global flag transparent_bg (default: 0)
  • New CLI option: -T / --transparent
  • Integrated into getopt_long options:
    static struct option long_opts[] = {    ...    {"transparent", no_argument, 0, 'T'},    ...};
    
  • Conditionally maps background color to transparent:
    if (transparent_bg && ttype != 6 && ttype != 7)    colors[','] = "\033[49m";  // Use terminal default background
    
  • Excludes ttype 6/7 terminals to preserve existing color expectations
  • Updates usage() documentation

Benefit: Enables seamless visual integration with terminals using custom or image-based backgrounds.

2. Enhanced timer: seconds → HH:MM:SS

Replaces the basic seconds counter with a human-readable time format for longer nyan sessions.

Before:

printf("\033[1;37mYou have nyaned for %0.0f seconds!\033[J\033[0m", diff);

After:

int total = (int)diff;
int h = total / 3600;
int m = (total % 3600) / 60;
int s = total % 60;
printf("\033[1;37mYou have nyaned for %02d:%02d:%02d!\033[J\033[0m", h, m, s);
  • Properly handles sessions lasting hours
  • Adjusted centering logic for fixed 8-character format (HH:MM:SS)

3. Code formatting and cleanup

Minor cosmetic improvements for consistency (no behavioral changes):

animation.c:

  • Normalized array declarations (opening brace on same line)
  • Compacted frames pointer array for readability

nyancat.c:

  • Improved indentation consistency
  • Cleaned up include statement ordering

Review tip: Use GitHub's "Hide whitespace" view (?w=1) for easier code review.

Testing

Verified across multiple scenarios:

Command | Expected Behavior | Status -- | -- | -- ./nyancat | Default rendering (unchanged) | ✅ ./nyancat -T | Transparent background + timer | ✅ ./nyancat -n | No counter display | ✅ ./nyancat -T -n | Transparent + no counter | ✅

All tests confirm:

  • Animation renders correctly in all modes
  • Transparent mode uses terminal's native background
  • Timer displays accurate HH:MM:SS elapsed time
  • No regressions in existing functionality

Backward Compatibility

  • ✅ Default behavior unchanged when no flags provided
  • ✅ Transparent mode is opt-in via explicit -T flag
  • ✅ All existing options work as expected

Credits

Transparent background feature concept and initial implementation by @naivecynics in #65.

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.

2 participants