Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Oct 31, 2024
1 parent 4b3087f commit 21f2cc5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/utils/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Printf
using Preferences

"""
Configures the default printing behaviour of `show_system`, which is invoked when a rich `text/htmal`
Configures the printing behaviour of `show_system`, which is invoked when a rich `text/htmal`
display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL.
The following options can be configured:
Expand All @@ -13,13 +13,18 @@ The following options can be configured:
"""
function set_show_preferences!(; max_species_list=nothing, max_species_visualize_ascii=nothing)
if !isnothing(max_species_list)
@set_preference!("max_species_list", max_species_list)
@set_preferences!("max_species_list" => max_species_list)

Check warning on line 16 in src/utils/show.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/show.jl#L14-L16

Added lines #L14 - L16 were not covered by tests
end
if !isnothing(max_species_visualize_ascii)
@set_preference!("max_species_visualize_ascii", max_species_visualize_ascii)
@set_preferences!("max_species_visualize_ascii" => max_species_visualize_ascii)

Check warning on line 19 in src/utils/show.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/show.jl#L18-L19

Added lines #L18 - L19 were not covered by tests
end
show_preferences()

Check warning on line 21 in src/utils/show.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/show.jl#L21

Added line #L21 was not covered by tests
end

"""
Display the current printing behaviour of `show_system`.
See [`set_show_preferences!](@ref) for more details on the keys.
"""
function show_preferences()
(; max_species_list=@load_preference("max_species_list", 10),
max_species_visualize_ascii=@load_preference("max_species_visualize_ascii", 0))

Check warning on line 30 in src/utils/show.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/show.jl#L30

Added line #L30 was not covered by tests
Expand Down Expand Up @@ -74,15 +79,15 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher
extra_line = true
@printf io " %-17s : %s\n" string(k) string(v)
end
if length(system) < show_preferences().max_species_list
if length(system) show_preferences().max_species_list
extra_line && println(io)
for atom in system
println(io, " ", atom)
end
extra_line = true
end

if length(system) < show_preferences().max_species_visualize_ascii
if length(system) show_preferences().max_species_visualize_ascii
ascii = visualize_ascii(system)
if !isempty(ascii)
extra_line && println(io)
Expand Down

0 comments on commit 21f2cc5

Please sign in to comment.