[ty] Avoid allocation for every stdout write (#26698)
## Summary
We allocated a new `Box<dyn Write>` for every `Write` call (unless the
compiler managed to remove it). This is rather expensive.
This PR replaces the `handle() -> Box<dyn Write>` function with
`with_handle` that takes a callback instead. This avoids the allocation
entirely.
> On 50k diagnostics, concise improved from 497.1ms to 475.2ms—about
13.5% faster for rendering-only time.
Related to astral-sh/ty#3958.
## Test Plan
Testing: Passed the ty test suite and repository hooks.