-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* +------------------------------------------------------------------------+ | ||
| Mobile Robot Programming Toolkit (MRPT) | | ||
| https://www.mrpt.org/ | | ||
| | | ||
| Copyright (c) 2005-2024, Individual contributors, see AUTHORS file | | ||
| See: https://www.mrpt.org/Authors - All rights reserved. | | ||
| Released under BSD License. See: https://www.mrpt.org/License | | ||
+------------------------------------------------------------------------+ */ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <string> | ||
|
||
namespace mrpt::system | ||
{ | ||
/** Build an text with a hyperlink, if printed to a terminal that supports it | ||
* (e.g. Ubuntu >=21.04), or the plain text otherwise. | ||
* | ||
* \ingroup mrpt_system_grp | ||
* \note (New in MRPT 2.11.8) | ||
* \sa See discussion in, for example, | ||
* https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda | ||
*/ | ||
std::string hyperlink( | ||
const std::string& text, const std::string& uri, | ||
bool force_use_format = false, bool show_uri_anyway = false); | ||
|
||
} // namespace mrpt::system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* +------------------------------------------------------------------------+ | ||
| Mobile Robot Programming Toolkit (MRPT) | | ||
| https://www.mrpt.org/ | | ||
| | | ||
| Copyright (c) 2005-2024, Individual contributors, see AUTHORS file | | ||
| See: https://www.mrpt.org/Authors - All rights reserved. | | ||
| Released under BSD License. See: https://www.mrpt.org/License | | ||
+------------------------------------------------------------------------+ */ | ||
|
||
#include "system-precomp.h" // Precompiled headers | ||
// | ||
#include <mrpt/core/format.h> | ||
#include <mrpt/system/hyperlink.h> | ||
|
||
#ifndef _WIN32 | ||
#include <unistd.h> | ||
|
||
#include <cstdio> | ||
#endif | ||
|
||
std::string mrpt::system::hyperlink( | ||
const std::string& text, const std::string& uri, bool force_use_format, | ||
bool show_uri_anyway) | ||
{ | ||
using namespace std::string_literals; | ||
|
||
bool supportsLinks = false; | ||
|
||
#ifndef _WIN32 | ||
thread_local bool coutIsAtty = isatty(fileno(stdout)); | ||
supportsLinks = coutIsAtty; | ||
#endif | ||
// See: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda | ||
if (supportsLinks || force_use_format) | ||
return mrpt::format( | ||
"\e]8;;%s\e\\%s\e]8;;\e\\", uri.c_str(), text.c_str()); | ||
else | ||
return show_uri_anyway ? // | ||
(text + " ("s + uri + ")"s) | ||
: // | ||
text; | ||
} |