|
32 | 32 | #include "io-util.h" |
33 | 33 | #include "log.h" |
34 | 34 | #include "macro.h" |
35 | | -#include "pager.h" |
36 | 35 | #include "parse-util.h" |
37 | 36 | #include "path-util.h" |
38 | 37 | #include "proc-cmdline.h" |
@@ -1272,184 +1271,3 @@ int vt_reset_keyboard(int fd) { |
1272 | 1271 |
|
1273 | 1272 | return 0; |
1274 | 1273 | } |
1275 | | - |
1276 | | -static bool urlify_enabled(void) { |
1277 | | - static int cached_urlify_enabled = -1; |
1278 | | - |
1279 | | - /* Unfortunately 'less' doesn't support links like this yet 😭, hence let's disable this as long as there's a |
1280 | | - * pager in effect. Let's drop this check as soon as less got fixed a and enough time passed so that it's safe |
1281 | | - * to assume that a link-enabled 'less' version has hit most installations. */ |
1282 | | - |
1283 | | - if (cached_urlify_enabled < 0) { |
1284 | | - int val; |
1285 | | - |
1286 | | - val = getenv_bool("SYSTEMD_URLIFY"); |
1287 | | - if (val >= 0) |
1288 | | - cached_urlify_enabled = val; |
1289 | | - else |
1290 | | - cached_urlify_enabled = colors_enabled() && !pager_have(); |
1291 | | - } |
1292 | | - |
1293 | | - return cached_urlify_enabled; |
1294 | | -} |
1295 | | - |
1296 | | -int terminal_urlify(const char *url, const char *text, char **ret) { |
1297 | | - char *n; |
1298 | | - |
1299 | | - assert(url); |
1300 | | - |
1301 | | - /* Takes an URL and a pretty string and formats it as clickable link for the terminal. See |
1302 | | - * https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda for details. */ |
1303 | | - |
1304 | | - if (isempty(text)) |
1305 | | - text = url; |
1306 | | - |
1307 | | - if (urlify_enabled()) |
1308 | | - n = strjoin("\x1B]8;;", url, "\a", text, "\x1B]8;;\a"); |
1309 | | - else |
1310 | | - n = strdup(text); |
1311 | | - if (!n) |
1312 | | - return -ENOMEM; |
1313 | | - |
1314 | | - *ret = n; |
1315 | | - return 0; |
1316 | | -} |
1317 | | - |
1318 | | -int terminal_urlify_path(const char *path, const char *text, char **ret) { |
1319 | | - _cleanup_free_ char *absolute = NULL; |
1320 | | - struct utsname u; |
1321 | | - const char *url; |
1322 | | - int r; |
1323 | | - |
1324 | | - assert(path); |
1325 | | - |
1326 | | - /* Much like terminal_urlify() above, but takes a file system path as input |
1327 | | - * and turns it into a proper file:// URL first. */ |
1328 | | - |
1329 | | - if (isempty(path)) |
1330 | | - return -EINVAL; |
1331 | | - |
1332 | | - if (isempty(text)) |
1333 | | - text = path; |
1334 | | - |
1335 | | - if (!urlify_enabled()) { |
1336 | | - char *n; |
1337 | | - |
1338 | | - n = strdup(text); |
1339 | | - if (!n) |
1340 | | - return -ENOMEM; |
1341 | | - |
1342 | | - *ret = n; |
1343 | | - return 0; |
1344 | | - } |
1345 | | - |
1346 | | - if (uname(&u) < 0) |
1347 | | - return -errno; |
1348 | | - |
1349 | | - if (!path_is_absolute(path)) { |
1350 | | - r = path_make_absolute_cwd(path, &absolute); |
1351 | | - if (r < 0) |
1352 | | - return r; |
1353 | | - |
1354 | | - path = absolute; |
1355 | | - } |
1356 | | - |
1357 | | - /* As suggested by https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda, let's include the local |
1358 | | - * hostname here. Note that we don't use gethostname_malloc() or gethostname_strict() since we are interested |
1359 | | - * in the raw string the kernel has set, whatever it may be, under the assumption that terminals are not overly |
1360 | | - * careful with validating the strings either. */ |
1361 | | - |
1362 | | - url = strjoina("file://", u.nodename, path); |
1363 | | - |
1364 | | - return terminal_urlify(url, text, ret); |
1365 | | -} |
1366 | | - |
1367 | | -int terminal_urlify_man(const char *page, const char *section, char **ret) { |
1368 | | - const char *url, *text; |
1369 | | - |
1370 | | - url = strjoina("man:", page, "(", section, ")"); |
1371 | | - text = strjoina(page, "(", section, ") man page"); |
1372 | | - |
1373 | | - return terminal_urlify(url, text, ret); |
1374 | | -} |
1375 | | - |
1376 | | -static int cat_file(const char *filename, bool newline) { |
1377 | | - _cleanup_fclose_ FILE *f = NULL; |
1378 | | - _cleanup_free_ char *urlified = NULL; |
1379 | | - int r; |
1380 | | - |
1381 | | - f = fopen(filename, "re"); |
1382 | | - if (!f) |
1383 | | - return -errno; |
1384 | | - |
1385 | | - r = terminal_urlify_path(filename, NULL, &urlified); |
1386 | | - if (r < 0) |
1387 | | - return r; |
1388 | | - |
1389 | | - printf("%s%s# %s%s\n", |
1390 | | - newline ? "\n" : "", |
1391 | | - ansi_highlight_blue(), |
1392 | | - urlified, |
1393 | | - ansi_normal()); |
1394 | | - fflush(stdout); |
1395 | | - |
1396 | | - for (;;) { |
1397 | | - _cleanup_free_ char *line = NULL; |
1398 | | - |
1399 | | - r = read_line(f, LONG_LINE_MAX, &line); |
1400 | | - if (r < 0) |
1401 | | - return log_error_errno(r, "Failed to read \"%s\": %m", filename); |
1402 | | - if (r == 0) |
1403 | | - break; |
1404 | | - |
1405 | | - puts(line); |
1406 | | - } |
1407 | | - |
1408 | | - return 0; |
1409 | | -} |
1410 | | - |
1411 | | -int cat_files(const char *file, char **dropins, CatFlags flags) { |
1412 | | - char **path; |
1413 | | - int r; |
1414 | | - |
1415 | | - if (file) { |
1416 | | - r = cat_file(file, false); |
1417 | | - if (r == -ENOENT && (flags & CAT_FLAGS_MAIN_FILE_OPTIONAL)) |
1418 | | - printf("%s# config file %s not found%s\n", |
1419 | | - ansi_highlight_magenta(), |
1420 | | - file, |
1421 | | - ansi_normal()); |
1422 | | - else if (r < 0) |
1423 | | - return log_warning_errno(r, "Failed to cat %s: %m", file); |
1424 | | - } |
1425 | | - |
1426 | | - STRV_FOREACH(path, dropins) { |
1427 | | - r = cat_file(*path, file || path != dropins); |
1428 | | - if (r < 0) |
1429 | | - return log_warning_errno(r, "Failed to cat %s: %m", *path); |
1430 | | - } |
1431 | | - |
1432 | | - return 0; |
1433 | | -} |
1434 | | - |
1435 | | -void print_separator(void) { |
1436 | | - |
1437 | | - /* Outputs a separator line that resolves to whitespace when copied from the terminal. We do that by outputting |
1438 | | - * one line filled with spaces with ANSI underline set, followed by a second (empty) line. */ |
1439 | | - |
1440 | | - if (underline_enabled()) { |
1441 | | - size_t i, c; |
1442 | | - |
1443 | | - c = columns(); |
1444 | | - |
1445 | | - flockfile(stdout); |
1446 | | - fputs_unlocked(ANSI_UNDERLINE, stdout); |
1447 | | - |
1448 | | - for (i = 0; i < c; i++) |
1449 | | - fputc_unlocked(' ', stdout); |
1450 | | - |
1451 | | - fputs_unlocked(ANSI_NORMAL "\n\n", stdout); |
1452 | | - funlockfile(stdout); |
1453 | | - } else |
1454 | | - fputs("\n\n", stdout); |
1455 | | -} |
0 commit comments