man: Center "SerenityOS manual" title

This patch calculates how many spaces are needed to center the top
title of "SerenityOS manual".
This commit is contained in:
xSlendiX 2022-02-16 23:10:44 +02:00 committed by Andreas Kling
parent 246c31ccf6
commit 19b7a5fe0d
Notes: sideshowbarker 2024-07-17 18:37:55 +09:00

View file

@ -116,13 +116,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto buffer = file->read_all();
auto source = String::copy(buffer);
outln("{}({})\t\tSerenityOS manual", name, section);
const String title("SerenityOS manual");
int spaces = view_width / 2 - String(name).length() - String(section).length() - title.length() / 2 - 4;
if (spaces < 0)
spaces = 0;
out("{}({})", name, section);
while (spaces--)
out(" ");
outln(title);
auto document = Markdown::Document::parse(source);
VERIFY(document);
String rendered = document->render_for_terminal(view_width);
out("{}", rendered);
outln("{}", rendered);
// FIXME: Remove this wait, it shouldn't be necessary but Shell does not
// resume properly without it. This wait also breaks <C-z> backgrounding