aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaksim Kita <kitaetoya@gmail.com>2023-06-08 13:38:21 +0000
committermaksim-kita <maksim-kita@yandex-team.com>2023-06-08 16:38:21 +0300
commit723a9414949d935da94e2df3ce0b64d5c5497c8e (patch)
treebad0d0d69f65316b9bd900a1987256c548a94942
parentd2704d925a4e0569a9ed1e8ce9b4287bbd9503b4 (diff)
downloadydb-723a9414949d935da94e2df3ce0b64d5c5497c8e.tar.gz
CLI added progress bar for import command
CLI added progress bar for import command Pull Request resolved: #243
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_profile.cpp14
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp15
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_service_scripting.cpp3
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp1
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_yql.cpp11
-rw-r--r--ydb/public/lib/ydb_cli/common/command.cpp6
-rw-r--r--ydb/public/lib/ydb_cli/common/common.cpp15
-rw-r--r--ydb/public/lib/ydb_cli/common/common.h1
-rw-r--r--ydb/public/lib/ydb_cli/common/interactive.cpp45
-rw-r--r--ydb/public/lib/ydb_cli/common/interactive.h6
-rw-r--r--ydb/public/lib/ydb_cli/common/parameters.cpp38
-rw-r--r--ydb/public/lib/ydb_cli/common/parameters.h2
-rw-r--r--ydb/public/lib/ydb_cli/common/pretty_table.cpp6
-rw-r--r--ydb/public/lib/ydb_cli/common/progress_bar.cpp21
-rw-r--r--ydb/public/lib/ydb_cli/common/progress_bar.h4
-rw-r--r--ydb/public/lib/ydb_cli/common/tabbed_table.cpp5
-rw-r--r--ydb/public/lib/ydb_cli/import/import.cpp16
17 files changed, 116 insertions, 93 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
index f41b522496..46f6eee8c0 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
@@ -21,18 +21,6 @@
namespace NYdb::NConsoleClient {
-namespace {
-
- bool IsStdinInteractive() {
-#if defined(_win32_)
- return _isatty(_fileno(stdin));
-#elif defined(_unix_)
- return isatty(fileno(stdin));
-#endif
- return true;
- }
-}
-
const TString AuthNode = "authentication";
TCommandConfig::TCommandConfig()
@@ -220,7 +208,7 @@ namespace {
TString authMethod = authValue["method"].as<TString>();
Cout << " " << authMethod;
if (authMethod == "ydb-token" ||authMethod == "iam-token"
- || authMethod == "yc-token" || authMethod == "sa-key-file"
+ || authMethod == "yc-token" || authMethod == "sa-key-file"
|| authMethod == "token-file" || authMethod == "yc-token-file")
{
TString authData = authValue["data"].as<TString>();
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp
index c2d9f5a321..ea34ed2a42 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp
@@ -2,6 +2,7 @@
#include <ydb/public/lib/ydb_cli/common/normalize_path.h>
#include <ydb/public/lib/ydb_cli/common/print_operation.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <ydb/public/lib/ydb_cli/import/import.h>
#include <ydb/library/backup/util.h>
@@ -17,20 +18,6 @@
namespace NYdb {
namespace NConsoleClient {
-namespace {
- bool IsStdinInteractive() {
-#if defined(_win32_)
- errno = 0;
- bool value = _isatty(_fileno(stdin));
- return value || (errno == EBADF);
-#elif defined(_unix_)
- errno = 0;
- bool value = isatty(fileno(stdin));
- return value || (errno == EBADF);
-#endif
- return true;
-}
-}
TCommandImport::TCommandImport()
: TClientCommandTree("import", {}, "Import service operations")
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_scripting.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_scripting.cpp
index 617a622c74..c3c2055701 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_service_scripting.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_service_scripting.cpp
@@ -2,6 +2,7 @@
#include <ydb/public/lib/ydb_cli/common/pretty_table.h>
#include <ydb/public/lib/ydb_cli/common/query_stats.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <util/folder/path.h>
#include <util/folder/dirut.h>
@@ -115,7 +116,7 @@ int TCommandExecuteYqlScript::Run(TConfig& config) {
paramBuilder->Build(),
FillSettings(settings)
);
-
+
auto result = asyncResult.GetValueSync();
ThrowOnError(result);
PrintResponseHeader(result);
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp
index b89bcdd15f..1fe9b25bb6 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_service_table.cpp
@@ -4,6 +4,7 @@
#include <ydb/public/lib/ydb_cli/common/pretty_table.h>
#include <ydb/public/lib/ydb_cli/common/print_operation.h>
#include <ydb/public/lib/ydb_cli/common/query_stats.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <ydb/public/sdk/cpp/client/ydb_proto/accessor.h>
#include <library/cpp/json/json_prettifier.h>
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_yql.cpp b/ydb/public/lib/ydb_cli/commands/ydb_yql.cpp
index c09188a485..45f70f8e51 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_yql.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_yql.cpp
@@ -4,6 +4,7 @@
#include <ydb/public/lib/ydb_cli/common/pretty_table.h>
#include <ydb/public/lib/ydb_cli/common/print_operation.h>
#include <ydb/public/lib/ydb_cli/common/query_stats.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <ydb/public/lib/ydb_cli/commands/interactive/interactive_cli.h>
#include <util/generic/queue.h>
@@ -108,7 +109,7 @@ int TCommandYql::Run(TConfig& config) {
TConfig& Config;
};
-
+
TTerminalOutput::Print("\033[32mYDB Interactive CLI \033[0m");
TTerminalOutput::Print("\033[31m(experimental, no compatibility guarantees)\033[0m\n\n");
TInteractiveCli::TConfig interactiveCfg;
@@ -123,7 +124,7 @@ int TCommandYql::Run(TConfig& config) {
return EXIT_SUCCESS;
} else {
- return RunCommand(config, Script);
+ return RunCommand(config, Script);
}
}
@@ -142,15 +143,15 @@ int TCommandYql::RunCommand(TConfig& config, const TString &script) {
ValidateResult = MakeHolder<NScripting::TExplainYqlResult>(
ExplainQuery(config, Script, NScripting::ExplainYqlRequestMode::Validate));
THolder<TParamsBuilder> paramBuilder;
- while (!IsInterrupted() &&
+ while (!IsInterrupted() &&
GetNextParams(ValidateResult->GetParameterTypes(), InputFormat, StdinFormat, FramingFormat, paramBuilder)) {
-
+
auto asyncResult = client.StreamExecuteYqlScript(
script,
paramBuilder->Build(),
FillSettings(settings)
);
-
+
auto result = asyncResult.GetValueSync();
ThrowOnError(result);
if (!PrintResponse(result)) {
diff --git a/ydb/public/lib/ydb_cli/common/command.cpp b/ydb/public/lib/ydb_cli/common/command.cpp
index 5eda961592..7b7a8af720 100644
--- a/ydb/public/lib/ydb_cli/common/command.cpp
+++ b/ydb/public/lib/ydb_cli/common/command.cpp
@@ -1,6 +1,8 @@
#include "command.h"
#include "normalize_path.h"
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
+
namespace NYdb {
namespace NConsoleClient {
@@ -95,7 +97,9 @@ TClientCommand::TClientCommand(const TString& name, const std::initializer_list<
HideOption("svnrevision");
Opts.AddHelpOption('h');
ChangeOptionDescription("help", "Print usage");
- Opts.SetWrap(Max(Opts.Wrap_, static_cast<ui32>(TermWidth())));
+ auto terminalWidth = GetTerminalWidth();
+ size_t lineLength = terminalWidth ? *terminalWidth : Max<size_t>();
+ Opts.SetWrap(Max(Opts.Wrap_, static_cast<ui32>(lineLength)));
}
ELogPriority TClientCommand::TConfig::VerbosityLevelToELogPriority(TClientCommand::TConfig::EVerbosityLevel lvl) {
diff --git a/ydb/public/lib/ydb_cli/common/common.cpp b/ydb/public/lib/ydb_cli/common/common.cpp
index ac1a9f6326..1e6153dcb6 100644
--- a/ydb/public/lib/ydb_cli/common/common.cpp
+++ b/ydb/public/lib/ydb_cli/common/common.cpp
@@ -90,21 +90,6 @@ TString ReadFromFile(TString& filePath, const TString& fileName, bool allowEmpty
}
}
-size_t TermWidth() {
-#if defined(_win32_)
- CONSOLE_SCREEN_BUFFER_INFO screen_buf_info;
- if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &screen_buf_info)) {
- return screen_buf_info.srWindow.Right - screen_buf_info.srWindow.Left + 1;
- }
-#elif defined(_unix_)
- struct winsize size;
- if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) != -1) {
- return size.ws_col;
- }
-#endif
- return Max<size_t>();
-}
-
TString InputPassword() {
// Disable echoing characters and enable per-symbol input handling
#if defined(_unix_)
diff --git a/ydb/public/lib/ydb_cli/common/common.h b/ydb/public/lib/ydb_cli/common/common.h
index f4a09a2f00..0afe4e4a84 100644
--- a/ydb/public/lib/ydb_cli/common/common.h
+++ b/ydb/public/lib/ydb_cli/common/common.h
@@ -39,7 +39,6 @@ private:
bool ReadFromFileIfExists(TString& filePath, const TString& fileName, TString& output, bool allowEmpty = false);
TString ReadFromFile(TString& filePath, const TString& fileName, bool allowEmpty = false);
-size_t TermWidth();
TString InputPassword();
}
diff --git a/ydb/public/lib/ydb_cli/common/interactive.cpp b/ydb/public/lib/ydb_cli/common/interactive.cpp
index dd2e0a94f2..7226328ca4 100644
--- a/ydb/public/lib/ydb_cli/common/interactive.cpp
+++ b/ydb/public/lib/ydb_cli/common/interactive.cpp
@@ -1,5 +1,14 @@
#include "interactive.h"
+#if defined(_unix_)
+#include <sys/ioctl.h>
+#include <termios.h>
+
+#elif defined(_win_)
+#include <windows.h>
+#include <io.h>
+#endif
+
namespace NYdb {
namespace NConsoleClient {
@@ -19,5 +28,41 @@ bool AskYesOrNo() {
return false;
}
+bool IsStdinInteractive() {
+#if defined(_win32_)
+ return _isatty(_fileno(stdin));
+#elif defined(_unix_)
+ return isatty(fileno(stdin));
+#endif
+ return true;
+}
+
+bool IsStdoutInteractive() {
+#if defined(_win32_)
+ return _isatty(_fileno(stdout));
+#elif defined(_unix_)
+ return isatty(fileno(stdout));
+#endif
+ return true;
+}
+
+std::optional<size_t> GetTerminalWidth() {
+ if (!IsStdoutInteractive())
+ return {};
+
+#if defined(_win32_)
+ CONSOLE_SCREEN_BUFFER_INFO screen_buf_info;
+ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &screen_buf_info)) {
+ return screen_buf_info.srWindow.Right - screen_buf_info.srWindow.Left + 1;
+ }
+#elif defined(_unix_)
+ struct winsize size;
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) != -1) {
+ return size.ws_col;
+ }
+#endif
+ return {};
+}
+
}
}
diff --git a/ydb/public/lib/ydb_cli/common/interactive.h b/ydb/public/lib/ydb_cli/common/interactive.h
index 1910f6c73b..c0bfc68dcb 100644
--- a/ydb/public/lib/ydb_cli/common/interactive.h
+++ b/ydb/public/lib/ydb_cli/common/interactive.h
@@ -7,5 +7,11 @@ namespace NConsoleClient {
bool AskYesOrNo();
+bool IsStdinInteractive();
+
+bool IsStdoutInteractive();
+
+std::optional<size_t> GetTerminalWidth();
+
}
}
diff --git a/ydb/public/lib/ydb_cli/common/parameters.cpp b/ydb/public/lib/ydb_cli/common/parameters.cpp
index e602e8885c..6b4c3567cd 100644
--- a/ydb/public/lib/ydb_cli/common/parameters.cpp
+++ b/ydb/public/lib/ydb_cli/common/parameters.cpp
@@ -1,25 +1,13 @@
#include "parameters.h"
#include <ydb/public/lib/json_value/ydb_json_value.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <library/cpp/json/json_reader.h>
#include <library/cpp/threading/future/async.h>
namespace NYdb {
namespace NConsoleClient {
- bool IsStdinInteractive() {
-#if defined(_win32_)
- errno = 0;
- bool value = _isatty(_fileno(stdin));
- return value || (errno == EBADF);
-#elif defined(_unix_)
- errno = 0;
- bool value = isatty(fileno(stdin));
- return value || (errno == EBADF);
-#endif
- return true;
- }
-
void TCommandWithParameters::ParseParameters(TClientCommand::TConfig& config) {
for (const auto& parameterOption : ParameterOptions) {
auto equalPos = parameterOption.find("=");
@@ -42,7 +30,7 @@ void TCommandWithParameters::ParseParameters(TClientCommand::TConfig& config) {
Parameters[paramName] = parameterOption.substr(equalPos + 1);
ParameterSources[paramName] = "\'--param\' option";
}
-
+
for (auto& file : ParameterFiles) {
TString data;
data = ReadFromFile(file, "param-file");
@@ -57,7 +45,7 @@ void TCommandWithParameters::ParseParameters(TClientCommand::TConfig& config) {
ParameterSources[name] = "param file " + file;
}
}
-
+
if (!StdinParameters.empty() && IsStdinInteractive()) {
throw TMisuseException() << "\"--stdin-par\" option is allowed only with non-interactive stdin.";
}
@@ -66,7 +54,7 @@ void TCommandWithParameters::ParseParameters(TClientCommand::TConfig& config) {
throw TMisuseException() << "Parameter $" << *it << " value found in more than one source: \'--stdin-par\' option.";
}
if (Parameters.find("$" + *it) != Parameters.end()) {
- throw TMisuseException() << "Parameter $" << *it << " value found in more than one source: \'--stdin-par\' option, "
+ throw TMisuseException() << "Parameter $" << *it << " value found in more than one source: \'--stdin-par\' option, "
<< ParameterSources["$" + *it] << ".";
}
}
@@ -117,11 +105,11 @@ void TCommandWithParameters::AddParametersOption(TClientCommand::TConfig& config
void TCommandWithParameters::AddParametersStdinOption(TClientCommand::TConfig& config, const TString& requestString) {
TStringStream descr;
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
- descr << "Batching mode for stdin parameters processing. Available options:\n "
- << colors.BoldColor() << "iterative" << colors.OldColor()
+ descr << "Batching mode for stdin parameters processing. Available options:\n "
+ << colors.BoldColor() << "iterative" << colors.OldColor()
<< "\n Executes " << requestString << " for each parameter set (exactly one execution "
"when no framing specified in \"stdin-format\")\n "
- << colors.BoldColor() << "full" << colors.OldColor()
+ << colors.BoldColor() << "full" << colors.OldColor()
<< "\n Executes " << requestString << " once, with all parameter sets wrapped in json list, when EOF is reached on stdin\n "
<< colors.BoldColor() << "adaptive" << colors.OldColor()
<< "\n Executes " << requestString << " with a json list of parameter sets every time when its number reaches batch-limit, "
@@ -167,7 +155,7 @@ void TCommandWithParameters::AddParams(const std::map<TString, TType>& paramType
bool TCommandWithParameters::GetNextParams(const std::map<TString, TType>& paramTypes, EOutputFormat inputFormat, EOutputFormat encodingFormat,
EOutputFormat framingFormat, THolder<TParamsBuilder>& paramBuilder) {
paramBuilder = MakeHolder<TParamsBuilder>();
- AddParams(paramTypes, inputFormat, *paramBuilder);
+ AddParams(paramTypes, inputFormat, *paramBuilder);
if (IsStdinInteractive()) {
static bool firstEncounter = true;
if (!firstEncounter) {
@@ -278,7 +266,7 @@ bool TCommandWithParameters::GetNextParams(const std::map<TString, TType>& param
if (!futureData.Initialized() || listSize) {
futureData = NThreading::Async(ReadDataLambda, *pool);
}
- if (BatchMode == EBatchMode::Adaptive && listSize &&
+ if (BatchMode == EBatchMode::Adaptive && listSize &&
((BatchMaxDelay != TDuration::Zero() && !futureData.Wait(endTime)) || listSize == BatchLimit)) {
break;
}
@@ -290,7 +278,7 @@ bool TCommandWithParameters::GetNextParams(const std::map<TString, TType>& param
if (!listSize) {
endTime = Now() + BatchMaxDelay;
}
-
+
if (parser.GetKind() != TTypeParser::ETypeKind::Primitive) {
throw TMisuseException() << "Wrong type of list \"" << fullname << "\" elements.";
}
@@ -315,7 +303,7 @@ bool TCommandWithParameters::GetNextParams(const std::map<TString, TType>& param
if (!futureData.Initialized() || listSize) {
futureData = NThreading::Async(ReadDataLambda, *pool);
}
- if (BatchMode == EBatchMode::Adaptive && listSize &&
+ if (BatchMode == EBatchMode::Adaptive && listSize &&
((BatchMaxDelay != TDuration::Zero() && !futureData.Wait(endTime)) || listSize == BatchLimit)) {
break;
}
@@ -376,7 +364,7 @@ void TCommandWithParameters::ApplyParams(const TMap<TString, TString> &params, c
}
const TType &type = (*paramIt).second;
paramBuilder.AddParam(name, JsonToYdbValue(value, type, encoding));
- }
+ }
}
TMaybe<TString> TCommandWithParameters::ReadData(EOutputFormat framingFormat) {
@@ -396,7 +384,7 @@ TMaybe<TString> TCommandWithParameters::ReadData(EOutputFormat framingFormat) {
throw TMisuseException() << "Unknown framing format: " << framingFormat;
}
return result;
-
+
}
}
diff --git a/ydb/public/lib/ydb_cli/common/parameters.h b/ydb/public/lib/ydb_cli/common/parameters.h
index bd5ba31e77..7d3da3c356 100644
--- a/ydb/public/lib/ydb_cli/common/parameters.h
+++ b/ydb/public/lib/ydb_cli/common/parameters.h
@@ -23,8 +23,6 @@ enum class EBatchMode {
Adaptive /* "adaptive" */
};
-bool IsStdinInteractive();
-
class TCommandWithParameters : public TCommandWithExamples {
protected:
void ParseParameters(TClientCommand::TConfig& config);
diff --git a/ydb/public/lib/ydb_cli/common/pretty_table.cpp b/ydb/public/lib/ydb_cli/common/pretty_table.cpp
index dd9489dfab..86eadab59c 100644
--- a/ydb/public/lib/ydb_cli/common/pretty_table.cpp
+++ b/ydb/public/lib/ydb_cli/common/pretty_table.cpp
@@ -5,6 +5,8 @@
#include <util/generic/xrange.h>
#include <util/stream/format.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
+
namespace NYdb {
namespace NConsoleClient {
@@ -143,7 +145,9 @@ TVector<size_t> TPrettyTable::CalcWidths() const {
}
// adjust
- const size_t maxWidth = Max(Config.Width, TermWidth()) - ((Columns * 3) + 1);
+ auto terminalWidth = GetTerminalWidth();
+ size_t lineLength = terminalWidth ? *terminalWidth : Max<size_t>();
+ const size_t maxWidth = Max(Config.Width, lineLength) - ((Columns * 3) + 1);
size_t totalWidth = Accumulate(widths, (size_t)0);
while (totalWidth > maxWidth) {
auto it = MaxElement(widths.begin(), widths.end());
diff --git a/ydb/public/lib/ydb_cli/common/progress_bar.cpp b/ydb/public/lib/ydb_cli/common/progress_bar.cpp
index f046496b90..e2e22358a7 100644
--- a/ydb/public/lib/ydb_cli/common/progress_bar.cpp
+++ b/ydb/public/lib/ydb_cli/common/progress_bar.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include "progress_bar.h"
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
#include <util/string/cast.h>
namespace NYdb {
@@ -9,13 +10,27 @@ namespace NConsoleClient {
TProgressBar::TProgressBar(size_t capacity) : Capacity(capacity) {
}
+void TProgressBar::SetProcess(size_t progress)
+{
+ CurProgress = Min(progress, Capacity);
+ Render();
+}
+
void TProgressBar::AddProgress(size_t value) {
CurProgress = Min(CurProgress + value, Capacity);
- size_t barLen = TermWidth();
- if (Capacity == 0 || barLen == Max<size_t>()) {
+ if (Capacity == 0) {
return;
}
+ Render();
+}
+void TProgressBar::Render()
+{
+ std::optional<size_t> barLenOpt = GetTerminalWidth();
+ if (!barLenOpt)
+ return;
+
+ size_t barLen = *barLenOpt;
TString output = ToString(CurProgress * 100 / Capacity);
output += "% |";
TString outputEnd = "| [";
@@ -23,7 +38,7 @@ void TProgressBar::AddProgress(size_t value) {
outputEnd += "/";
outputEnd += ToString(Capacity);
outputEnd += "]";
-
+
if (barLen > output.Size()) {
barLen -= output.Size();
} else {
diff --git a/ydb/public/lib/ydb_cli/common/progress_bar.h b/ydb/public/lib/ydb_cli/common/progress_bar.h
index 27b9f750fa..fb55cb1d56 100644
--- a/ydb/public/lib/ydb_cli/common/progress_bar.h
+++ b/ydb/public/lib/ydb_cli/common/progress_bar.h
@@ -9,9 +9,13 @@ class TProgressBar {
public:
explicit TProgressBar(size_t capacity);
+ void SetProcess(size_t progress);
+
void AddProgress(size_t value);
private:
+ void Render();
+
size_t Capacity = 0;
size_t CurProgress = 0;
};
diff --git a/ydb/public/lib/ydb_cli/common/tabbed_table.cpp b/ydb/public/lib/ydb_cli/common/tabbed_table.cpp
index f5371d22a2..eb53b145e1 100644
--- a/ydb/public/lib/ydb_cli/common/tabbed_table.cpp
+++ b/ydb/public/lib/ydb_cli/common/tabbed_table.cpp
@@ -1,5 +1,7 @@
#include "tabbed_table.h"
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
+
#include "common.h"
#include "print_utils.h"
@@ -47,7 +49,8 @@ void TAdaptiveTabbedTable::InitializeColumnInfo(size_t maxCols, size_t minColumn
}
void TAdaptiveTabbedTable::CalculateColumns() {
- size_t lineLength = TermWidth();
+ auto terminalWidth = GetTerminalWidth();
+ size_t lineLength = terminalWidth ? *terminalWidth : Max<size_t>();
size_t max_length = 0;
for (auto entry : Entries) {
if (entry.Name.length() > max_length) {
diff --git a/ydb/public/lib/ydb_cli/import/import.cpp b/ydb/public/lib/ydb_cli/import/import.cpp
index 0171046007..167eeea28c 100644
--- a/ydb/public/lib/ydb_cli/import/import.cpp
+++ b/ydb/public/lib/ydb_cli/import/import.cpp
@@ -10,6 +10,8 @@
#include <ydb/public/api/protos/ydb_table.pb.h>
#include <ydb/public/lib/json_value/ydb_json_value.h>
#include <ydb/public/lib/ydb_cli/common/recursive_list.h>
+#include <ydb/public/lib/ydb_cli/common/interactive.h>
+#include <ydb/public/lib/ydb_cli/common/progress_bar.h>
#include <ydb/public/lib/ydb_cli/dump/util/util.h>
#include <ydb/public/lib/ydb_cli/import/cli_arrow_helpers.h>
@@ -84,15 +86,6 @@ FHANDLE GetStdinFileno() {
#endif
}
-bool IsStdoutInteractive() {
-#if defined(_win32_)
- return _isatty(_fileno(stdout));
-#elif defined(_unix_)
- return isatty(fileno(stdout));
-#endif
- return true;
-}
-
class TMaxInflightGetter {
public:
TMaxInflightGetter(ui64 totalMaxInFlight, std::atomic<ui64>& filesCount)
@@ -277,11 +270,12 @@ TStatus TImportFileClient::Import(const TVector<TString>& filePaths, const TStri
std::mutex progressWriteLock;
std::atomic<ui64> globalProgress{0};
+ TProgressBar progressBar(100);
+
auto writeProgress = [&]() {
ui64 globalProgressValue = globalProgress.load();
std::lock_guard<std::mutex> lock(progressWriteLock);
- Cout << "Progress " << (globalProgressValue / filePathsSize) << '%' << "\r";
- Cout.Flush();
+ progressBar.SetProcess(globalProgressValue / filePathsSize);
};
auto start = TInstant::Now();