use iced::{Element, Subscription, Task};
use scrive_core::SyntaxDef;
use scrive_iced::{CodeEditor, Event};
struct App {
editor: CodeEditor,
}
#[derive(Debug, Clone)]
enum Message {
Editor(Event),
}
impl App {
fn new() -> Self {
let grammar = SyntaxDef::from_sublime_syntax(include_str!("assets/rust.sublime-syntax"))
.expect("bundled Rust grammar parses");
let source = "fn main() {\n // edit me — highlighting is on at load\n println!(\"hello, scrive\");\n}\n";
Self { editor: CodeEditor::new(source).language(grammar) }
}
fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Editor(event) => self.editor.update(event).map(Message::Editor),
}
}
fn view(&self) -> Element<'_, Message> {
self.editor.view().map(Message::Editor)
}
fn subscription(&self) -> Subscription<Message> {
self.editor.subscription().map(Message::Editor)
}
}
fn main() -> iced::Result {
let app = iced::application(App::new, App::update, App::view)
.title("scrive — minimal")
.subscription(App::subscription);
scrive_iced::required_fonts()
.iter()
.fold(app, |app, font| app.font(*font))
.run()
}