Skip to content

Commit

Permalink
prettyprint vector of notes as well (#113)
Browse files Browse the repository at this point in the history
* prettyprint vector of notes as well

* big increase of note vector display
  • Loading branch information
Datseris authored Jan 26, 2019
1 parent c84f097 commit 66eb2fd
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/note.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Base.lastindex(n::Notes) = lastindex(n.notes)
Base.firstindex(n::Notes) = firstindex(n.notes)
Base.getindex(n::Notes, i::Int) = n.notes[i]
Base.getindex(n::Notes, r) = Notes(n.notes[r], n.tpq)
Base.view(n::Notes, r) = view(n.notes, r)

# Pushing
Base.push!(no::Notes{N}, n::N) where {N <: AbstractNote} = push!(no.notes, n)
Expand Down Expand Up @@ -171,15 +172,31 @@ end
function Base.show(io::IO, ::MIME"text/plain", notes::Notes{N}) where {N}
mprint = nameof(N)
print(io, "$(length(notes)) $(mprint)s with tpq=$(notes.tpq)")
i = 1
while i min(10, length(notes))
print(io, "\n", " ", notes[i])
i += 1
end
if length(notes) > 10
_notevectorprint(io, notes)
end
function Base.show(io::IO, notes::Vector{N}) where {N<:AbstractNote}
mprint = nameof(N)
print(io, "$(length(notes))-element Vector{$mprint}")
_notevectorprint(io, notes)
end

function _notevectorprint(io, notes)
s = 7
if length(notes) > 2s
for note in (@view notes[1:s])
print(io, "\n", " ", note)
end
print(io, "\n", "")
for note in (@view notes[end-s+1:end])
print(io, "\n", " ", note)
end
else
for note in notes
print(io, "\n", " ", note)
end
end
end

function Base.show(io::IO, notes::Notes{N}) where {N}
mprint = nameof(N)
print(io, "Notes{$(mprint)} with $(length(notes)) notes")
Expand Down

0 comments on commit 66eb2fd

Please sign in to comment.