Add comprehensive conditional styling feature#81
Merged
Conversation
Add new source files to Xcode project: - Sources/ConditionalStyleBuilder.swift - Sources/String+ConditionalStyling.swift - Tests/RainbowTests/ConditionalStylingTests.swift This ensures proper integration with Xcode IDE and project management.
Document the new conditional styling feature with practical examples: - Basic conditional styling with colorIf, styleIf - Log level styling patterns - Advanced conditional builder with fluent interface - Closure-based conditional styling - Progress-based styling examples The examples showcase both simple and complex use cases, demonstrating how conditional styling improves code readability and reduces the need for ternary operators in styling logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a powerful conditional styling system for the Rainbow library that allows developers to apply colors and styles based on runtime conditions, significantly improving code readability and reducing the need for ternary operators in styling logic.
Key Features
🎯 Basic Conditional APIs
colorIf(_:_:)- Apply colors conditionallybackgroundColorIf(_:_:)- Apply background colors conditionallystyleIf(_:_:)- Apply styles conditionallystylesIf(_:_:)- Apply multiple styles conditionallyapplyIf(_:transform:)- Apply custom transformations conditionally🚀 Advanced Conditional Builder
ConditionalStyleBuilder- Fluent interface for complex conditional stylingConditionalStyleStep- Chain multiple conditional styles.red,.bold,.underline, etc.📝 Usage Examples
Basic Conditional Styling:
Advanced Conditional Builder:
🔧 Implementation Details
\u{001B}[31;1minstead of\u{001B}[1m\u{001B}[31m)✅ Quality Assurance
Rainbow.enabled = false🎨 Design Philosophy
The conditional styling system follows a SwiftUI-inspired fluent interface design, making it intuitive for developers familiar with modern Swift APIs. The implementation prioritizes:
📊 Impact
This feature addresses a common pain point in terminal styling where developers often resort to verbose ternary operators or if-else statements to apply conditional styling. The new APIs provide a clean, chainable interface that makes styling logic more declarative and maintainable.
Test Plan
Breaking Changes
None - this is a purely additive feature that maintains full backward compatibility.