Skip to content

Commit

Permalink
Merge pull request #1496 from contour-terminal/fix/ssh_better_feedback
Browse files Browse the repository at this point in the history
Make user feedback during ssh login less verbose
  • Loading branch information
christianparpart authored Apr 16, 2024
2 parents ab3cbc9 + 25f5832 commit 8887acb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
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::processState()
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 @@ void SshSession::injectRead(std::string_view buf)
_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));
}

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 @@ bool SshSession::connect(std::string_view host, int port)
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 @@ void SshSession::authenticateWithPrivateKey()
return;
}

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

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

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

setState(State::OpenChannel);
}
Expand Down Expand Up @@ -1289,7 +1299,8 @@ bool SshSession::authenticateWithAgent()
}
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

0 comments on commit 8887acb

Please sign in to comment.