Skip to content

Add command line option for short banner #50726

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

Merged
merged 11 commits into from
Aug 3, 2023
Merged

Add command line option for short banner #50726

merged 11 commits into from
Aug 3, 2023

Conversation

LilithHafner
Copy link
Member

  o  | Version 1.10.0-beta1 (2023-07-25)
 o o | Official https://julialang.org/ release
  o  | Version 1.11.0-DEV.229 (2023-07-29)
 o o | scoped-export/de8be2b039* (fork: 35 commits, 0 days)

(it has color, too)

@LilithHafner LilithHafner added REPL Julia's REPL (Read Eval Print Loop) display and printing Aesthetics and correctness of printed representations of objects. labels Jul 30, 2023
@LilithHafner
Copy link
Member Author

I've reviewed and approve @c42f's contribution to this PR.

Copy link
Member

@c42f c42f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked through all this again including your parts @LilithHafner. I added another two tiny tests to cover the command line argument more thoroughly.

It looks good to me I say we merge it as soon as CI passes.

Personally I'll be turning this on by default for all my Julia aliases :)

@c42f
Copy link
Member

c42f commented Aug 3, 2023

The windows test failure here looks spurious - something to do with temporary files and the file system.

@LilithHafner LilithHafner merged commit c62f4ea into master Aug 3, 2023
@LilithHafner LilithHafner deleted the short-banner branch August 3, 2023 11:42
@tecosaur
Copy link
Member

@LilithHafner did you by any chance see my efforts to support multiple banner sizes based on the terminal resolution?

@LilithHafner
Copy link
Member Author

I did not, would you share a link?

@tecosaur
Copy link
Member

tecosaur commented Aug 23, 2023

I had a look when I sent that message, unfortunately it seems like the discussion has disappeared into the slack-hole. That said, I can do a brief recap and demo.

I don't think it's very nice how with a narrow or small terminal window, the Julia banner can (a) get ruined by line wrapping, or (b) take up almost all of the window. So, I designed a number of alternative scaling of the Julia banner that are picked between based on displaysize(io).

image

@LilithHafner
Copy link
Member Author

I love the rendering of "Julia" in the 8x55 version!

@tecosaur
Copy link
Member

The 8 or less rows options do assume the Julia mono font, but I like them. I'd be happy to PR these once StyledStrings is in, but I do think we'd then want to switch out --banner=short to --banner=<int>, say with 0 being the smallest size and going up from there.

@LilithHafner
Copy link
Member Author

The deadline to cleanly swap that out (i.e. drop support for --banner=short) is 1.11

@tecosaur
Copy link
Member

Mmm, I'd also like to get StyledStrings in with 1.11 (and Stefan/Kristopher/Jameson seemed to think that reasonable I spoke with them at JuliaCon).

@LilithHafner
Copy link
Member Author

LilithHafner commented Feb 12, 2024

For @c42f and others who may want to opt into this by default, here's a little monstrosity to put in startup.jl that does that

# Use --short banner by default (https://github.com/JuliaLang/julia/pull/50726#issuecomment-1939089858)
if VERSION >= v"1.11.0-DEV.222" && isinteractive()
    c_options = cglobal(:jl_options, Base.JLOptions)
    opts = unsafe_load(c_options)
    if opts.banner == -1 && isa(stdin, Base.TTY)
        # opts.banner = 2
        fields = fieldnames(Base.JLOptions)
        args = (f == :banner ? 2 : getfield(opts, f) for f in fields)
        new_opts = Base.JLOptions(args...)
        unsafe_store!(c_options, new_opts)
    end
end

@tecosaur
Copy link
Member

That almost makes me wonder if a JULIA_BANNER env var may be worth it.

@LilithHafner
Copy link
Member Author

Or a ShortBanner package. Then it would just be using ShortBanner (and have a lower startup time). I may make that package a couple weeks after the 1.11 feature freeze once these internals are a bit more settled.

@vtjnash
Copy link
Member

vtjnash commented Feb 12, 2024

FWIW, I think a slightly more standard form of this would use:

        unsafe_store!(Ptr{typeof(banner)}(c_options) + fieldoffset(opts, :banner), 2)

@LilithHafner
Copy link
Member Author

That fieldoffset method does not exist.

julia> only(methods(fieldoffset))
fieldoffset(x::DataType, idx::Integer)
     @ Base reflection.jl:917

@vtjnash
Copy link
Member

vtjnash commented Feb 13, 2024

Ugh, you are right, and it really should exist for this use case. Anyways, here is the verbose version of it then:

julia> code_typed() do; fieldoffset(Base.JLOptions, Base.fieldindex(Base.JLOptions, :banner)); end
1-element Vector{Any}:
 CodeInfo(
    @ REPL[7]:1 within `#21`
1 ─     return 0x0000000000000001
) => UInt64

@c42f
Copy link
Member

c42f commented Feb 18, 2024

Oh my. I love that use of code_typed() with the lambda 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants