colorize prompts to and from codex
This commit is contained in:
36
codex.el
36
codex.el
@@ -23,6 +23,21 @@
|
|||||||
"Chat with Codex."
|
"Chat with Codex."
|
||||||
:group 'tools)
|
: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"
|
(defcustom codex-command "codex"
|
||||||
"Codex executable to invoke."
|
"Codex executable to invoke."
|
||||||
:type 'string
|
:type 'string
|
||||||
@@ -63,6 +78,9 @@
|
|||||||
|
|
||||||
(defvar-local codex--prompt-start nil)
|
(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)
|
(defun list->hash-set (list &optional test)
|
||||||
"Return a hash table whose keys are the elements of LIST."
|
"Return a hash table whose keys are the elements of LIST."
|
||||||
(let ((ht (make-hash-table :test (or test #'equal))))
|
(let ((ht (make-hash-table :test (or test #'equal))))
|
||||||
@@ -75,19 +93,19 @@
|
|||||||
|
|
||||||
(defun prompt-delimiter ()
|
(defun prompt-delimiter ()
|
||||||
(newline)
|
(newline)
|
||||||
(insert "---")
|
(insert (codex--propertize-label "---" 'codex-prompt-delimiter-face))
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
(defun user-prompt ()
|
(defun user-prompt ()
|
||||||
(prompt-delimiter)
|
(prompt-delimiter)
|
||||||
(insert "User:")
|
(insert (codex--propertize-label "User:" 'codex-user-prompt-face))
|
||||||
(newline)
|
(newline)
|
||||||
(setq codex--prompt-start (point-marker)))
|
(setq codex--prompt-start (point-marker)))
|
||||||
|
|
||||||
(defun codex--write-to-chat (msg)
|
(defun codex--write-to-chat (msg)
|
||||||
(with-codex-buffer
|
(with-codex-buffer
|
||||||
(newline)
|
(newline)
|
||||||
(insert "Codex:")
|
(insert (codex--propertize-label "Codex:" 'codex-assistant-prompt-face))
|
||||||
(newline)
|
(newline)
|
||||||
(insert msg)
|
(insert msg)
|
||||||
(user-prompt)))
|
(user-prompt)))
|
||||||
@@ -213,3 +231,15 @@
|
|||||||
(insert (concat "Switching to session " session-id))
|
(insert (concat "Switching to session " session-id))
|
||||||
(insert "Switching to new session"))
|
(insert "Switching to new session"))
|
||||||
(user-prompt))))
|
(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)))
|
||||||
|
|||||||
Reference in New Issue
Block a user