ADDED http/elisp-http-make-content.el Index: http/elisp-http-make-content.el ================================================================== --- http/elisp-http-make-content.el +++ http/elisp-http-make-content.el @@ -0,0 +1,89 @@ +;;(load "~/glibc/dark_c/emacs-symfony-cli/http-content.el") + +;;;(global-set-key (kbd "M-m") #'(lambda () (interactive) (elisp-http-login-content))) + +(setq http-token "") + +(defun elisp-http-get-header () + (if-let* ((auth-header (unless (or (null http-token) + (string= http-token "")) + (list (cons "Authorization" (concat "Bearer " http-token))))) + (headers (append + '(("Host" . "localhost:8080") + ("Accept" . "*/*") + ("Content-Type" . "application/json")) + auth-header))) + headers + )) + +(setq my-headers + (or (elisp-http-get-header) + '(("Host" . "localhost:8080") + ("Accept" . "*/*") + ("Content-Type" . "application/json")))) + +(defun elisp-http-register-line () + (let* ((_path (elisp-http-prompt-api)) + (path (format "POST /%s HTTP/1.1" _path))) + path)) + +(defun elisp-http-get-line () + (let* ((_path (elisp-http-prompt-api)) + (path (format "GET /%s HTTP/1.1" _path))) + path)) + +;;;(elisp-http-register-line) + +(defun elisp-http-make-content () + (let ((request-line (elisp-http-set-request-line))) + (concat + request-line "\n" + (mapconcat (lambda (x) + (format "%s: %s" (car x) (cdr x))) + my-headers + "\n")))) + +;;;(elisp-http-make-content) + +(defun elisp-http-register-content () + "Generate HTTP request content for registration with JSON payload." + (let* ((email (elisp-http-prompt-email)) + (password (elisp-http-prompt-password)) + (request-line (elisp-http-register-line)) + (json-body (json-encode `(("email" . ,email) ("password" . ,password)))) + (headers (append my-headers + (list (cons "Content-Length" + (number-to-string (string-bytes json-body)))))) + (header-block + (mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x))) + headers + "\n"))) + (concat request-line "\n" + header-block "\n\n" + json-body))) + +;; Пример использования: +;;;(elisp-http-register-content) + +(defun elisp-http-login-content () + "Generate HTTP request content for login with JSON payload using 'email'." + (let* ((email (elisp-http-prompt-email)) + (password (elisp-http-prompt-password)) + (request-line (format "POST /%s HTTP/1.1" (elisp-http-prompt-api))) + (json-body (json-encode `(("email" . ,email) ("password" . ,password)))) + (headers (append my-headers + (list (cons "Content-Length" + (number-to-string (string-bytes json-body)))))) + (header-block + (mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x))) + headers + "\n"))) + (concat request-line "\n" + header-block "\n\n" + json-body))) +;;;(elisp-http-login-content) + +;;;(setq youo (elisp-http-login-content)) + +;;; "email": "somex@gmail.com", +;;; "password": "test1234" ADDED http/elisp-http-prompt.el Index: http/elisp-http-prompt.el ================================================================== --- http/elisp-http-prompt.el +++ http/elisp-http-prompt.el @@ -0,0 +1,13 @@ +(defun elisp-http-prompt-api () + (let* ((prompt-api (propertize "апи: " 'face '(:foreground "cyan" :weight bold)))) + (read-from-minibuffer prompt-api))) + +(defun elisp-http-prompt-email () + (let* ((prompt-register (propertize "email: " 'face '(:foreground "cyan" :weight bold)))) + (read-from-minibuffer prompt-register))) + + +(defun elisp-http-prompt-password () + (let* ((prompt-register (propertize "password: " 'face '(:foreground "red" :weight bold)))) + (read-from-minibuffer prompt-register))) + ADDED http/elisp-http-style.el Index: http/elisp-http-style.el ================================================================== --- http/elisp-http-style.el +++ http/elisp-http-style.el @@ -0,0 +1,119 @@ +;;; styles.el --- Summary + +;;; Commentary: +;; Brief description of the file. + +;;; Code: +(defface tetramorf-style-face + ;;;cosmic face + '((t (:foreground "purple" + :background "black" + :weight ultra-bold + :height 2.0 + :slant italic + :underline nil + :box (:line-width 1 :color "blue violet") + :family "Courier New"))) + "Инферно стиль с элементами темной эстетики.") + +(defface aldebaran-metal-face + '((t (:foreground "silver" + :background "black" + :weight ultra-bold + :height 2.0 + :slant normal + :underline t + :box (:line-width 2 :color "gray30" :style released-button) + :family "Consolas"))) + "Металлический стиль с ощущением силы и мощи.") + +(defface info-poetry-face + '((t (:foreground "lavender" + :background "midnight blue" + :weight light + :height 1.8 + :slant italic + :underline t + :box (:line-width 1 :color "thistle4" :style released-button) + :family "Georgia"))) + "Поэтический стиль с оттенками ночного неба и загадочности.") + +(defface info-poetry-face-1 + '((t (:foreground "lavender" + :background "midnight blue" + :weight light + :height 1.3 + :slant italic + :underline t + :box (:line-width 1 :color "thistle4" :style released-button) + :family "Georgia"))) + "Поэтический стиль с оттенками ночного неба и загадочности.") + + +(defface xxxface + '((((class color) (min-colors 88) (background light)) + :background "darkseagreen2") + (((class color) (min-colors 88) (background dark)) + :background "darkolivegreen") + (((class color) (min-colors 16) (background light)) + :background "darkseagreen2") + (((class color) (min-colors 16) (background dark)) + :background "darkolivegreen") + (((class color) (min-colors 8)) + :background "green" :foreground "black") + (t :inverse-video t)) + "Basic face for highlighting." + :group 'basic-faces) + +(defface evil-error-face + '((t (:foreground "firebrick1" + :background "black" + :weight bold + :slant normal + :underline t + :inverse-video t + :box (:line-width 2 :color "dark red" :style released-button) + :height 2.0 + :family "Monospace"))) + "Зловещий стиль для отображения ошибок.") + +(defface cyberpunk-success-face + '((t (:foreground "lime" + :background "black" + :weight bold + :slant normal + :underline t + :box (:line-width 2 :color "cyan" :style solid) + :height 2.5 + :family "Courier New"))) + "Киберпанковский стиль для успешных сообщений.") + +(defface cyberpunk-unsuccess-face + '((t (:foreground "red" + :background "black" + :weight bold + :slant normal + :underline t + :box (:line-width 2 :color "cyan" :style solid) + :height 2.5 + :family "Courier New"))) + "Киберпанковский стиль для успешных сообщений.") + + + +(defface cyberpunk-last-value-face + '((t (:foreground "lime" + :background "black" + :weight bold + :slant italic + :box (:line-width 3 :color "lime" :style released-button) + :height 2.4 + :family "Courier New"))) + "Cyberpunk style for displaying the last value.") + + +(provide 'styles) +;;; styles.el ends here +;;; styles.el --- Summary + + ADDED http/elisp-http.el Index: http/elisp-http.el ================================================================== --- http/elisp-http.el +++ http/elisp-http.el @@ -0,0 +1,52 @@ +(load "~/glibc/dark_c/emacs-symfony-cli/http-content.el") +(load "~/glibc/dark_c/emacs-symfony-cli/elisp-http-style.el") +(load "~/glibc/dark_c/emacs-symfony-cli/elisp-http-prompt.el") +;;;;(global-set-key (kbd "M-m") #'(lambda () (interactive) (elisp-http) (monitor-http-buffer))) + +;;(setq http-content (elisp-http-register-content)) +;;(setq http-content (elisp-http-make-content)) +;;(setq http-content (elisp-http-login-content)) + +http-content + + +(defun elisp-http () + (interactive) + (make-network-process + :name "elisp-post" + :host "localhost" + :service 8080 + :buffer "*X*" + :nowait t + :filter (lambda (process-name output-data) + (with-current-buffer (process-buffer process-name) + (unless (bound-and-true-p already-scaled) + (setq-local already-scaled t) + (text-scale-increase 4)) + (goto-char (point-max)) + (insert output-data))) + :sentinel (lambda (proc event) + (when (string= event "open\n") + (process-send-string + proc + http-content + ))))) + +(defvar monitor-http-buffer--timer nil) + + +(defun monitor-http-buffer () + (setq monitor-http-buffer--timer + (run-at-time 1 1 + (lambda () + (let ((buf (get-buffer "*X*"))) + (when (and (buffer-live-p buf) + (> (buffer-size buf) 0)) + (psysho-log "[ELISP-HTTP] Пришли данные. Смотрим...") + (display-buffer buf) + (when (timerp monitor-http-buffer--timer) + (cancel-timer monitor-http-buffer--timer)))))))) + + + + ADDED http/http-content.el Index: http/http-content.el ================================================================== --- http/http-content.el +++ http/http-content.el @@ -0,0 +1,2 @@ +(defvar http-content + "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" "содержание http") ADDED http/issue Index: http/issue ================================================================== --- http/issue +++ http/issue @@ -0,0 +1,25 @@ +цель написать клиента наподобие постмана +чтобы этот клиент мог забирать +php bin/console debug:router --format=json > routes.json +вот такой файл +и сразу пользоваться. плюс из базы брать юзера. +тут же консольно брать токен. и все чтобы очень удобно было + +| Событие `event` | Значение | +| ------------------------------- | ------------------------------------------------- | +| `"open\n"` | Успешное соединение (для клиента при `:nowait t`) | +| `"failed with code N\n"` | Ошибка соединения, `N` — код errno | +| `"connection broken by peer\n"` | Сервер внезапно закрыл соединение | +| `"closed\n"` | Соединение закрыто (обычно после получения всего) | +| `"deleted\n"` | Процесс был удалён | +| `"exit N\n"` | Процесс завершился с кодом `N` | +| `"signal SIG\n"` | Процесс получил сигнал | + + +задача - передать токен пользователя в пост запрос +проверить на авторизации пост запрос + + +итак вся суть это формирование контента +давай +сначала зарегаюсь через кли просто ADDED http/scratch.el Index: http/scratch.el ================================================================== --- http/scratch.el +++ http/scratch.el @@ -0,0 +1,75 @@ +(defvar monitor-http-buffer--timer nil + "Таймер для мониторинга буфера *X*.") + +(defun monitor-http-buffer () + (setq monitor-http-buffer--timer + (run-at-time 1 1 + (lambda () + (let ((buf (get-buffer "*X*"))) + (when (and (buffer-live-p buf) + (> (with-current-buffer buf + (- (point-max) (point-min))) + 0)) + (psysho-log "[MONITOR] Буфер *X* заполнен, открываю...") + (display-buffer buf) + (when monitor-http-buffer--timer + (cancel-timer monitor-http-buffer--timer) + (setq monitor-http-buffer--timer nil)))))))) + + +(defun monitor-http-buffer () + (run-at-time 1 1 + (lambda () + (let ((buf (get-buffer "*X*"))) + (when (and (buffer-live-p buf) + (> (with-current-buffer buf + (- (point-max) (point-min))) + 0)) + (psysho-log "[MONITOR] Буфер *X* заполнен, открываю...") + (display-buffer buf) + (cancel-function-timers 'monitor-http-buffer)))))) +psysho-log - это то же что и message но с моими шрифтами +я хочу monitor-http-buffer чтобы прекращалась после показа буффер - соообщение только один раз +выходило чтоб + + +в елисп емакс проверить что буффер - существует и что там есть контент +(with-current-buffer "*X*" (- (point-max) (point-min))) +где буффер X - это вывод http запроса - runtime-at - надо использовать и вот так мониторить буду + + +есть ли в емакс возможности реагировать на события кроме таймера? + +;;(process-send-string "tcp-client" "GET / HTTP/1.1\r\nHost: gnu.org\r\n\r\n") + + +;;(start-process "x1" "*xxxxx*" "/root/glibc/dark_c/sfirot" "") +;;(get-process "x1") +;;(set-process-sentinel (get-process "x1") +;; (lambda (proc event) +;; (psysho-log "Process %s message: %s" proc event))) +;;(print (copy-sequence timer-list)) +;;;(mapc #'cancel-timer timer-list) + + +(defun my-buffer-change-fn (beg end len) + (message "Buffer changed from %d to %d (replaced %d chars)" beg end len)) + +(add-hook 'after-change-functions #'my-buffer-change-fn) + + +(defun my-watch-buffer (beg end len) + (when (string= (buffer-name) "*X*") + (message "*X* was modified"))) + +(add-hook 'after-change-functions #'my-watch-buffer) + +(defun my-monitor-buffer-change (beg end len) + (when (> (- (point-max) (point-min)) 0) + (psysho-log "[HOOK] Буфер *X* получил данные, открываю...") + (display-buffer (current-buffer)) + ;; Удаляем хук, чтобы сработал только один раз + (remove-hook 'after-change-functions #'my-monitor-buffer-change t))) + +(with-current-buffer "*X*" + (add-hook 'after-change-functions #'my-monitor-buffer-change nil t))