Skip to content

Should we allow IOContext to accept kwargs #47396

@m-wells

Description

@m-wells

IOContext already accepts Vararg{Pair{Symbol}}. The following code seems to work just fine.

> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.2 (2022-09-29)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> Base.IOContext(io; kwargs...) = if length(kwargs) > 0
       IOContext(io, kwargs...)
       else
       convert(IOContext, io)
       end

julia> IOContext(stdout)
IOContext(Base.TTY(RawFD(13) open, 0 bytes waiting))

julia> io = IOContext(stdout)
IOContext(Base.TTY(RawFD(13) open, 0 bytes waiting))

julia> printstyled(io, rand())
0.39622936715782087
julia> io = IOContext(stdout; compact=true)
IOContext(Base.TTY(RawFD(13) open, 0 bytes waiting))

julia> printstyled(io, rand(), color=:red)
0.0857637

I can open a PR if there is interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.keyword argumentsf(x; keyword=arguments)performanceMust go faster

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions