From 34681544664838a45d37e48eda10c6da87236012 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@gmail.com>
Date: Fri, 4 Oct 2019 10:49:25 +0300
Subject: [PATCH] box/console: Provide console.eos() api

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.

Part-of #3834

Reviewed-by: Konstantin Osipov <kostja.osipov@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
(cherry picked from commit 9d83b5f64626719752a1e74a67f42c61d381bce5)
---
 src/box/lua/console.lua | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index efd1cddd89..7cf8cfb686 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -177,6 +177,23 @@ 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.
+    local d = current_output()
+    if d["fmt"] == "yaml" then
+        error("console.eos(): is immutable for output " .. d["fmt"])
+    else
+        output_eos[d["fmt"]] = eos_value
+    end
+end
+
 --
 -- Map output format descriptor into a "\set" command.
 local function output_to_cmd_string(desc)
@@ -805,6 +822,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;
-- 
GitLab