colorize prompts to and from codex

This commit is contained in:
2026-01-09 13:49:48 -05:00
parent e4849c4366
commit 22daba6368

View File

@@ -23,6 +23,21 @@
"Chat with Codex."
:group 'tools)
(defface codex-prompt-delimiter-face
'((t :inherit shadow))
"Face for prompt delimiters."
:group 'codex)
(defface codex-user-prompt-face
'((t :inherit font-lock-keyword-face))
"Face for the user prompt label."
:group 'codex)
(defface codex-assistant-prompt-face
'((t :inherit font-lock-function-name-face))
"Face for the Codex prompt label."
:group 'codex)
(defcustom codex-command "codex"
"Codex executable to invoke."
:type 'string
@@ -63,6 +78,9 @@
(defvar-local codex--prompt-start nil)
(defun codex--propertize-label (text face)
(propertize text 'face face 'rear-nonsticky '(face)))
(defun list->hash-set (list &optional test)
"Return a hash table whose keys are the elements of LIST."
(let ((ht (make-hash-table :test (or test #'equal))))
@@ -75,19 +93,19 @@
(defun prompt-delimiter ()
(newline)
(insert "---")
(insert (codex--propertize-label "---" 'codex-prompt-delimiter-face))
(newline))
(defun user-prompt ()
(prompt-delimiter)
(insert "User:")
(insert (codex--propertize-label "User:" 'codex-user-prompt-face))
(newline)
(setq codex--prompt-start (point-marker)))
(defun codex--write-to-chat (msg)
(with-codex-buffer
(newline)
(insert "Codex:")
(insert (codex--propertize-label "Codex:" 'codex-assistant-prompt-face))
(newline)
(insert msg)
(user-prompt)))
@@ -213,3 +231,15 @@
(insert (concat "Switching to session " session-id))
(insert "Switching to new session"))
(user-prompt))))
(defun codex-rename-current-session (name)
(interactive "sNew name: ")
(let* ((sessions (codex--read-sessions-file))
(new-sessions
(mapcar
(lambda (tup)
(if (string-equal (cdr tup) codex--session-id)
(cons name (cdr tup))
tup))
sessions)))
(codex--write-sessions-file new-sessions)))