Feature/UI crate#18
Merged
Merged
Conversation
Copy style.rs, ui/confirm, ui/diff, ui/input, ui/wrap modules to a new tinyharness-ui workspace crate. Original files in src/ remain untouched; the binary crate still uses its local copy.
Output wraps Box<dyn Write + Send>, provides: - plain output: line(), blank(), raw() - styled helpers: success(), error(), warning(), info(), dim(), bold(), styled_line() - impl Write for use with writeln!(output, ...) All terminal I/O will funnel through Output, eliminating direct println!/eprintln! from the binary crate.
Add tinyharness-ui as a dependency of the binary crate. The CommandContext struct now owns an Output (stdout by default), making it available to all command handlers without further plumbing. All existing callsites compile unchanged.
Replace all println!/print! calls in apikey, clear, exit, help, context, and mode commands with writeln!/write! through Output. These functions now take &mut Output instead of calling println! directly. The /unload handler in mod.rs also updated.
Add &mut Output param to sync functions (execute_context_limit, execute_autoaccept). execute_showthink uses ctx.output directly. Async commands (TimeoutCommand, RetriesCommand, ThinkCommand) create a local Output::stdout() since they can't hold a reference across .await points.
Remove all println! calls from command.rs (~40 calls) and settings.rs (~20 calls). All functions now take &mut Output or use ctx.output for output. format_command_rows and format_denied_command_rows remain pure data helpers.
Add &mut Output parameter to execute_add, execute_drop, execute_list, execute_clear, and execute_refresh. Replace all println! calls with writeln! through Output.
Remove all println!/print!/eprintln! calls from skill.rs (~20) and sessions.rs (~15). handle_skill_use uses ctx.output directly. execute_show now accepts &mut ctx.output instead of creating a separate io::stdout(). cleanup_empty_sessions uses a local Output::stderr() for its error logging.
Add &mut Output parameter to show_last, show_session, and execute. Replace all println!/print! calls (~25) with writeln!/write! through Output.
models.rs, compact.rs, and init.rs all create a local Output::stdout() inside their async_command! bodies since they can't hold a reference across .await points. execute_compact and execute_init now take &mut Output and thread it through to all sub-functions. Update tools.rs caller accordingly.
- Extract style.rs and ui/ (confirm, diff, input, wrap) into new tinyharness-ui workspace crate for clean separation of concerns - Replace eprintln! calls in tinyharness-lib with tracing::warn! so the library doesn't write to stderr directly - Add tracing-subscriber to binary crate to route lib diagnostics - Add Output abstraction (tinyharness_ui::output) with styled convenience methods and impl Write for writeln! macro support - Update all imports: crate::style → tinyharness_ui::style, crate::ui::* → tinyharness_ui::ui::* - Bump version to 0.1.1 across workspace
3fe6fc7 to
c9aa8a4
Compare
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.
Extract
tinyharness-uicrate and adopttracingin the libraryA refactoring pass that improves separation of concerns and follows Rust ecosystem conventions for library diagnostics.
What changed
New
tinyharness-uiworkspace crate —src/style.rsandsrc/ui/(confirm, diff, input, wrap) were moved out of the binary crate into a dedicated crate. The binary no longer owns terminal UI code directly; it imports fromtinyharness_ui.Outputabstraction —tinyharness_ui::output::OutputwrapsBox<dyn Write + Send>with styled convenience methods (success,error,warning,info,dim,bold) and implementsstd::io::Writesowriteln!macros continue to work with ANSI constants. Comes with 30+ unit tests.tracingintinyharness-lib— Replaced 4eprintln!calls withtracing::warn!(). Libraries should not write directly to stdout/stderr; they should use a logging facade. The binary crate now initializes atracing_subscriberto route library diagnostics to stderr.Import hygiene — All
crate::style::*/crate::ui::*imports updated totinyharness_ui::style::*/tinyharness_ui::ui::*.Version bump —
0.1.0→0.1.1across the workspace.Why
tinyharness-lib.eprintln!in library code is an anti-pattern — it bypasses any logging configuration the application might have and can't be redirected or filtered at the application level.Outputstruct provides a single, testable abstraction for all terminal I/O, replacing scatteredwriteln!(stdout, ...)/writeln!(stderr, ...)calls with a consistent interface.