Skip to content

Commit

Permalink
Merge pull request #169 from smehringer/stdin
Browse files Browse the repository at this point in the history
[FIX] Do not consume std::cin in interactive mode.
  • Loading branch information
eseiler authored Jan 13, 2023
2 parents 8d0ee72 + d2a3894 commit e7e9556
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/sharg/detail/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace sharg::detail
inline bool is_terminal()
{
#ifndef _WIN32
return isatty(STDOUT_FILENO);
return isatty(STDIN_FILENO);
#else
return false;
#endif
Expand Down
21 changes: 6 additions & 15 deletions include/sharg/detail/version_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,18 @@ class version_checker
)";
std::string line{};
std::getline(std::cin, line);
line.resize(1); // ignore everything but the first char or resizes the empty string to the default
line.resize(1, 's'); // ignore everything but the first char or resizes the empty string to the default

switch (line[0])
{
case 'y':
{
return true;
}
case 's':
case 'a':
{
return false;
write_cookie(std::string{"ALWAYS"}); // overwrite cookie
return true;
}
case 'n':
{
Expand All @@ -380,23 +381,13 @@ class version_checker
}
default:
{
write_cookie(std::string{"ALWAYS"}); // overwrite cookie
return true;
return false;
}
}
}
else // if !detail::is_terminal()
{
std::cerr << R"(
#######################################################################
Automatic Update Notifications
#######################################################################
This app performs automatic checks for updates. For more information
see: https://docs.seqan.de/sharg/main_user/about_update_notifications.html
#######################################################################
)";
return true; // default: check version if you cannot ask the user
return false; // default: do not check version today, if you cannot ask the user
}
} // LCOV_EXCL_STOP

Expand Down

1 comment on commit e7e9556

@vercel
Copy link

@vercel vercel bot commented on e7e9556 Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sharg-parser – ./

sharg-parser-seqan.vercel.app
sharg-parser-git-main-seqan.vercel.app
sharg.vercel.app
sharg-100.vercel.app

Please sign in to comment.