diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6d824aa..3d42086 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,7 +18,6 @@ jobs: fail-fast: false matrix: version: - - '1.6' - '1.9' - '1.10' - 'nightly' diff --git a/Project.toml b/Project.toml index 8886d3c..9092fbb 100644 --- a/Project.toml +++ b/Project.toml @@ -6,19 +6,28 @@ version = "0.4.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PeriodicTable = "7b2266bf-644c-5ea3-82d8-af4bbd25a884" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a" +[weakdeps] +AtomsView = "ee286e10-dd2d-4ff2-afcb-0a3cd50c8041" + +[extensions] +AtomsBaseAtomsViewExt = "AtomsView" + [compat] +AtomsView = "0.1" PeriodicTable = "1" +Preferences = "1.4" Requires = "1" StaticArrays = "1" Unitful = "1" UnitfulAtomic = "1" -julia = "1.6" +julia = "1.9" [extras] Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" diff --git a/ext/AtomsBaseAtomsViewExt.jl b/ext/AtomsBaseAtomsViewExt.jl new file mode 100644 index 0000000..31773f7 --- /dev/null +++ b/ext/AtomsBaseAtomsViewExt.jl @@ -0,0 +1,8 @@ +module AtomsBaseAtomsViewExt + using AtomsBase + using AtomsView + + function Base.show(io::IO, mime::MIME"text/html", system::AbstractSystem) + write(io, AtomsView.visualize_structure(system, mime)) + end +end diff --git a/src/AtomsBase.jl b/src/AtomsBase.jl index 76d3d75..a732abc 100644 --- a/src/AtomsBase.jl +++ b/src/AtomsBase.jl @@ -18,24 +18,10 @@ include("utils/visualize_ascii.jl") include("utils/show.jl") include("utils/atomview.jl") - # prototype implementations include("implementation/atom.jl") include("implementation/flexible_system.jl") include("implementation/fast_system.jl") include("implementation/utils.jl") - -# TODO: -# - this should be converted to an extension -# - should work for AbstractSystem -function __init__() - @require AtomsView="ee286e10-dd2d-4ff2-afcb-0a3cd50c8041" begin - function Base.show(io::IO, mime::MIME"text/html", system::FlexibleSystem) - write(io, AtomsView.visualize_structure(system, mime)) - end - end -end - - end diff --git a/src/utils/show.jl b/src/utils/show.jl index 7d09841..a2664ed 100644 --- a/src/utils/show.jl +++ b/src/utils/show.jl @@ -1,4 +1,35 @@ using Printf +using Preferences + +""" +Configures the printing behaviour of `show_system`, which is invoked when a rich `text/plain` +display of an `AbstractSystem` is requested. This is for example the case in a Julia REPL. +The following options can be configured: + +- `max_particles_list`: Maximal number of particles in a system until `show_system` + includes a listing of every particle. Default: 10 +- `max_particles_visualize_ascii`: Maximal number of particles in a system + until `show_system` includes a representation of the system in the form of + an ascii cartoon using `visualize_ascii`. Default 0, i.e. disabled. +""" +function set_show_preferences!(; max_particles_list=nothing, max_particles_visualize_ascii=nothing) + if !isnothing(max_particles_list) + @set_preferences!("max_particles_list" => max_particles_list) + end + if !isnothing(max_particles_visualize_ascii) + @set_preferences!("max_particles_visualize_ascii" => max_particles_visualize_ascii) + end + show_preferences() +end + +""" +Display the current printing behaviour of `show_system`. +See [`set_show_preferences!](@ref) for more details on the keys. +""" +function show_preferences() + (; max_particles_list=@load_preference("max_particles_list", 10), + max_particles_visualize_ascii=@load_preference("max_particles_visualize_ascii", 0)) +end """ Suggested function to print AbstractSystem objects to screen @@ -26,7 +57,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher println(io, "):") extra_line = false - if any(pbc) + if any(pbc) extra_line = true box = bounding_box(system) bunit = unit(eltype(first(bounding_box(system)))) @@ -47,7 +78,7 @@ 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) < 10 + if length(system) ≤ show_preferences().max_particles_list extra_line && println(io) for atom in system println(io, " ", atom) @@ -55,9 +86,7 @@ function show_system(io::IO, ::MIME"text/plain", system::AbstractSystem{D}) wher extra_line = true end - # TODO We will make this configurable in a follow-up PR - show_ascii = false - if show_ascii + if length(system) ≤ show_preferences().max_particles_visualize_ascii ascii = visualize_ascii(system) if !isempty(ascii) extra_line && println(io)