Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Konstantin Osipov <kostja@tarantool.org>,
	Alexander Turenko <alexander.turenko@tarantool.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>
Subject: [tarantool-patches] [PATCH 5/6] box/console: Provide console.eos() api
Date: Fri,  6 Sep 2019 00:28:14 +0300	[thread overview]
Message-ID: <20190905212815.7311-6-gorcunov@gmail.com> (raw)
In-Reply-To: <20190905212815.7311-1-gorcunov@gmail.com>

The other modules would be able to find out which eos marker
is currently active. For example when reading replies from
remote server via text based console protocol.

@TarantoolBot document
Title: > require('console').eos()

Returns a string with currently active end of string marker.

@TarantoolBot document
Title: > require('console').eos("")

Sets end of string marker for appliable output modes.
YAML output mode does not support eos change. For Lua
mode it is possible to set eos to empty string (like
in example above) or any other symbol.

Note that default semicolon symbol is mandatory for
remote text consoles thus if get zapped the read
procedure from remote socket will not be possible and
connection get stuck forever. Use this ability with
extreme caution.

Part-of #3834
---
 src/box/lua/console.lua | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
v3:
 - Don't use ... in arguments but rather name it eos_value

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index a6ff0e659..c1e8daaf8 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -164,6 +164,21 @@ local function current_eos()
     return output_eos[current_output()["fmt"]]
 end
 
+local function console_eos(eos_value)
+    if not eos_value then
+        return tostring(current_eos())
+    end
+    -- We can't allow to change yaml eos format because
+    -- it is a part of encoding standart, thus permit
+    -- only for modes where it is safe.
+    local d = current_output()
+    if d["fmt"] == "lua" then
+        output_eos["lua"] = eos_value
+    else
+        error("console.eos(): is immutable for output " .. d["fmt"])
+    end
+end
+
 --
 -- Map output format descriptor into a "\set" command.
 local function output_to_cmd_string(desc)
@@ -792,6 +807,7 @@ package.loaded['console'] = {
     delimiter = delimiter;
     set_default_output = set_default_output;
     get_default_output = get_default_output;
+    eos = console_eos;
     ac = ac;
     connect = connect;
     listen = listen;
-- 
2.20.1

  parent reply	other threads:[~2019-09-05 21:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05 21:28 [tarantool-patches] [PATCH v3 0/6] box/console: Improve lua mode for remote console Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 1/6] box/console: Add mapping for direct symbols Cyrill Gorcunov
2019-09-09 15:11   ` [tarantool-patches] " Sergey Ostanevich
2019-09-09 15:54     ` [tarantool-patches] " Cyrill Gorcunov
2019-09-10  3:59       ` [tarantool-patches] Re[2]: [tarantool-patches] " Sergey Ostanevich
2019-09-05 21:28 ` [tarantool-patches] [PATCH 2/6] box/console: Add explicit output EOS mapping Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 3/6] box/console: Refactor command handling Cyrill Gorcunov
2019-09-05 21:28 ` [tarantool-patches] [PATCH 4/6] box/console: Fix hang in remote console lua mode Cyrill Gorcunov
2019-09-05 21:28 ` Cyrill Gorcunov [this message]
2019-09-05 21:28 ` [tarantool-patches] [PATCH 6/6] box/console: Rename output_parse to parse_output Cyrill Gorcunov

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=20190905212815.7311-6-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 5/6] box/console: Provide console.eos() api' \
    /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