Added initcmd entry in state variable
This commit is contained in:
parent
0017f69cee
commit
a03fe92410
@ -58,9 +58,11 @@ mutable struct State
|
|||||||
dry::Bool
|
dry::Bool
|
||||||
cmd::String
|
cmd::String
|
||||||
default::Symbol; # default session name
|
default::Symbol; # default session name
|
||||||
|
initcmd::Vector{String} # Commands to initialize the gnuplot session (e.g., to set default terminal)
|
||||||
verbose::Bool; # verbosity level (true/false)
|
verbose::Bool; # verbosity level (true/false)
|
||||||
|
silent::Bool; # Silent flag
|
||||||
printlines::Int; # How many data lines are printed in log
|
printlines::Int; # How many data lines are printed in log
|
||||||
State() = new(Dict{Symbol, DrySession}(), true, "gnuplot", :default, false, 4)
|
State() = new(Dict{Symbol, DrySession}(), true, "gnuplot", :default, Vector{String}(), false, false, 4)
|
||||||
end
|
end
|
||||||
const state = State()
|
const state = State()
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ function CheckGnuplotVersion(cmd::AbstractString)
|
|||||||
if ver < v"4.7"
|
if ver < v"4.7"
|
||||||
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
error("gnuplot ver. >= 4.7 is required, but " * string(ver) * " was found.")
|
||||||
end
|
end
|
||||||
@info " Gnuplot version: " * string(ver)
|
#@info " Gnuplot version: " * string(ver)
|
||||||
return ver
|
return ver
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -161,7 +163,7 @@ end
|
|||||||
function getsession(sid::Symbol)
|
function getsession(sid::Symbol)
|
||||||
global state
|
global state
|
||||||
if !(sid in keys(state.sessions))
|
if !(sid in keys(state.sessions))
|
||||||
@info "Creating session $sid..."
|
#@info "Creating session $sid..."
|
||||||
if state.dry
|
if state.dry
|
||||||
gnuplot(sid)
|
gnuplot(sid)
|
||||||
else
|
else
|
||||||
@ -193,7 +195,7 @@ end
|
|||||||
println(gp::DrySession, str::AbstractString) = nothing
|
println(gp::DrySession, str::AbstractString) = nothing
|
||||||
function println(gp::Session, str::AbstractString)
|
function println(gp::Session, str::AbstractString)
|
||||||
global state
|
global state
|
||||||
if state.verbose
|
if !state.silent && state.verbose
|
||||||
printstyled(color=:yellow, "GNUPLOT ($(gp.sid)) $str\n")
|
printstyled(color=:yellow, "GNUPLOT ($(gp.sid)) $str\n")
|
||||||
end
|
end
|
||||||
w = write(gp.pin, strip(str) * "\n")
|
w = write(gp.pin, strip(str) * "\n")
|
||||||
@ -205,7 +207,7 @@ end
|
|||||||
|
|
||||||
function println(gp::Session, d::DataSource)
|
function println(gp::Session, d::DataSource)
|
||||||
if typeof(gp) == concretetype(Session)
|
if typeof(gp) == concretetype(Session)
|
||||||
if state.verbose
|
if !state.silent && state.verbose
|
||||||
for ii in 1:length(d.lines)
|
for ii in 1:length(d.lines)
|
||||||
v = d.lines[ii]
|
v = d.lines[ii]
|
||||||
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) $v\n")
|
printstyled(color=:light_black, "GNUPLOT ($(gp.sid)) $v\n")
|
||||||
@ -232,6 +234,8 @@ end
|
|||||||
writeread(gp::DrySession, str::AbstractString) = ""
|
writeread(gp::DrySession, str::AbstractString) = ""
|
||||||
function writeread(gp::Session, str::AbstractString)
|
function writeread(gp::Session, str::AbstractString)
|
||||||
global state
|
global state
|
||||||
|
silent = state.silent
|
||||||
|
state.silent = true
|
||||||
write(gp.pin, "print 'GNUPLOT_CAPTURE_BEGIN'\n")
|
write(gp.pin, "print 'GNUPLOT_CAPTURE_BEGIN'\n")
|
||||||
println(gp, strip(str))
|
println(gp, strip(str))
|
||||||
write(gp.pin, "print 'GNUPLOT_CAPTURE_END'\n")
|
write(gp.pin, "print 'GNUPLOT_CAPTURE_END'\n")
|
||||||
@ -242,6 +246,7 @@ function writeread(gp::Session, str::AbstractString)
|
|||||||
l == "GNUPLOT_CAPTURE_END" && break
|
l == "GNUPLOT_CAPTURE_END" && break
|
||||||
push!(out, l)
|
push!(out, l)
|
||||||
end
|
end
|
||||||
|
state.silent = silent
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -253,7 +258,7 @@ function setWindowTitle(session::Session)
|
|||||||
if term in ("aqua", "x11", "qt", "wxt")
|
if term in ("aqua", "x11", "qt", "wxt")
|
||||||
opts = writeread(session, "print GPVAL_TERMOPTIONS")[1]
|
opts = writeread(session, "print GPVAL_TERMOPTIONS")[1]
|
||||||
if findfirst("title", opts) == nothing
|
if findfirst("title", opts) == nothing
|
||||||
println(session, "set term $term $opts title 'Gnuplot.jl: $(session.sid)'")
|
writeread(session, "set term $term $opts title 'Gnuplot.jl: $(session.sid)'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -265,7 +270,6 @@ function reset(gp::DrySession)
|
|||||||
gp.plots = [SinglePlot()]
|
gp.plots = [SinglePlot()]
|
||||||
gp.curmid = 1
|
gp.curmid = 1
|
||||||
println(gp, "reset session")
|
println(gp, "reset session")
|
||||||
# setWindowTitle(gp)
|
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -620,8 +624,6 @@ function driver(args...; flag3d=false)
|
|||||||
error("The term tuple must contain at most two strings")
|
error("The term tuple must contain at most two strings")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#elseif arg[1] == :verb
|
|
||||||
# (loop == 1) && (state.verbose = arg[2])
|
|
||||||
else
|
else
|
||||||
(loop == 2) && newcmd(gp; [arg]...) # A cmd keyword
|
(loop == 2) && newcmd(gp; [arg]...) # A cmd keyword
|
||||||
end
|
end
|
||||||
@ -690,20 +692,32 @@ function gnuplot(sid::Symbol, cmd::AbstractString)
|
|||||||
saveOutput = false
|
saveOutput = false
|
||||||
|
|
||||||
while isopen(stream)
|
while isopen(stream)
|
||||||
line = convert(String, readline(stream))
|
line = readline(stream)
|
||||||
|
|
||||||
|
if (length(line) >= 1) && (line[1] == Char(0x1b)) # Escape (xterm -ti vt340)
|
||||||
|
buf = Vector{UInt8}()
|
||||||
|
append!(buf, convert(Vector{UInt8}, [line...]))
|
||||||
|
push!(buf, 0x0a)
|
||||||
|
c = 0x00
|
||||||
|
while c != 0x1b
|
||||||
|
c = read(stream, 1)[1]
|
||||||
|
push!(buf, c)
|
||||||
|
end
|
||||||
|
c = read(stream, 1)[1]
|
||||||
|
push!(buf, c)
|
||||||
|
write(stdout, buf)
|
||||||
|
continue
|
||||||
|
end
|
||||||
if line == "GNUPLOT_CAPTURE_BEGIN"
|
if line == "GNUPLOT_CAPTURE_BEGIN"
|
||||||
saveOutput = true
|
saveOutput = true
|
||||||
else
|
else
|
||||||
(saveOutput) && (put!(channel, line))
|
if (line != "") && (line != "GNUPLOT_CAPTURE_END") && (!state.silent)
|
||||||
if line == "GNUPLOT_CAPTURE_END"
|
|
||||||
saveOutput = false
|
|
||||||
elseif line != ""
|
|
||||||
printstyled(color=:cyan, "GNUPLOT ($sid) -> $line\n")
|
printstyled(color=:cyan, "GNUPLOT ($sid) -> $line\n")
|
||||||
#(state.verbose >= 1) && (printstyled(color=:cyan, "GNUPLOT ($sid) -> $line\n"))
|
end
|
||||||
|
(saveOutput) && (put!(channel, line))
|
||||||
|
(line == "GNUPLOT_CAPTURE_END") && (saveOutput = false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
global state
|
|
||||||
delete!(state.sessions, sid)
|
delete!(state.sessions, sid)
|
||||||
return nothing
|
return nothing
|
||||||
end
|
end
|
||||||
@ -734,6 +748,10 @@ function gnuplot(sid::Symbol, cmd::AbstractString)
|
|||||||
state.sessions[sid] = out
|
state.sessions[sid] = out
|
||||||
|
|
||||||
setWindowTitle(out)
|
setWindowTitle(out)
|
||||||
|
for l in state.initcmd
|
||||||
|
writeread(out, l)
|
||||||
|
end
|
||||||
|
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1021,6 +1039,12 @@ function setverbose(b::Bool)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function initcmd()
|
||||||
|
global state
|
||||||
|
return state.initcmd
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
`save(...)`
|
`save(...)`
|
||||||
@ -1113,7 +1137,7 @@ function contourlines(args...; cntrparam="level auto 10", offset=0, width=0.)
|
|||||||
d = cumsum(elength(curx, cury))
|
d = cumsum(elength(curx, cury))
|
||||||
i0 = findall(d .<= width); sort!(i0)
|
i0 = findall(d .<= width); sort!(i0)
|
||||||
i1 = findall(d .> width)
|
i1 = findall(d .> width)
|
||||||
n = 1
|
if (length(i0) > 0) && (length(i1) > 0)
|
||||||
rot1 = atan(cury[i0[end]]-cury[i0[1]], curx[i0[end]]-curx[i0[1]]) * 180 / pi
|
rot1 = atan(cury[i0[end]]-cury[i0[1]], curx[i0[end]]-curx[i0[1]]) * 180 / pi
|
||||||
rot = round(mod(rot1, 360))
|
rot = round(mod(rot1, 360))
|
||||||
x = mean(curx[i0])
|
x = mean(curx[i0])
|
||||||
@ -1123,6 +1147,7 @@ function contourlines(args...; cntrparam="level auto 10", offset=0, width=0.)
|
|||||||
cury = cury[i1]
|
cury = cury[i1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
append!(outc, string.(curx) .* " " .* string.(cury))
|
append!(outc, string.(curx) .* " " .* string.(cury))
|
||||||
push!(outc, "")
|
push!(outc, "")
|
||||||
empty!(curx)
|
empty!(curx)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user