(defvar squeeze-control-inhibit-display nil)
-(defun squeeze-update-state (string)
- (let (done-something)
- (dolist (line (split-string string "\n"))
- (when (squeeze-update-state-from-line line)
- (setq done-something t)))
- (when done-something
- (unless squeeze-control-inhibit-display
- (squeeze-control-display-players))))
- string)
+(lexical-let ((buffer ""))
+ (defun squeeze-update-state (string)
+ (if (cl-position ?\n string)
+ (let (done-something)
+ (setq string (concat buffer string))
+ (dolist (line (split-string string "\n"))
+ (when (squeeze-update-state-from-line line)
+ (setq done-something t)))
+ (when done-something
+ (unless squeeze-control-inhibit-display
+ (squeeze-control-display-players)))
+ (setq buffer ""))
+ (setq buffer (concat buffer string)))
+ string))
(defconst squeeze-player-line-regexp
"^\\(\\(?:[0-9a-f]\\{2\\}%3A\\)\\{5\\}[0-9a-f]\\{2\\}\\) ")
playerindex playerid uuid ip name model isplayer displaytype canpoweroff connected power volume)
(defun squeeze-string-plistify (string start end)
+ (unless end
+ (setq end (length string)))
(save-match-data
(let (result)
(loop
(when (> mend end)
(return))
(push (intern (format ":%s" (substring string (match-beginning 1) (match-end 1)))) result)
- (push (url-unhex-string (substring string (match-beginning 2) (match-end 2))) result)
+ (push (decode-coding-string
+ (url-unhex-string (substring string (match-beginning 2) (match-end 2)))
+ 'utf-8)
+ result)
(setq start mend))
(return)))
(nreverse result))))
(when startpos
(squeeze-string-plistify string startpos (length string)))))
+(defun squeeze-parse-count (string)
+ (save-match-data
+ (let ((countpos (string-match "count%3A\\([0-9]*\\)\\>" string)))
+ (if countpos
+ (string-to-number
+ (substring string (match-beginning 1) (match-end 1)))
+ (let ((kind
+ (progn (string-match "^\\([a-z]*\\) " string)
+ (substring string (match-beginning 1) (match-end 1)))))
+ (message "no count found in %s line" kind)
+ nil)))))
+
(defun squeeze-parse-players-line (string)
- (let ((countpos (string-match " count%3A\\([0-9]\\) " string))
- (startpos (match-end 0)))
- (unless countpos
- (message "no count found in players line"))
- (let ((count (string-to-number (substring string (match-beginning 1) (match-end 1))))
- result endpos)
- (dotimes (i (1- count))
- (setq endpos (progn (string-match " connected%3A[0-1] " string startpos)
- (match-end 0)))
- (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result)
- (setq startpos endpos))
- (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result)
- result)))
+ (let ((count (squeeze-parse-count string))
+ (startpos (string-match "playerindex" string))
+ result endpos)
+ (dotimes (i (1- count))
+ (setq endpos (progn (string-match " connected%3A[0-1] " string startpos)
+ (match-end 0)))
+ (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result)
+ (setq startpos endpos))
+ (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result)
+ result))
+
(defun squeeze-complete-command-at-point ()
(save-excursion
"serverstatus" "status" "displaystatus" "readdirectory"
;; Notifications
-
+
;; Alarm commands and queries
"alarm" "alarms"
"favorites"
))))
-(defun squeeze ()
+(defun squeeze-read-server-parameters (address port)
+ (let ((host (read-string "Host: " nil nil address))
+ (port (read-number "Port: " port)))
+ (cons host port)))
+
+(defun squeeze (&optional address port)
(interactive)
- (let ((buffer (make-comint-in-buffer "squeeze" nil
- (cons squeeze-server-address
- squeeze-server-port))))
+ (unless address (setq address squeeze-server-address))
+ (unless port (setq port squeeze-server-port))
+ (when current-prefix-arg
+ (let ((parameters (squeeze-read-server-parameters address port)))
+ (setq address (car parameters)
+ port (cdr parameters))))
+ (let ((buffer (make-comint-in-buffer "squeeze" nil (cons address port))))
(switch-to-buffer buffer)
(squeeze-mode)))
-(defun squeeze-control ()
+(defun squeeze-control (&optional address port)
(interactive)
- (squeeze)
+ (unless address (setq address squeeze-server-address))
+ (unless port (setq port squeeze-server-port))
+ (when current-prefix-arg
+ (let ((parameters (squeeze-read-server-parameters address port)))
+ (setq address (car parameters)
+ port (cdr parameters))))
+ (let ((current-prefix-arg nil))
+ (squeeze address port))
(let ((buffer (get-buffer-create "*squeeze-control*")))
(switch-to-buffer buffer)
(squeeze-control-listen)