Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make user feedback during ssh login less verbose #1496

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<li>Add generation of config file from internal state (#1282)</li>
<li>Add SGRSAVE and SGRRESTORE VT sequences to save and restore SGR state (They intentionally conflict with XTPUSHSGR and XTPOPSGR)</li>
<li>Update of contour.desktop file (#1423)</li>
<li>Fixed too verbose info during ssh session login (#1447)</li>
<li>Fixes corruption of sixel image on high resolution (#1049)</li>
<li>Fixes bad wording of OS/X to macOS (#1462)</li>
<li>Fixes key bindings and search prompt collision (#1472)</li>
Expand Down
29 changes: 20 additions & 9 deletions src/vtpty/SshSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,10 @@
void SshSession::start()
{
if (_config.port == 22)
logInfo("Starting SSH session to host: {}@{}", _config.username, _config.hostname);
logInfoWithInject("Starting SSH session to host: {}@{}", _config.username, _config.hostname);
else
logInfo("Starting SSH session to host: {}@{}:{}", _config.username, _config.hostname, _config.port);
logInfoWithInject(
"Starting SSH session to host: {}@{}:{}", _config.username, _config.hostname, _config.port);

assert(_state == State::Initial);
// auto const _ = std::lock_guard { _mutex };
Expand Down Expand Up @@ -897,16 +898,25 @@
_injectCV.notify_all();
}

void SshSession::logInject(std::string_view message) const
{
const_cast<SshSession*>(this)->injectRead(fmt::format("\U0001F511 \033[1;33m{}\033[m\r\n", message));

Check warning on line 903 in src/vtpty/SshSession.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy-review

clang-tidy

warning: do not use const_cast [cppcoreguidelines-pro-type-const-cast] ```cpp const_cast<SshSession*>(this)->injectRead(fmt::format("\U0001F511 \033[1;33m{}\033[m\r\n", message)); ^ ```
}

void SshSession::logInfo(std::string_view message) const
{
sshLog()("{}", message);
const_cast<SshSession*>(this)->injectRead(fmt::format("\U0001F511 \033[1;33m{}\033[m\r\n", message));
}

void SshSession::logInfoWithInject(std::string_view message) const
{
logInfo(message);
logInject(message);
}

void SshSession::logError(std::string_view message) const
{
errorLog()("{}", message);
const_cast<SshSession*>(this)->injectRead(fmt::format("\U0001F511 \033[1;31m{}\033[m\r\n", message));
}

bool SshSession::connect(std::string_view host, int port)
Expand Down Expand Up @@ -968,9 +978,9 @@
auto const addrAndPort =
port == 22 ? std::string(addrStr) : fmt::format("{}:{}", addrStr, port);
if (host != addrStr)
logInfo("Connected to {} ({})", host, addrAndPort);
logInfoWithInject("Connected to {} ({})", host, addrAndPort);
else
logInfo("Connected to {}", addrAndPort);
logInfoWithInject("Connected to {}", addrAndPort);
return true;
}

Expand Down Expand Up @@ -1196,7 +1206,7 @@
return;
}

logInfo("Successfully authenticated with private key.");
logInfoWithInject("Successfully authenticated with private key.");

setState(State::OpenChannel);
}
Expand Down Expand Up @@ -1234,7 +1244,7 @@
return;
}

logInfo("Successfully authenticated with password.");
logInfoWithInject("Successfully authenticated with password.");

setState(State::OpenChannel);
}
Expand Down Expand Up @@ -1289,7 +1299,8 @@
}
if (rc == LIBSSH2_ERROR_NONE)
{
logInfo("Successfully authenticated with SSH agent with identity: {}", identity->comment);
logInfoWithInject("Successfully authenticated with SSH agent with identity: {}",
identity->comment);
setState(State::OpenChannel);
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions src/vtpty/SshSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ class SshSession final: public Pty
void setState(State nextState);

void logInfo(std::string_view message) const;
void logInject(std::string_view message) const;
void logInfoWithInject(std::string_view message) const;

template <typename... Args>
void logInfoWithInject(fmt::format_string<Args...> fmt, Args&&... args) const
{
logInfoWithInject(fmt::format(fmt, std::forward<Args>(args)...));
}

template <typename... Args>
void logInfo(fmt::format_string<Args...> fmt, Args&&... args) const
Expand Down
Loading