truncate long messages when printing osc debug messages

This commit is contained in:
Jamie Forth 2015-08-21 16:30:14 +01:00
parent ccb3f2d5a9
commit 9fde4ea5ce
2 changed files with 16 additions and 8 deletions

View file

@ -27,5 +27,5 @@
address port #\Tab timetag #\Tab
(when timetag (timetag->unix-time timetag))
#\Tab #\Tab)
(format-osc-data data stream)
(format-osc-data data :stream stream)
(format stream "~%"))

View file

@ -35,15 +35,23 @@
:timetag timetag
:elements elements))
(defgeneric format-osc-data (data &optional stream))
(defgeneric format-osc-data (data &key stream width))
(defmethod format-osc-data ((message message) &optional (stream t))
(format stream "~a~{ ~a~}~%"
(command message)
(args message)))
(defmethod format-osc-data ((message message) &key (stream t)
(width 80))
(let ((args-string (format nil "~{~a~^ ~}" (args message))))
(when (> (length args-string) width)
(setf args-string
(concatenate 'string
(subseq args-string 0 width)
"...")))
(format stream "~a~a ~a~%"
#\Tab
(command message)
args-string)))
(defmethod format-osc-data ((bundle bundle) &optional (stream t))
(defmethod format-osc-data ((bundle bundle) &key (stream t) (width 80))
(format stream "~&[ ~a~%" (timetag bundle))
(dolist (element (elements bundle))
(format-osc-data element stream))
(format-osc-data element :stream stream :width width))
(format stream "~&]~%"))