fix(tui): Surgical parenthesis balance repair for TUI client main loop
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
Some checks failed
Deploy-Agent-V15-Stdin / JOB-V15-STDIN (push) Failing after 3s
This commit is contained in:
@@ -67,54 +67,54 @@ The OpenCortex TUI Client is a standalone Common Lisp application built on **Cro
|
|||||||
(bt:make-thread #'listen-thread :name "tui-listener")
|
(bt:make-thread #'listen-thread :name "tui-listener")
|
||||||
|
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(with-screen (scr :input-echoing nil :input-blocking nil :enable-colors t :cursor-visible t)
|
(with-screen (scr :input-echoing nil :input-blocking nil :enable-colors t :cursor-visible t)
|
||||||
(let* ((h (height scr))
|
(let* ((h (height scr))
|
||||||
(w (width scr))
|
(w (width scr))
|
||||||
(chat-win (make-instance 'window :height (- h 2) :width w :position (list 0 0)))
|
(chat-win (make-instance 'window :height (- h 2) :width w :position (list 0 0)))
|
||||||
(status-win (make-instance 'window :height 1 :width w :position (list (- h 2) 0)))
|
(status-win (make-instance 'window :height 1 :width w :position (list (- h 2) 0)))
|
||||||
(input-win (make-instance 'window :height 1 :width w :position (list (- h 1) 0))))
|
(input-win (make-instance 'window :height 1 :width w :position (list (- h 1) 0))))
|
||||||
|
|
||||||
;; Initial Prompt
|
;; Initial Prompt
|
||||||
(add-string input-win "> ")
|
(add-string input-win "> ")
|
||||||
(refresh input-win)
|
(refresh input-win)
|
||||||
|
|
||||||
(loop while *is-running* do
|
(loop while *is-running* do
|
||||||
;; 1. Handle incoming messages
|
;; 1. Handle incoming messages
|
||||||
(let ((new-msgs (dequeue-msgs)))
|
(let ((new-msgs (dequeue-msgs)))
|
||||||
(when new-msgs
|
(when new-msgs
|
||||||
(dolist (msg new-msgs)
|
(dolist (msg new-msgs)
|
||||||
(push msg *chat-history*)
|
(push msg *chat-history*)
|
||||||
(setf *chat-history* (subseq *chat-history* 0 (min (length *chat-history*) 500))))
|
(setf *chat-history* (subseq *chat-history* 0 (min (length *chat-history*) 500))))
|
||||||
|
|
||||||
(clear chat-win)
|
(clear chat-win)
|
||||||
(let ((line-num 0))
|
(let ((line-num 0))
|
||||||
(dolist (m (reverse (subseq *chat-history* 0 (min (length *chat-history*) (- h 3)))))
|
(dolist (m (reverse (subseq *chat-history* 0 (min (length *chat-history*) (- h 3)))))
|
||||||
(add-string chat-win m :y line-num :x 0)
|
(add-string chat-win m :y line-num :x 0)
|
||||||
(incf line-num)))
|
(incf line-num)))
|
||||||
(refresh chat-win)))
|
(refresh chat-win)))
|
||||||
|
|
||||||
;; 2. Render Status Bar
|
;; 2. Render Status Bar
|
||||||
(clear status-win)
|
(clear status-win)
|
||||||
(add-string status-win *status-text* :attributes '(:reverse))
|
(add-string status-win *status-text* :attributes '(:reverse))
|
||||||
(refresh status-win)
|
(refresh status-win)
|
||||||
|
|
||||||
;; 3. Handle Keyboard Input
|
;; 3. Handle Keyboard Input
|
||||||
(let ((ch (get-char scr)))
|
(let ((ch (get-char scr)))
|
||||||
(when ch
|
(when ch
|
||||||
(cond
|
(cond
|
||||||
((eq ch #\Newline)
|
((eq ch #\Newline)
|
||||||
(let ((cmd (coerce *input-buffer* 'string)))
|
(let ((cmd (coerce *input-buffer* 'string)))
|
||||||
(setf (fill-pointer *input-buffer*) 0)
|
(setf (fill-pointer *input-buffer*) 0)
|
||||||
(when (> (length cmd) 0)
|
(when (> (length cmd) 0)
|
||||||
(let ((framed (opencortex:frame-message (format nil "~s" (list :type :EVENT :payload (list :sensor :chat-message :text cmd))))))
|
(let ((framed (opencortex:frame-message (format nil "~s" (list :type :EVENT :payload (list :sensor :chat-message :text cmd))))))
|
||||||
(format *stream* "~a" framed)
|
(format *stream* "~a" framed)
|
||||||
(finish-output *stream*)))
|
(finish-output *stream*)))
|
||||||
(when (string= cmd "/exit") (setf *is-running* nil))))
|
(when (string= cmd "/exit") (setf *is-running* nil))))
|
||||||
((eq ch :backspace)
|
((eq ch :backspace)
|
||||||
(when (> (length *input-buffer*) 0)
|
(when (> (length *input-buffer*) 0)
|
||||||
(decf (fill-pointer *input-buffer*))))
|
(decf (fill-pointer *input-buffer*))))
|
||||||
((characterp ch)
|
((characterp ch)
|
||||||
(vector-push-extend ch *input-buffer*))))
|
(vector-push-extend ch *input-buffer*)))))
|
||||||
|
|
||||||
(clear input-win)
|
(clear input-win)
|
||||||
(add-string input-win (concatenate 'string "> " (coerce *input-buffer* 'string)))
|
(add-string input-win (concatenate 'string "> " (coerce *input-buffer* 'string)))
|
||||||
|
|||||||
@@ -54,54 +54,54 @@
|
|||||||
(bt:make-thread #'listen-thread :name "tui-listener")
|
(bt:make-thread #'listen-thread :name "tui-listener")
|
||||||
|
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(with-screen (scr :input-echoing nil :input-blocking nil :enable-colors t :cursor-visible t)
|
(with-screen (scr :input-echoing nil :input-blocking nil :enable-colors t :cursor-visible t)
|
||||||
(let* ((h (height scr))
|
(let* ((h (height scr))
|
||||||
(w (width scr))
|
(w (width scr))
|
||||||
(chat-win (make-instance 'window :height (- h 2) :width w :position (list 0 0)))
|
(chat-win (make-instance 'window :height (- h 2) :width w :position (list 0 0)))
|
||||||
(status-win (make-instance 'window :height 1 :width w :position (list (- h 2) 0)))
|
(status-win (make-instance 'window :height 1 :width w :position (list (- h 2) 0)))
|
||||||
(input-win (make-instance 'window :height 1 :width w :position (list (- h 1) 0))))
|
(input-win (make-instance 'window :height 1 :width w :position (list (- h 1) 0))))
|
||||||
|
|
||||||
;; Initial Prompt
|
;; Initial Prompt
|
||||||
(add-string input-win "> ")
|
(add-string input-win "> ")
|
||||||
(refresh input-win)
|
(refresh input-win)
|
||||||
|
|
||||||
(loop while *is-running* do
|
(loop while *is-running* do
|
||||||
;; 1. Handle incoming messages
|
;; 1. Handle incoming messages
|
||||||
(let ((new-msgs (dequeue-msgs)))
|
(let ((new-msgs (dequeue-msgs)))
|
||||||
(when new-msgs
|
(when new-msgs
|
||||||
(dolist (msg new-msgs)
|
(dolist (msg new-msgs)
|
||||||
(push msg *chat-history*)
|
(push msg *chat-history*)
|
||||||
(setf *chat-history* (subseq *chat-history* 0 (min (length *chat-history*) 500))))
|
(setf *chat-history* (subseq *chat-history* 0 (min (length *chat-history*) 500))))
|
||||||
|
|
||||||
(clear chat-win)
|
(clear chat-win)
|
||||||
(let ((line-num 0))
|
(let ((line-num 0))
|
||||||
(dolist (m (reverse (subseq *chat-history* 0 (min (length *chat-history*) (- h 3)))))
|
(dolist (m (reverse (subseq *chat-history* 0 (min (length *chat-history*) (- h 3)))))
|
||||||
(add-string chat-win m :y line-num :x 0)
|
(add-string chat-win m :y line-num :x 0)
|
||||||
(incf line-num)))
|
(incf line-num)))
|
||||||
(refresh chat-win)))
|
(refresh chat-win)))
|
||||||
|
|
||||||
;; 2. Render Status Bar
|
;; 2. Render Status Bar
|
||||||
(clear status-win)
|
(clear status-win)
|
||||||
(add-string status-win *status-text* :attributes '(:reverse))
|
(add-string status-win *status-text* :attributes '(:reverse))
|
||||||
(refresh status-win)
|
(refresh status-win)
|
||||||
|
|
||||||
;; 3. Handle Keyboard Input
|
;; 3. Handle Keyboard Input
|
||||||
(let ((ch (get-char scr)))
|
(let ((ch (get-char scr)))
|
||||||
(when ch
|
(when ch
|
||||||
(cond
|
(cond
|
||||||
((eq ch #\Newline)
|
((eq ch #\Newline)
|
||||||
(let ((cmd (coerce *input-buffer* 'string)))
|
(let ((cmd (coerce *input-buffer* 'string)))
|
||||||
(setf (fill-pointer *input-buffer*) 0)
|
(setf (fill-pointer *input-buffer*) 0)
|
||||||
(when (> (length cmd) 0)
|
(when (> (length cmd) 0)
|
||||||
(let ((framed (opencortex:frame-message (format nil "~s" (list :type :EVENT :payload (list :sensor :chat-message :text cmd))))))
|
(let ((framed (opencortex:frame-message (format nil "~s" (list :type :EVENT :payload (list :sensor :chat-message :text cmd))))))
|
||||||
(format *stream* "~a" framed)
|
(format *stream* "~a" framed)
|
||||||
(finish-output *stream*)))
|
(finish-output *stream*)))
|
||||||
(when (string= cmd "/exit") (setf *is-running* nil))))
|
(when (string= cmd "/exit") (setf *is-running* nil))))
|
||||||
((eq ch :backspace)
|
((eq ch :backspace)
|
||||||
(when (> (length *input-buffer*) 0)
|
(when (> (length *input-buffer*) 0)
|
||||||
(decf (fill-pointer *input-buffer*))))
|
(decf (fill-pointer *input-buffer*))))
|
||||||
((characterp ch)
|
((characterp ch)
|
||||||
(vector-push-extend ch *input-buffer*))))
|
(vector-push-extend ch *input-buffer*)))))
|
||||||
|
|
||||||
(clear input-win)
|
(clear input-win)
|
||||||
(add-string input-win (concatenate 'string "> " (coerce *input-buffer* 'string)))
|
(add-string input-win (concatenate 'string "> " (coerce *input-buffer* 'string)))
|
||||||
|
|||||||
Reference in New Issue
Block a user