[Tarantool-patches] [PATCH] console: add line carrying backslash

Olga Arkhangelskaia arkholga at tarantool.org
Tue Apr 14 15:35:04 MSK 2020


When using interactive console(stdin) instead of \set delimiter <delimiter>
with "\", "\" in the end if line can be used.

The patch enables "\" only for REPL over stdin. I have troubles to write
tests for stdin input, because in case we attach to the console (remote
or to self) another read (console_read) is used. And in this case I do
not think that we need support backslash, because we stop reading
till "\n" or "\r".
Another problem that I have faced is testing (I have tried remote instance,
console over socket and i little bit of popen. However, all this test take
advantage of console_read and do not touch local_read.
If you have any ideas how to test interactive
console within test-run, please share.

Closes #4317
---
Branch:
OKriw/gh-4317-console-support-line-carrying-with-backslash
 src/box/lua/console.lua | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 17e2c91b2..4c2c7a132 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -573,14 +573,20 @@ local function local_read(self)
             break
         end
         if delim == "" then
-            local lang = box.session.language
-            if not lang or lang == 'lua' then
-                -- stop once a complete Lua statement is entered
-                if local_check_lua(buf) then
+            -- if no delim is set and line ends with the backslash
+            -- continue reading
+            if buf:sub(-1, -1) == '\\' then
+                buf = buf:sub(0, #buf - 1)
+            else
+                local lang = box.session.language
+                if not lang or lang == 'lua' then
+                    -- stop once a complete Lua statement is entered
+                    if local_check_lua(buf) then
+                        break
+                    end
+                else
                     break
                 end
-            else
-                break
             end
         elseif #buf >= #delim and buf:sub(#buf - #delim + 1) == delim then
             buf = buf:sub(0, #buf - #delim)
-- 
2.20.1 (Apple Git-117)



More information about the Tarantool-patches mailing list