Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing interface functions for an IO #2

Open
vtjnash opened this issue Mar 16, 2023 · 3 comments
Open

missing interface functions for an IO #2

vtjnash opened this issue Mar 16, 2023 · 3 comments

Comments

@vtjnash
Copy link

vtjnash commented Mar 16, 2023

The typical interface functions for an IO are most clearly reflected by the forwarding methods provided by AbstractPipe:
https://github.com/JuliaLang/julia/blob/17cfb8e65ead377bf1b4598d8a9869144142c84e/base/io.jl#L414-L443

in particular, this method seems to be missing, and typically is the primary method that makes something an "IO" subtype

unsafe_write(io::AbstractPipe, p::Ptr{UInt8}, nb::UInt) 
@timholy
Copy link
Member

timholy commented Mar 16, 2023

I wondered about implementing that. But one thing this package absolutely must do is ensure that any terminal-escapes get "closed": you don't want to truncate

julia> sprint("abcdef"; context=:color=>true) do io, str
           printstyled(io, str; color=:red)
       end
"\e[31mabcdef\e[39m"

before the color gets restored to default at the end. (As stated in the README, it gets truncated to "\e[31mabcd…\e[39m" if your width limit is 5.)

My thinking was that if I live in just the world of Chars, then I have a better change of understanding how to interpret what I'm getting than if I delve into Ptr{UInt8}. Whether I was correct or not, the omission was deliberate.

However, I guess I could implement it to interpret it as a String, and do Char level processing on the string. Would that be better than intercepting dispatch at a higher level, as done here?

@timholy
Copy link
Member

timholy commented Mar 17, 2023

I guess the other reason not to implement it: TextWidthLimiter is only about text; one should not be able to write binary data to it.

@timholy
Copy link
Member

timholy commented Mar 21, 2023

More generally, I'm wondering if we want an abstract type TextIO <: IO end type that only supports text IO. There seem to be many applications. For example, for JuliaLang/julia#48444 (comment) I plan to create a TypeTreeIO <: TextIO object that adds children on encountering '{', ',', or '}'.

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

No branches or pull requests

2 participants