[PATCH 6/7] box/console: Provide console.eos() api

Cyrill Gorcunov gorcunov at gmail.com
Fri Sep 20 21:45:22 MSK 2019


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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 71c64bc01..99a0646b4 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -170,6 +170,24 @@ local function current_eos()
     return output_eos[current_output()["fmt"]]
 end
 
+--
+-- Set/get current console EOS value from
+-- currently active output format.
+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)
@@ -798,6 +816,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




More information about the Tarantool-patches mailing list