branch: externals/drepl
commit 91be4becdfeead7fb2e8e7160d142f52fe675374
Author: Augusto Stoffel <[email protected]>
Commit: Augusto Stoffel <[email protected]>
Support HTML output in usql
---
drepl-usql.el | 13 +++++++++++++
drepl-usql/drepl-usql.go | 14 ++++++++++++--
drepl.el | 2 +-
3 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/drepl-usql.el b/drepl-usql.el
index 70635e34cd..73a6e8da34 100644
--- a/drepl-usql.el
+++ b/drepl-usql.el
@@ -92,6 +92,19 @@ Note that this requires a Go compiler."
(setq-local indent-line-function #'ignore)
(when (fboundp 'sql-indent-enable) (sql-indent-enable)))
+(cl-defmethod drepl--eval ((repl drepl-usql) code)
+ "Send an eval request to REPL with CODE as argument."
+ (let ((cb (lambda (data)
+ (when (string= (alist-get 'format data) 'html)
+ (save-excursion
+ (let* ((start (previous-single-char-property-change (point)
'field))
+ (end (point))
+ (html (buffer-substring-no-properties start end)))
+ (when (eq (char-after start) ?<)
+ (comint-mime-render-html '((type . "text/html")) html)
+ (delete-region start end))))))))
+ (drepl--communicate repl cb 'eval :code code)))
+
(cl-defmethod drepl--init ((repl drepl-usql))
(cl-call-next-method repl)
(push '("5151" . comint-mime-osc-handler) ansi-osc-handlers)
diff --git a/drepl-usql/drepl-usql.go b/drepl-usql/drepl-usql.go
index c92eddc707..1f75ba5c92 100644
--- a/drepl-usql/drepl-usql.go
+++ b/drepl-usql/drepl-usql.go
@@ -25,6 +25,7 @@ type Dline struct {
scanner *bufio.Scanner
handler *handler.Handler
completer readline.AutoCompleter
+ nextMsg *map[string]any
}
// One-size-fits-all struct to decode an incoming message
@@ -146,6 +147,12 @@ func (l *Dline) Complete(code string, pos int) (string,
[]string) {
// Next returns the next line of runes (excluding '\n') from the input.
func (l *Dline) Next() ([]rune, error) {
+ if l.nextMsg != nil {
+ // Send now the response of the previous eval command, so the
+ // client knows it has finished.
+ l.SendMsg(*l.nextMsg)
+ l.nextMsg = nil
+ }
fmt.Print(l.MakePrompt())
for {
msg, err := l.ReadMsg()
@@ -158,7 +165,10 @@ func (l *Dline) Next() ([]rune, error) {
}
switch msg.Op {
case "eval":
- l.SendMsg(map[string]any{"id": msg.Id})
+ l.nextMsg = &map[string]any{
+ "id": msg.Id,
+ "format": env.Pall()["format"],
+ }
l.SendStatus("rawio")
return []rune(msg.Code), nil
case "checkinput":
@@ -231,7 +241,7 @@ func main() {
}
env.Pset("pager", "off")
scanner := bufio.NewScanner(os.Stdin)
- l := &Dline{scanner: scanner, completer: nil}
+ l := &Dline{scanner: scanner, completer: nil, nextMsg: nil}
l.handler = handler.New(l, usr, wd, false)
l.handler.SetSingleLineMode(true)
l.SendStatus("rawio") // The following line may ask for a password
diff --git a/drepl.el b/drepl.el
index bbfd142172..27dd0002aa 100644
--- a/drepl.el
+++ b/drepl.el
@@ -5,7 +5,7 @@
;; Author: Augusto Stoffel <[email protected]>
;; Keywords: languages, processes
;; URL: https://github.com/astoff/drepl
-;; Package-Requires: ((emacs "29.1") (comint-mime "0.3"))
+;; Package-Requires: ((emacs "29.1") (comint-mime "0.7"))
;; Version: 0.3
;; This program is free software; you can redistribute it and/or modify