mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +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:
parent
c54ae3afd6
commit
b0a4bcb688
1 changed files with 21 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue