Просмотр исходного кода

sql: Re-prompt user for input after unrecognized command

This fixes a bug in the SQL REPL where after a user enters an
unrecognized command, the REPL would not print another "> " prompt and
would not accept any more input.
Nicholas Cellino 3 лет назад
Родитель
Сommit
626ea5007a
1 измененных файлов с 13 добавлено и 7 удалено
  1. 13 7
      Userland/Utilities/sql.cpp

+ 13 - 7
Userland/Utilities/sql.cpp

@@ -272,7 +272,11 @@ private:
         }
 
         if (piece.starts_with('.')) {
-            handle_command(piece);
+            bool ready_for_input = handle_command(piece);
+            if (ready_for_input)
+                m_loop.deferred_invoke([this]() {
+                    read_sql();
+                });
         } else {
             auto statement_id = m_sql_client->sql_statement(m_connection_id, piece);
             m_sql_client->async_statement_execute(statement_id);
@@ -297,16 +301,20 @@ private:
         return prompt_builder.build();
     }
 
-    void handle_command(StringView command)
+    bool handle_command(StringView command)
     {
+        bool ready_for_input = true;
         if (command == ".exit" || command == ".quit") {
             m_keep_running = false;
+            ready_for_input = false;
         } else if (command.starts_with(".connect ")) {
             auto parts = command.split_view(' ');
-            if (parts.size() == 2)
+            if (parts.size() == 2) {
                 connect(parts[1]);
-            else
+                ready_for_input = false;
+            } else {
                 outln("\033[33;1mUsage: .connect <database name>\033[0m");
+            }
         } else if (command.starts_with(".read ")) {
             if (!m_input_file) {
                 auto parts = command.split_view(' ');
@@ -318,12 +326,10 @@ private:
             } else {
                 outln("\033[33;1mCannot recursively read sql files\033[0m");
             }
-            m_loop.deferred_invoke([this]() {
-                read_sql();
-            });
         } else {
             outln("\033[33;1mUnrecognized command:\033[0m {}", command);
         }
+        return ready_for_input;
     }
 };