Compare commits

...

3 Commits

Author SHA1 Message Date
TEC 443552f217
Rename PkgExt to PkgUtils to avoid name conflicts
It's a weird bug, but I'm just going to work around it for now so I can
develop other packages that have a "PkgExt" extension without needing to
run Julia with --startup-file=no.
2024-06-03 15:27:19 +08:00
TEC d049d8aff6
REPL.TerminalMenus.terminal no longer exists
As of the latest master
2024-03-21 00:14:59 +08:00
TEC 5f896490e9
Restructure Pkg interaction 2024-02-29 03:38:58 +08:00
6 changed files with 65 additions and 40 deletions

View File

@ -28,7 +28,7 @@ QOI = "4b34888f-f399-49d4-9bb3-47ed5cae4e65"
TiffImages = "731e570b-9d59-4bfa-96dc-6df516fadf69"
[extensions]
PkgExt = "Pkg"
PkgUtils = "Pkg"
cairomakie = "CairoMakie"
gadfly = "Gadfly"
hdf5 = "HDF5"

6
ext/PkgUtils.jl Normal file
View File

@ -0,0 +1,6 @@
module PkgUtils
include(joinpath(dirname(@__DIR__), "src", "pkgstack.jl"))
using .PkgStack
end

View File

@ -18,6 +18,8 @@ include("cmdpuns.jl")
include("termsetup.jl")
include("about.jl")
include("pkgutils.jl")
include("autoloads.jl")
using .Autoloads
include("autoload_data.jl")
@ -25,41 +27,6 @@ include("autoload_data.jl")
include("sessions.jl")
using .Sessions
@static if VERSION <= v"1.10"
const Pkg = let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
@something(get(Base.loaded_modules, pkg_id, nothing),
Base.require(pkg_id))
end
lazypkg() = Pkg
include("../ext/PkgExt.jl")
using .PkgExt
else
function lazypkg()
pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
@something(get(Base.loaded_modules, pkg_id, nothing),
Base.require(pkg_id))
end
end
function ensureglobalpkg(pkg::String)
if isnothing(Base.find_package(pkg))
Pkg = lazypkg()
oldproj = Base.current_project()
try
Pkg.activate()
@info "Installing $pkg"
Pkg.add(pkg)
finally
if isnothing(oldproj)
Pkg.activate()
else
Pkg.activate(oldproj)
end
end
end
end
function theme_term end # For cairomakie.jl
function __init__()

View File

@ -1,8 +1,8 @@
module PkgExt
module PkgStack
import Setup: lazypkg
import Markdown: @md_str
import Setup: lazypkg
const Pkg = lazypkg()
function stack(envs)
@ -61,11 +61,14 @@ Unstack a previously stacked environment.
function environments()
envs = String[]
for depot in Base.DEPOT_PATH
@show depot
envdir = joinpath(depot, "environments")
isdir(envdir) || continue
for env in readdir(envdir)
if !isnothing(match(r"^__", env))
@info "Skip(1) $env"
elseif !isnothing(match(r"^v\d+\.\d+$", env))
@info "Skip(2) $env"
else
push!(envs, '@' * env)
end

47
src/pkgutils.jl Normal file
View File

@ -0,0 +1,47 @@
@static if VERSION <= v"1.10"
const Pkg = let pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
@something(get(Base.loaded_modules, pkg_id, nothing),
Base.require(pkg_id))
end
lazypkg() = Pkg
include("../ext/PkgUtils.jl")
using .PkgUtils
else
const Pkg = Ref{Module}()
function lazypkg()
if !isassigned(Pkg)
pkg_id = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
Pkg[] = @something(get(Base.loaded_modules, pkg_id, nothing),
Base.require(pkg_id))
end
Pkg[]
end
end
function withproject(f::Function, proj::Union{String, Nothing})
Pkg = lazypkg()
oldproj = Base.current_project()
try
if isnothing(proj)
Pkg.activate()
else
Pkg.activate(proj)
end
f()
finally
if isnothing(oldproj)
Pkg.activate()
else
Pkg.activate(oldproj)
end
end
end
function ensureglobalpkg(pkg::String)
isnothing(Base.find_package(pkg)) || return
withproject(nothing) do
@info "Installing $pkg"
lazypkg().add(pkg)
end
end

View File

@ -49,7 +49,9 @@ end
clearterm() = print("\e[2J")
function termcode()
REPL.Terminals.raw!(REPL.TerminalMenus.terminal, true)
term_env = get(ENV, "TERM", @static Sys.iswindows() ? "" : "dumb")
term = REPL.Terminals.TTYTerminal(term_env, stdin, stdout, stderr)
REPL.Terminals.raw!(term, true)
print("\eP+q544e\e\\")
output = @task readuntil(stdin, "\e\\")
schedule(output)
@ -61,7 +63,7 @@ function termcode()
catch
""
end
REPL.Terminals.raw!(REPL.TerminalMenus.terminal, false)
REPL.Terminals.raw!(term, false)
String(hex2bytes(last(split(value, '='))))
end