Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Aleksandr Lyapunov <alyapunov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] Introduce fselect - formatted select
Date: Mon, 14 Sep 2020 22:02:27 +0300	[thread overview]
Message-ID: <20200914190227.w4f5nkgklqz6dx7k@tkn_work_nb> (raw)
In-Reply-To: <1594375434-743-2-git-send-email-alyapunov@tarantool.org>

I have not much to say here. It's nice. It is for humans and so unlikely
we should provide some guarantees except options meaning.

My first thoughts were how to generalize and allow to reuse it.
box.execute() also provides columns metainfo, but the format is a bit
different. I guess it'll be the first request to us: support such output
in SQL. Maybe just for box.execute(), via Lua. However we can be
consider it as a separate task.

I also had thoughts whether we should tweak formatting things on some
other level: say, provide an option for :select(), which sets a
metatable with particular __serialize function. So data will be
available as usual in a script, but will be formatted this way in the
interactive console. I'm not sure, because there is the donwside: it
surely not so short as 'fselect'.

I see that you continue to improve the patch on the branch: now 'sql',
'github' and 'jira' delimiters are supported. For me it looks like it
goes to be a separate module for formatting tables (like 'csv' we
already have). Not just 'formatted select' thing. However here I'm not
sure too.

That's all. It is nice and it is okay to push from my side.

Several nits are below.

WBR, Alexander Turenko.

> +-- index.fselect - formatted select.
> +base_index_mt.fselect = function(index, key, opts)
> +    -- options.
> +    local max_width = 140

We can obtain terminal width and use it as default:

 | tarantool> ffi = require('ffi')
 | tarantool> ffi.cdef('void rl_get_screen_size(int *rows, int *cols);')
 | tarantool> colsp = ffi.new('int[1]')
 | tarantool> ffi.C.rl_get_screen_size(nil, colsp)
 | tarantool> colsp[0]
 | ---
 | - 190
 | ...

It returns zero, when I run it from a file (not from the console), so a
default when there is no terminal size information is necessary anyway.

Not sure about portability of calling rl_get_screen_size(), though.

> +    local num_rows = #tab
> +    local space = box.space[index.space_id]
> +    local fmt = space:format() 

Nit: trailing whitespace.

> +    -- format string - cut or fill with spaces to make is exactly n symbols.
> +    -- also replace spaces with non-break spaces.
> +    local fmt_str = function(x, n)
> +        if not x then x = '' end
> +        local str
> +        if x:len() <= n then
> +            local add = n - x:len()
> +            local addl = math.floor(add/2)
> +            local addr = math.ceil(add/2)
> +            str = string.rep(' ', addl) .. x .. string.rep(' ', addr)

There is quite similar string.center() function (src/lua/string.lua).

  reply	other threads:[~2020-09-14 19:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-10 10:03 [Tarantool-patches] [PATCH] Formatted select in lua console Aleksandr Lyapunov
2020-07-10 10:03 ` [Tarantool-patches] [PATCH] Introduce fselect - formatted select Aleksandr Lyapunov
2020-09-14 19:02   ` Alexander Turenko [this message]
2020-07-10 10:08 ` [Tarantool-patches] [PATCH] Formatted select in lua console Aleksandr Lyapunov
2020-07-10 15:37 ` Oleg Babin
2020-07-13  8:52   ` Aleksandr Lyapunov

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=20200914190227.w4f5nkgklqz6dx7k@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=alyapunov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] Introduce fselect - formatted select' \
    /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