Add text/org show method for survey => result

This commit is contained in:
TEC 2022-05-21 00:24:47 +08:00
parent e4134063ea
commit ab6d9674a3
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 24 additions and 1 deletions

View File

@ -770,6 +770,11 @@ function show(io::IO, ::MIME"text/org", q::Question{T}) where {T}
end
end
function show(io::IO, ::MIME"text/org", (q, a)::Pair{<:Question, <:Answer})
printstyled(io, "- ", q.prompt, " :: ", color=:blue)
println(io, join(split(string(a.value), '\n'), "\n "))
end
function show(io::IO, m::MIME"text/org", part::SurveyPart)
printstyled(io, "* ", if isnothing(part.label)
"Unlabeled part"
@ -780,7 +785,16 @@ function show(io::IO, m::MIME"text/org", part::SurveyPart)
print(io, '\n')
for q in part.questions
show(io, m, q)
q === last(part.questions) || print(io, "\n")
end
end
function show(io::IO, m::MIME"text/org", (part, response)::Pair{SurveyPart, Response})
printstyled(io, "* ", if isnothing(part.label)
"Unlabeled part"
else part.label end, "\n\n", color=:yellow)
foreach(part.questions) do q
show(io, m, q => response[q.id])
last(part.questions) === q || print(io, '\n')
end
end
@ -797,4 +811,13 @@ function show(io::IO, m::MIME"text/org", s::Survey)
end
end
function show(io::IO, m::MIME"text/org", (s, response)::Pair{Survey, Response})
printstyled(io, "#+title: ", s.name, "\n\n", color=:magenta)
parts = [s[p] for p in 1:length(s)]
for part in parts
show(io, m, part => response)
part === last(parts) || print(io, "\n\n")
end
end
end