Skip to content

Commit

Permalink
Further delay querying for the result of the asynchronous operation
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpf authored Jan 25, 2025
1 parent c0b570f commit 19f65dd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions custom-prompt/custom-prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -626,18 +626,21 @@ void report_command_status(std::string_view& last_command, int exit_code, long l
* Show the primary prompt.
*
* @param shlvl Current shell level.
* @param git_repository_information Current Git repository information.
* @param git_repository_information_future Git information provider.
* @param venv Python virtual environment.
*/
void display_primary_prompt(int shlvl, std::string const& git_repository_information)
void display_primary_prompt(int shlvl, std::future<std::string> const& git_repository_information_future, char const *venv)
{
LOG_DEBUG("Current Git repository information is '%s'.", git_repository_information.data());
char const* venv = std::getenv("VIRTUAL_ENV_PROMPT");
LOG_DEBUG("Current Python virtual environment is '%s'.", venv);
std::cout << "\n" HOST_ICON " " BBI_YELLOW HOST RESET "" BB_CYAN DIRECTORY RESET;
if(git_repository_information_future.wait_for(std::chrono::milliseconds(150)) != std::future_status::ready){
std::cout << "" << B_GREY "unavailable" RESET;
}else{
std::string git_repository_information = git_repository_information_future.get();
if (!git_repository_information.empty())
{
std::cout << "" << git_repository_information;
}
}
if (venv != nullptr)
{
std::cout << "" B_BLUE << venv << RESET;
Expand Down Expand Up @@ -708,10 +711,8 @@ int main_internal(int const argc, char const* argv[])
set_terminal_title(pwd);

int shlvl = std::stoi(argv[7]);
display_primary_prompt(shlvl,
git_repository_information_future.wait_for(std::chrono::milliseconds(150)) == std::future_status::ready
? git_repository_information_future.get()
: B_GREY "unavailable" RESET);
char const *venv = getenv("VIRTUAL_ENV_PROMPT");
display_primary_prompt(shlvl, git_repository_information_future, venv);

return EXIT_SUCCESS;
}
Expand Down

0 comments on commit 19f65dd

Please sign in to comment.