45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
/**
|
|
* @file main.cpp
|
|
* @author apio (cloudapio.eu)
|
|
* @brief Graphical text editor.
|
|
*
|
|
* @copyright Copyright (c) 2024, the Luna authors.
|
|
*
|
|
*/
|
|
|
|
#include "EditorWidget.h"
|
|
#include <os/ArgumentParser.h>
|
|
#include <os/File.h>
|
|
#include <ui/App.h>
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
{
|
|
StringView path;
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("A graphical text editor"_sv);
|
|
parser.add_system_program_info("editor"_sv);
|
|
parser.add_positional_argument(path, "path", false);
|
|
parser.parse(argc, argv);
|
|
|
|
ui::App app;
|
|
TRY(app.init());
|
|
|
|
auto* window = TRY(ui::Window::create(ui::Rect { 200, 300, 600, 600 }));
|
|
window->set_background(ui::Color::from_rgb(40, 40, 40));
|
|
window->set_title("Text Editor");
|
|
app.set_main_window(window);
|
|
|
|
auto* editor = TRY(window->create_main_widget<EditorWidget>());
|
|
if (!path.is_empty()) TRY(editor->load_file(path));
|
|
|
|
TRY(window->add_keyboard_shortcut({ moon::K_CH26, ui::Mod_Ctrl }, true, [&](ui::Shortcut) {
|
|
auto result = editor->save_file();
|
|
if (result.has_error()) os::eprintln("editor: failed to save file: %s", result.error_string());
|
|
else
|
|
os::println("editor: buffer saved to %s successfully", editor->path().name().chars());
|
|
}));
|
|
|
|
return app.run();
|
|
}
|