mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
md: Port to LibMain
This commit is contained in:
parent
dff6460373
commit
5f602e39e9
2 changed files with 8 additions and 12 deletions
|
@ -127,7 +127,7 @@ target_link_libraries(lsusb LibUSBDB LibMain)
|
||||||
target_link_libraries(man LibMarkdown LibMain)
|
target_link_libraries(man LibMarkdown LibMain)
|
||||||
target_link_libraries(markdown-check LibMarkdown)
|
target_link_libraries(markdown-check LibMarkdown)
|
||||||
target_link_libraries(matroska LibVideo)
|
target_link_libraries(matroska LibVideo)
|
||||||
target_link_libraries(md LibMarkdown)
|
target_link_libraries(md LibMarkdown LibMain)
|
||||||
target_link_libraries(mkdir LibMain)
|
target_link_libraries(mkdir LibMain)
|
||||||
target_link_libraries(mkfifo LibMain)
|
target_link_libraries(mkfifo LibMain)
|
||||||
target_link_libraries(mknod LibMain)
|
target_link_libraries(mknod LibMain)
|
||||||
|
|
|
@ -7,17 +7,15 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (pledge("stdio rpath tty", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio rpath tty"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* filename = nullptr;
|
const char* filename = nullptr;
|
||||||
bool html = false;
|
bool html = false;
|
||||||
|
@ -28,7 +26,7 @@ int main(int argc, char* argv[])
|
||||||
args_parser.add_option(html, "Render to HTML rather than for the terminal", "html", 'H');
|
args_parser.add_option(html, "Render to HTML rather than for the terminal", "html", 'H');
|
||||||
args_parser.add_option(view_width, "Viewport width for the terminal (defaults to current terminal width)", "view-width", 0, "width");
|
args_parser.add_option(view_width, "Viewport width for the terminal (defaults to current terminal width)", "view-width", 0, "width");
|
||||||
args_parser.add_positional_argument(filename, "Path to Markdown file", "path", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(filename, "Path to Markdown file", "path", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
if (!html && view_width == 0) {
|
if (!html && view_width == 0) {
|
||||||
if (isatty(STDOUT_FILENO)) {
|
if (isatty(STDOUT_FILENO)) {
|
||||||
|
@ -55,10 +53,7 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pledge("stdio", nullptr) < 0) {
|
TRY(Core::System::pledge("stdio"));
|
||||||
perror("pledge");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto buffer = file->read_all();
|
auto buffer = file->read_all();
|
||||||
dbgln("Read size {}", buffer.size());
|
dbgln("Read size {}", buffer.size());
|
||||||
|
@ -73,4 +68,5 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
String res = html ? document->render_to_html() : document->render_for_terminal(view_width);
|
String res = html ? document->render_to_html() : document->render_for_terminal(view_width);
|
||||||
out("{}", res);
|
out("{}", res);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue