Print boolean with PrettyTables.jl

I am printing a struct with PrettyTables.jl and would like boolean values to print out as true or false rather than Float64s. Is there a way to do this? Thank you.

Example

using PrettyTables

struct M
    x::String
    y::Float64
    z::Bool
end

function Base.show(io::IO, ::MIME"text/plain", m::M)
    values = [getfield(m, f) for f in fieldnames(M)]
    return pretty_table(
        values;
        compact_printing=false,
        header=["Value"],
        row_name_alignment=:l,
        row_names=[fieldnames(M)...],
        formatters=ft_printf("%5.2f"),
        alignment=:l,
    )
end

m = M("x", .3, true)

Output:

julia> m
┌───┬───────┐
│   │ Value │
├───┼───────┤
│ x │ x     │
│ y │  0.30 │
│ z │  1.00 │
└───┴───────┘

Converting boolean to string before returning the pretty_table, seems to work:

 [(typeof(v) == Bool) && (values[i] = string(v)) for (i,v) in pairs(values)]

the output is:

julia> m = M("x", .3, true)
┌───┬───────┐
│   │ Value │
├───┼───────┤
│ x │ x     │
│ y │  0.30 │
│ z │ true  │
└───┴───────┘

It’s the formatters option. I think it applies to all <: Number types, and Bool <: Number.

You can define a small helper function which checks if something is a Bool and if so, returns that thing, and if not uses @sprintf, like in this thread.

Thank you!