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