Added terminal(), terminals() and splash() functions
This commit is contained in:
parent
c5abde30ff
commit
faa701af61
@ -5,7 +5,7 @@ using StatsBase, ColorSchemes, ColorTypes, StructC14N, ReusePatterns
|
|||||||
import Base.reset
|
import Base.reset
|
||||||
import Base.write
|
import Base.write
|
||||||
|
|
||||||
export @gp, @gsp, save, linestyles, palette, contourlines, hist
|
export @gp, @gsp, save, linestyles, palette, contourlines, hist, terminal, terminals
|
||||||
|
|
||||||
# ╭───────────────────────────────────────────────────────────────────╮
|
# ╭───────────────────────────────────────────────────────────────────╮
|
||||||
# │ TYPE DEFINITIONS │
|
# │ TYPE DEFINITIONS │
|
||||||
@ -61,6 +61,8 @@ const options = Options()
|
|||||||
# │ LOW LEVEL FUNCTIONS │
|
# │ LOW LEVEL FUNCTIONS │
|
||||||
# ╰───────────────────────────────────────────────────────────────────╯
|
# ╰───────────────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
|
version() = v"1.0-dev"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
# gpversion
|
# gpversion
|
||||||
@ -70,6 +72,7 @@ const options = Options()
|
|||||||
blocks).
|
blocks).
|
||||||
"""
|
"""
|
||||||
function gpversion()
|
function gpversion()
|
||||||
|
options.dry && (return v"0.0.0")
|
||||||
icmd = `$(options.cmd) --version`
|
icmd = `$(options.cmd) --version`
|
||||||
|
|
||||||
proc = open(`$icmd`, read=true)
|
proc = open(`$icmd`, read=true)
|
||||||
@ -282,7 +285,6 @@ end
|
|||||||
# ╰───────────────────────────────────────────────────────────────────╯
|
# ╰───────────────────────────────────────────────────────────────────╯
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function DrySession(sid::Symbol)
|
function DrySession(sid::Symbol)
|
||||||
global options
|
|
||||||
(sid in keys(sessions)) && error("Gnuplot session $sid is already active")
|
(sid in keys(sessions)) && error("Gnuplot session $sid is already active")
|
||||||
out = DrySession(sid, Vector{DataSet}(), [SinglePlot()], 1)
|
out = DrySession(sid, Vector{DataSet}(), [SinglePlot()], 1)
|
||||||
sessions[sid] = out
|
sessions[sid] = out
|
||||||
@ -292,7 +294,6 @@ end
|
|||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function GPSession(sid::Symbol)
|
function GPSession(sid::Symbol)
|
||||||
function readTask(sid, stream, channel)
|
function readTask(sid, stream, channel)
|
||||||
global options
|
|
||||||
saveOutput = false
|
saveOutput = false
|
||||||
|
|
||||||
while isopen(stream)
|
while isopen(stream)
|
||||||
@ -326,7 +327,6 @@ function GPSession(sid::Symbol)
|
|||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
global options
|
|
||||||
|
|
||||||
gpversion()
|
gpversion()
|
||||||
session = DrySession(sid)
|
session = DrySession(sid)
|
||||||
@ -370,7 +370,6 @@ end
|
|||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function getsession(sid::Symbol=options.default)
|
function getsession(sid::Symbol=options.default)
|
||||||
global options
|
|
||||||
if !(sid in keys(sessions))
|
if !(sid in keys(sessions))
|
||||||
if options.dry
|
if options.dry
|
||||||
DrySession(sid)
|
DrySession(sid)
|
||||||
@ -400,7 +399,6 @@ end
|
|||||||
"""
|
"""
|
||||||
write(gp::DrySession, str::AbstractString) = nothing
|
write(gp::DrySession, str::AbstractString) = nothing
|
||||||
function write(gp::GPSession, str::AbstractString)
|
function write(gp::GPSession, str::AbstractString)
|
||||||
global options
|
|
||||||
if options.verbose
|
if options.verbose
|
||||||
printstyled(color=:light_yellow, "GNUPLOT ($(gp.sid)) $str\n")
|
printstyled(color=:light_yellow, "GNUPLOT ($(gp.sid)) $str\n")
|
||||||
end
|
end
|
||||||
@ -436,7 +434,6 @@ end
|
|||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
writeread(gp::DrySession, str::AbstractString) = [""]
|
writeread(gp::DrySession, str::AbstractString) = [""]
|
||||||
function writeread(gp::GPSession, str::AbstractString)
|
function writeread(gp::GPSession, str::AbstractString)
|
||||||
global options
|
|
||||||
verbose = options.verbose
|
verbose = options.verbose
|
||||||
|
|
||||||
options.verbose = false
|
options.verbose = false
|
||||||
@ -517,7 +514,6 @@ end
|
|||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
function quit(gp::DrySession)
|
function quit(gp::DrySession)
|
||||||
global options
|
|
||||||
delete!(sessions, gp.sid)
|
delete!(sessions, gp.sid)
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
@ -939,10 +935,7 @@ end
|
|||||||
Quit the session and the associated gnuplot process (if any).
|
Quit the session and the associated gnuplot process (if any).
|
||||||
"""
|
"""
|
||||||
function quit(sid::Symbol)
|
function quit(sid::Symbol)
|
||||||
global options
|
(sid in keys(sessions)) || (return 0)
|
||||||
if !(sid in keys(sessions))
|
|
||||||
error("Gnuplot session $sid do not exists")
|
|
||||||
end
|
|
||||||
return quit(sessions[sid])
|
return quit(sessions[sid])
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -952,7 +945,6 @@ end
|
|||||||
Quit all the sessions and the associated gnuplot processes.
|
Quit all the sessions and the associated gnuplot processes.
|
||||||
"""
|
"""
|
||||||
function quitall()
|
function quitall()
|
||||||
global options
|
|
||||||
for sid in keys(sessions)
|
for sid in keys(sessions)
|
||||||
quit(sid)
|
quit(sid)
|
||||||
end
|
end
|
||||||
@ -994,11 +986,8 @@ function exec(gp::GPSession, command::String)
|
|||||||
|
|
||||||
return join(answer, "\n")
|
return join(answer, "\n")
|
||||||
end
|
end
|
||||||
function exec(s::String)
|
|
||||||
global options
|
|
||||||
exec(getsession(), s)
|
|
||||||
end
|
|
||||||
exec(sid::Symbol, s::String) = exec(getsession(sid), s)
|
exec(sid::Symbol, s::String) = exec(getsession(sid), s)
|
||||||
|
exec(s::String) = exec(getsession(), s)
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -1008,7 +997,6 @@ exec(sid::Symbol, s::String) = exec(getsession(sid), s)
|
|||||||
Set verbose flag to `true` or `false` (default: `false`).
|
Set verbose flag to `true` or `false` (default: `false`).
|
||||||
"""
|
"""
|
||||||
function setverbose(b::Bool)
|
function setverbose(b::Bool)
|
||||||
global options
|
|
||||||
options.verbose = b
|
options.verbose = b
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1084,7 +1072,6 @@ end
|
|||||||
# return nothing
|
# return nothing
|
||||||
# end
|
# end
|
||||||
# function repl()
|
# function repl()
|
||||||
# global options
|
|
||||||
# return repl(options.default)
|
# return repl(options.default)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
@ -1301,4 +1288,43 @@ function histo2segments(in_x, counts)
|
|||||||
return (x, y)
|
return (x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
terminals() = split(exec("print GPVAL_TERMINALS"), " ")
|
||||||
|
terminal() = exec("print GPVAL_TERM") * " " * exec("print GPVAL_TERMOPTIONS")
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
function splash(outputfile="")
|
||||||
|
quit(:splash)
|
||||||
|
gp = getsession(:splash)
|
||||||
|
if outputfile == ""
|
||||||
|
# Try to set a reasonably modern terminal. Setting the size
|
||||||
|
# is necessary for the text to be properly sized. The
|
||||||
|
# `noenhanced` option is required to display the "@" character
|
||||||
|
# (alternatively use "\\\\@", but it doesn't work on all
|
||||||
|
# terminals).
|
||||||
|
terms = terminals()
|
||||||
|
if "wxt" in terms
|
||||||
|
exec(gp, "set term wxt noenhanced size 600,300")
|
||||||
|
elseif "qt" in terms
|
||||||
|
exec(gp, "set term qt noenhanced size 600,300")
|
||||||
|
elseif "aqua" in terms
|
||||||
|
exec(gp, "set term aqua noenhanced size 600,300")
|
||||||
|
else
|
||||||
|
@warn "None of the `wxt`, `qt` and `aqua` terminals are available. Output may look strange.."
|
||||||
|
end
|
||||||
|
else
|
||||||
|
exec(gp, "set term unknown")
|
||||||
|
end
|
||||||
|
@gp :- :splash "set margin 0" "set border 0" "unset tics"
|
||||||
|
@gp :- :splash xr=[-0.3,1.7] yr=[-0.3,1.1]
|
||||||
|
@gp :- :splash "set origin 0,0" "set size 1,1"
|
||||||
|
@gp :- :splash "set label 1 at graph 1,1 right font 'Verdana,20' tc rgb '#4d64ae' ' Ver: " * string(version()) * "' "
|
||||||
|
@gp :- :splash "set arrow 1 from graph 0.05, 0.15 to graph 0.95, 0.15 size 0.2,20,60 noborder lw 9 lc rgb '#4d64ae'"
|
||||||
|
@gp :- :splash "set arrow 2 from graph 0.15, 0.05 to graph 0.15, 0.95 size 0.2,20,60 noborder lw 9 lc rgb '#4d64ae'"
|
||||||
|
@gp :- :splash ["0.35 0.65 @ 13253682'", "0.85 0.65 g 3774278", "1.3 0.65 p 9591203"] "w labels notit font 'Mono,160' tc rgb var"
|
||||||
|
(outputfile == "") || save(:splash, term="pngcairo transparent noenhanced size 600,300", output=outputfile)
|
||||||
|
nothing
|
||||||
|
end
|
||||||
|
|
||||||
end #module
|
end #module
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user