Tarantool development patches archive
 help / color / mirror / Atom feed
From: Olga Arkhangelskaia <arkholga@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Cc: alexander.turenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 2/2] console: add line carrying backslash
Date: Wed, 10 Jun 2020 12:43:54 +0300	[thread overview]
Message-ID: <20200610094354.31831-3-arkholga@tarantool.org> (raw)
In-Reply-To: <20200610094354.31831-1-arkholga@tarantool.org>

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

Closes #4317
---
 src/box/lua/console.lua       | 18 ++++++++-----
 test/app-tap/gh-4317.test.lua | 51 +++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 6 deletions(-)
 create mode 100755 test/app-tap/gh-4317.test.lua

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)
diff --git a/test/app-tap/gh-4317.test.lua b/test/app-tap/gh-4317.test.lua
new file mode 100755
index 000000000..d7a5063e7
--- /dev/null
+++ b/test/app-tap/gh-4317.test.lua
@@ -0,0 +1,51 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local console = require('console')
+local fio = require('fio')
+
+-- The following cases use LD_PRELOAD, so will not work under
+-- Mac OS X.
+if jit.os == 'OSX' then
+    os.exit(0)
+end
+
+test = tap.test("console")
+test:plan(1)
+
+-- Allow to run the test from the repository root without
+-- test-run:
+--
+-- $ ./src/tarantool test/app-tap/gh-4317.test.lua
+--
+-- It works at least for in-source build.
+local is_under_test_run = pcall(require, 'test_run')
+local isatty_lib_dir = is_under_test_run and '../..' or 'test'
+local isatty_lib_path = fio.pathjoin(isatty_lib_dir, 'libisatty.so')
+local saved_path = os.getenv('PATH')
+if not is_under_test_run then
+    os.setenv('PATH', './src:', saved_path)
+end
+
+local tarantool_command = "local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)"
+local result_str =  [[tarantool> local a = 0 \
+         > for i = 1, 10 do
+         > a = a + i
+         > end \
+         > print(a)
+55
+---
+...
+
+tarantool> ]]
+local cmd = ([[printf '%s\n' | LD_PRELOAD='%s' tarantool ]] ..
+[[2>/dev/null]]):format(tarantool_command, isatty_lib_path)
+local fh = io.popen(cmd, 'r')
+-- Readline on CentOS 7 produces \e[?1034h escape
+-- sequence before tarantool> prompt, remove it.
+local result = fh:read('*a'):gsub('\x1b%[%?1034h', '')
+fh:close()
+test:is(result, result_str, "Backslash")
+
+test:check()
+os.exit(0)
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2020-06-10  9:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10  9:43 [Tarantool-patches] [PATCH v2 0/2] console: support of backslash Olga Arkhangelskaia
2020-06-10  9:43 ` [Tarantool-patches] [PATCH 1/2] test: add libisatty to test local console Olga Arkhangelskaia
2020-06-11 16:47   ` Igor Munkin
2020-06-10  9:43 ` Olga Arkhangelskaia [this message]
2020-06-11 16:48   ` [Tarantool-patches] [PATCH 2/2] console: add line carrying backslash Igor Munkin
2020-06-16 14:39   ` Alexander Turenko
2020-06-11 16:49 ` [Tarantool-patches] [PATCH v2 0/2] console: support of backslash Igor Munkin
2020-07-08 18:42 ` Alexander Turenko
2020-07-09  6:01   ` Olga Arkhangelskaia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200610094354.31831-3-arkholga@tarantool.org \
    --to=arkholga@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/2] console: add line carrying backslash' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox