Welcome to WriterUI, your go-to library for simplifying console-based user interactions and message formatting.
WriterUI provides a set of functional methods for interacting with the console, allowing you to display formatted messages, capture user input, and customize the console output. Written in F# to leverage functional programming patterns and pipeline operations.
Display formatted messages with optional colors and spacing.
message None "Welcome to the writer console UI helper!"
error "Oops! Something went wrong."
warn "Warning: Proceed with caution."
Type-safe input capture with built-in error handling.
let intInput = inputTyped<int> None (Some "Please enter an integer:")
let boolInput = inputTyped<bool> None (Some "Enter 'true' or 'false':")
let strInput = input None (Some "Enter a string:")
Customise colors and formatting using the WriteOptions record:
message (Some {
CustomColor = Some ConsoleColor.Magenta
BackgroundColor = Some ConsoleColor.Black
IncludeLineSpace = true
}) "Customized message!"
let customInput = input
(Some {
CustomColor = Some ConsoleColor.DarkCyan
BackgroundColor = None
IncludeLineSpace = true
})
(Some "Enter with style:")
Add the WriterUI library through NuGet Package Manager.
open WriterUI
message None "Welcome to my application!"
let age = inputTyped<int> None (Some "Please enter your age:")
The library has been rewritten in F# to:
- Better support functional programming patterns
- Enable pipeline operations with consistent parameter ordering
- Provide cleaner option handling
- Leverage F#'s type inference and pattern matching
- Simplify error handling
The library provides type-safe input handling using F#'s generic constraints:
let age = inputTyped<int> None (Some "Enter age:") // Works
let request = inputTyped<HttpClient> None (Some "Stringify an HttpClient?") // No way!
let name = input None (Some "Enter name:") // String input
- Error handling is built into inputTyped<'T> with recursive retry
- All functions handle None cases gracefully
- Background colors automatically reset to terminal defaults
- Thread-safe console operations
MIT License. See the LICENSE file for details.
- Updated syntax to show F# examples
- Removed C# examples and namespace references
- Added explanation for F# migration
- Simplified API examples
- Updated configuration examples to use F# record syntax
- Added note about background color handling