From 38607b8bea1ede7a124c8fe384d7efca76f9f011 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 30 Sep 2020 21:23:48 +0200 Subject: =?UTF-8?q?Re-add=20src=20folder=20in=20main=20=F0=9F=93=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/Cargo.toml | 6 +---- main/main.rs | 74 -------------------------------------------------------- main/src/main.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 79 deletions(-) delete mode 100644 main/main.rs create mode 100644 main/src/main.rs diff --git a/main/Cargo.toml b/main/Cargo.toml index dcb75981..65e61cfd 100644 --- a/main/Cargo.toml +++ b/main/Cargo.toml @@ -6,9 +6,5 @@ edition = "2018" [dependencies] typstc = { path = ".." } -fontdock = { path = "../../fontdock", features = ["fs"] } +fontdock = { path = "../../fontdock" } futures-executor = "0.3" - -[[bin]] -name = "typstc-main" -path = "main.rs" diff --git a/main/main.rs b/main/main.rs deleted file mode 100644 index 5b3538d5..00000000 --- a/main/main.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::cell::RefCell; -use std::fs::{read_to_string, File}; -use std::io::BufWriter; -use std::path::{Path, PathBuf}; -use std::rc::Rc; - -use fontdock::fs::{FsIndex, FsProvider}; -use futures_executor::block_on; - -use typstc::export::pdf; -use typstc::font::FontLoader; -use typstc::syntax::LineMap; -use typstc::{Feedback, Pass, Typesetter}; - -fn main() { - let args: Vec<_> = std::env::args().collect(); - if args.len() < 2 || args.len() > 3 { - println!("Usage: typst src.typ [out.pdf]"); - return; - } - - let src_path = Path::new(&args[1]); - let dest_path = if args.len() <= 2 { - src_path.with_extension("pdf") - } else { - PathBuf::from(&args[2]) - }; - - if src_path == dest_path { - panic!("source and destination path are the same"); - } - - let src = read_to_string(src_path).expect("failed to read from source file"); - - let mut index = FsIndex::new(); - index.search_dir("fonts"); - index.search_os(); - - let (descriptors, files) = index.into_vecs(); - let provider = FsProvider::new(files); - let loader = FontLoader::new(Box::new(provider), descriptors); - let loader = Rc::new(RefCell::new(loader)); - - let typesetter = Typesetter::new(loader.clone()); - let Pass { - output: layouts, - feedback: Feedback { mut diagnostics, .. }, - } = block_on(typesetter.typeset(&src)); - - if !diagnostics.is_empty() { - diagnostics.sort(); - - let map = LineMap::new(&src); - for diagnostic in diagnostics { - let span = diagnostic.span; - let start = map.location(span.start); - let end = map.location(span.end); - - println!( - " {}: {}:{}-{}: {}", - diagnostic.v.level, - src_path.display(), - start, - end, - diagnostic.v.message, - ); - } - } - - let loader = loader.borrow(); - let file = File::create(&dest_path).expect("failed to create output file"); - let writer = BufWriter::new(file); - pdf::export(&layouts, &loader, writer).expect("failed to export pdf"); -} diff --git a/main/src/main.rs b/main/src/main.rs new file mode 100644 index 00000000..5b3538d5 --- /dev/null +++ b/main/src/main.rs @@ -0,0 +1,74 @@ +use std::cell::RefCell; +use std::fs::{read_to_string, File}; +use std::io::BufWriter; +use std::path::{Path, PathBuf}; +use std::rc::Rc; + +use fontdock::fs::{FsIndex, FsProvider}; +use futures_executor::block_on; + +use typstc::export::pdf; +use typstc::font::FontLoader; +use typstc::syntax::LineMap; +use typstc::{Feedback, Pass, Typesetter}; + +fn main() { + let args: Vec<_> = std::env::args().collect(); + if args.len() < 2 || args.len() > 3 { + println!("Usage: typst src.typ [out.pdf]"); + return; + } + + let src_path = Path::new(&args[1]); + let dest_path = if args.len() <= 2 { + src_path.with_extension("pdf") + } else { + PathBuf::from(&args[2]) + }; + + if src_path == dest_path { + panic!("source and destination path are the same"); + } + + let src = read_to_string(src_path).expect("failed to read from source file"); + + let mut index = FsIndex::new(); + index.search_dir("fonts"); + index.search_os(); + + let (descriptors, files) = index.into_vecs(); + let provider = FsProvider::new(files); + let loader = FontLoader::new(Box::new(provider), descriptors); + let loader = Rc::new(RefCell::new(loader)); + + let typesetter = Typesetter::new(loader.clone()); + let Pass { + output: layouts, + feedback: Feedback { mut diagnostics, .. }, + } = block_on(typesetter.typeset(&src)); + + if !diagnostics.is_empty() { + diagnostics.sort(); + + let map = LineMap::new(&src); + for diagnostic in diagnostics { + let span = diagnostic.span; + let start = map.location(span.start); + let end = map.location(span.end); + + println!( + " {}: {}:{}-{}: {}", + diagnostic.v.level, + src_path.display(), + start, + end, + diagnostic.v.message, + ); + } + } + + let loader = loader.borrow(); + let file = File::create(&dest_path).expect("failed to create output file"); + let writer = BufWriter::new(file); + pdf::export(&layouts, &loader, writer).expect("failed to export pdf"); +} -- cgit v1.2.3