Userland: Make man provide a view_width to `render_for_terminal()'

This makes tables actually show up when rendered through `man'
This commit is contained in:
AnotherTest 2020-10-21 18:06:36 +03:30 committed by Andreas Kling
parent 619cd613d0
commit 5b72d17ff6
Notes: sideshowbarker 2024-07-19 01:48:31 +09:00

View file

@ -30,10 +30,21 @@
#include <LibCore/File.h>
#include <LibMarkdown/Document.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
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());
}