mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
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:
parent
619cd613d0
commit
5b72d17ff6
1 changed files with 12 additions and 1 deletions
|
@ -30,10 +30,21 @@
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
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) {
|
if (pledge("stdio rpath", nullptr) < 0) {
|
||||||
perror("pledge");
|
perror("pledge");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -104,6 +115,6 @@ int main(int argc, char* argv[])
|
||||||
auto document = Markdown::Document::parse(source);
|
auto document = Markdown::Document::parse(source);
|
||||||
ASSERT(document);
|
ASSERT(document);
|
||||||
|
|
||||||
String rendered = document->render_for_terminal();
|
String rendered = document->render_for_terminal(view_width);
|
||||||
printf("%s", rendered.characters());
|
printf("%s", rendered.characters());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue