Skip to content

Feature/UI crate#18

Merged
PTFOPlayer merged 13 commits into
masterfrom
feature/ui-crate
May 31, 2026
Merged

Feature/UI crate#18
PTFOPlayer merged 13 commits into
masterfrom
feature/ui-crate

Conversation

@PTFOPlayer
Copy link
Copy Markdown
Owner

Extract tinyharness-ui crate and adopt tracing in the library

A refactoring pass that improves separation of concerns and follows Rust ecosystem conventions for library diagnostics.

What changed

  • New tinyharness-ui workspace cratesrc/style.rs and src/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 from tinyharness_ui.

  • Output abstractiontinyharness_ui::output::Output wraps Box<dyn Write + Send> with styled convenience methods (success, error, warning, info, dim, bold) and implements std::io::Write so writeln! macros continue to work with ANSI constants. Comes with 30+ unit tests.

  • tracing in tinyharness-lib — Replaced 4 eprintln! calls with tracing::warn!(). Libraries should not write directly to stdout/stderr; they should use a logging facade. The binary crate now initializes a tracing_subscriber to route library diagnostics to stderr.

  • Import hygiene — All crate::style::* / crate::ui::* imports updated to tinyharness_ui::style::* / tinyharness_ui::ui::*.

  • Version bump0.1.00.1.1 across the workspace.

Why

  • The binary crate was accumulating too many concerns. Extracting UI code follows the same pattern already established with 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.
  • The Output struct provides a single, testable abstraction for all terminal I/O, replacing scattered writeln!(stdout, ...) / writeln!(stderr, ...) calls with a consistent interface.

PTFOPlayer added 12 commits May 29, 2026 08:45
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
@PTFOPlayer PTFOPlayer merged commit 7d92828 into master May 31, 2026
4 checks passed
@PTFOPlayer PTFOPlayer deleted the feature/ui-crate branch June 4, 2026 10:09
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