1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:17:46 +00:00

shot: Make output filename a hyperlink when applicable

The hyperlink only gets printed when stdout is a TTY, so e.g. something
like `shot | cat` will not get the hyperlink escapes.
This commit is contained in:
Ryan Liptak 2021-07-31 20:22:27 -07:00 committed by Gunnar Beutner
parent c54ae3afd6
commit b0a4bcb688

View file

@ -7,6 +7,7 @@
#include <AK/Format.h>
#include <AK/Optional.h>
#include <AK/URL.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DateTime.h>
#include <LibCore/File.h>
@ -166,6 +167,25 @@ int main(int argc, char** argv)
return 1;
}
outln("{}", output_path);
bool printed_hyperlink = false;
if (isatty(STDOUT_FILENO)) {
auto full_path = Core::File::real_path_for(output_path);
if (!full_path.is_null()) {
char hostname[HOST_NAME_MAX];
VERIFY(gethostname(hostname, sizeof(hostname)) == 0);
auto url = URL::create_with_file_scheme(full_path, {}, hostname);
out("\033]8;;{}\033\\", url.serialize());
printed_hyperlink = true;
}
}
out("{}", output_path);
if (printed_hyperlink) {
out("\033]8;;\033\\");
}
outln("");
return 0;
}