From 5b72d17ff642c8d5d20bc1487466c13ebd6cfb45 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Wed, 21 Oct 2020 18:06:36 +0330 Subject: [PATCH] Userland: Make `man` provide a `view_width` to `render_for_terminal()' This makes tables actually show up when rendered through `man' --- Userland/man.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Userland/man.cpp b/Userland/man.cpp index feb4887aa5..8c53760728 100644 --- a/Userland/man.cpp +++ b/Userland/man.cpp @@ -30,10 +30,21 @@ #include #include #include +#include #include int main(int argc, char* argv[]) { + int view_width = 0; + if (isatty(STDOUT_FILENO)) { + struct winsize ws; + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0) + view_width = ws.ws_col; + } + + if (view_width == 0) + view_width = 80; + if (pledge("stdio rpath", nullptr) < 0) { perror("pledge"); return 1; @@ -104,6 +115,6 @@ int main(int argc, char* argv[]) auto document = Markdown::Document::parse(source); ASSERT(document); - String rendered = document->render_for_terminal(); + String rendered = document->render_for_terminal(view_width); printf("%s", rendered.characters()); }