branch: externals/drepl
commit 5b19ef40e122ac62a05828bdb2e44f1db086d2c1
Author: Augusto Stoffel <arstof...@gmail.com>
Commit: Augusto Stoffel <arstof...@gmail.com>

    Ask for database connection URL when starting usql
---
 drepl-usql.el            |  8 +++++++-
 drepl-usql/drepl-usql.go | 11 ++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drepl-usql.el b/drepl-usql.el
index 29c66d2e85..3e4c377fde 100644
--- a/drepl-usql.el
+++ b/drepl-usql.el
@@ -41,6 +41,9 @@
                                    (or load-file-name default-directory)))
   "Directory containing the `drepl-usql' source code.")
 
+(defvar drepl-usql--connection-history nil
+  "History list of database connections.")
+
 (defcustom drepl-usql-program
   (expand-file-name "drepl-usql" drepl-usql--directory)
   "Name of the drepl-usql executable."
@@ -59,7 +62,9 @@
 
 (cl-defmethod drepl--command ((_ drepl-usql))
   (if-let ((prog (executable-find drepl-usql-program)))
-      (list prog)
+      (list prog (read-from-minibuffer "Connect to database: "
+                                       nil nil nil
+                                       'drepl-usql--connection-history))
     (lwarn 'drepl-usql :error
            "`%s' not found, built it with %s"
            drepl-usql-program
@@ -68,6 +73,7 @@
 
 (cl-defmethod drepl--init ((repl drepl-usql))
   (cl-call-next-method repl)
+  (setf (drepl--status repl) 'rawio)
   (push '("5151" . comint-mime-osc-handler) ansi-osc-handlers)
   (drepl--adapt-comint-to-mode ".sql"))
 
diff --git a/drepl-usql/drepl-usql.go b/drepl-usql/drepl-usql.go
index e0671495a8..5d073dbbf0 100644
--- a/drepl-usql/drepl-usql.go
+++ b/drepl-usql/drepl-usql.go
@@ -3,6 +3,7 @@ package main
 import (
        "bufio"
        "bytes"
+       "context"
        "encoding/base64"
        "encoding/json"
        "fmt"
@@ -228,7 +229,6 @@ func (l *Dline) Password(prompt string) (string, error) {
 func (l *Dline) SetOutput(f func(string) string) {}
 
 func main() {
-       scanner := bufio.NewScanner(os.Stdin)
        usr, err := user.Current()
        if err != nil {
                log.Fatal(err)
@@ -238,12 +238,13 @@ func main() {
                log.Fatal(err)
        }
        env.Pset("pager", "off")
+       scanner := bufio.NewScanner(os.Stdin)
        l := &Dline{scanner: scanner, completer: nil}
-       h := handler.New(l, usr, wd, false)
-       l.handler = h
-       h.SetSingleLineMode(true)
+       l.handler = handler.New(l, usr, wd, false)
+       l.handler.SetSingleLineMode(true)
+       l.handler.Open(context.Background(), os.Args[1:]...)
        l.SendLogo()
-       err = h.Run()
+       err = l.handler.Run()
        if err != nil {
                log.Fatal(err)
        }

Reply via email to