Use a Unicode default with project-level LaTeX compatibility
This commit is contained in:
1 parent
38a2a4a958
commit
81ac3ae321
11 files changed
+741
-126
No files matched your search
@@ -1,4 +1,6 @@
|
||||
//! Loopback editor for comparing actual native page updates with full jobs.
|
||||
use library::{EditorFormat, ModeChoice};
|
||||
use projects::CompileMode;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
@@ -61,6 +63,13 @@ struct Save {
|
||||
files: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ChangeMode {
|
||||
mode: CompileMode,
|
||||
#[serde(default)]
|
||||
files: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
enum PreviewReply {
|
||||
Http(Request),
|
||||
Socket(mpsc::Sender<(u16, Value)>),
|
||||
@@ -285,7 +294,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
error
|
||||
});
|
||||
}
|
||||
let usage = "native_editor [--input-profile PROFILE] [--web-dir DIR] [--source-root DIR] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...] or native_editor [--input-profile PROFILE] --web-dir DIR --projects STORE FORMAT FORMAT_RESOURCES RUNS [PORT]";
|
||||
let usage = "native_editor [--input-profile PROFILE] [--web-dir DIR] [--source-root DIR] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...] or native_editor [--input-profile PROFILE] --web-dir DIR --projects STORE FORMAT FORMAT_RESOURCES RUNS [--unicode-format FORMAT FORMAT_RESOURCES] [PORT]";
|
||||
let input_profile = if args.next_if(|arg| arg == "--input-profile").is_some() {
|
||||
match args.next().as_deref().and_then(std::ffi::OsStr::to_str) {
|
||||
Some("tex8bit") => InputProfile::TeX8Bit,
|
||||
@@ -313,12 +322,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let format = args.next().ok_or(usage)?.canonicalize()?;
|
||||
let manifest = args.next().ok_or(usage)?.canonicalize()?;
|
||||
let runs = args.next().ok_or(usage)?;
|
||||
let unicode = if args.next_if(|arg| arg == Path::new("--unicode-format")).is_some() {
|
||||
if input_profile != InputProfile::TeX8Bit {
|
||||
return Err("The secondary Unicode format requires a pdfLaTeX primary format".into());
|
||||
}
|
||||
Some(EditorFormat::prepared(
|
||||
args.next().ok_or(usage)?.canonicalize()?,
|
||||
args.next().ok_or(usage)?.canonicalize()?,
|
||||
InputProfile::XeTeX,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Some(library::Library::new(
|
||||
store,
|
||||
format,
|
||||
manifest,
|
||||
runs,
|
||||
input_profile,
|
||||
EditorFormat::prepared(format, manifest, input_profile),
|
||||
unicode,
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
@@ -454,6 +474,37 @@ fn serve(
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if rest == "compile-mode" && request.method() == &Method::Post {
|
||||
if !project_open && pending.is_none() {
|
||||
reply(request, 409, json!({"error": "The project is no longer open. Reload to reopen it."}));
|
||||
continue;
|
||||
}
|
||||
let mut request = request;
|
||||
if !request.headers().iter().any(|header| {
|
||||
header.field.equiv("Content-Type")
|
||||
&& header.value.as_str().split(';').next() == Some("application/json")
|
||||
}) {
|
||||
reply(request, 415, json!({"error": "Expected JSON compilation settings"}));
|
||||
continue;
|
||||
}
|
||||
let change: ChangeMode = match read_json(&mut request) {
|
||||
Ok(change) => change,
|
||||
Err(error) => {
|
||||
reply(request, 400, json!({"error": error}));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
match library.change_mode(id, change.mode, change.files) {
|
||||
Ok(next) => {
|
||||
let payload = next.sources.clone();
|
||||
session = None;
|
||||
opening = Some(next);
|
||||
reply(request, 200, payload);
|
||||
}
|
||||
Err(error) => reply(request, 422, json!({"error": error.to_string()})),
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if request.method() == &Method::Get {
|
||||
match (rest, pending) {
|
||||
("project", Some(opening)) => {
|
||||
@@ -529,6 +580,7 @@ fn serve(
|
||||
compiler,
|
||||
cache,
|
||||
first_preview_revision,
|
||||
mode_choice,
|
||||
queue,
|
||||
save_number,
|
||||
editor,
|
||||
@@ -559,6 +611,9 @@ fn serve(
|
||||
let mut payload = project_payload(
|
||||
run, entry, declared, files, queue.current.load(Ordering::Acquire), id.as_deref(),
|
||||
)?;
|
||||
if let Some(choice) = mode_choice {
|
||||
payload["compile_mode"] = json!(choice);
|
||||
}
|
||||
if cache.as_ref().is_some_and(preview_cache::PreviewCache::exists) {
|
||||
payload["cached_preview"] = json!(true);
|
||||
}
|
||||
@@ -733,14 +788,23 @@ impl OpeningEditor {
|
||||
id: String,
|
||||
run: PathBuf,
|
||||
staged: StagedProject,
|
||||
cache: Option<preview_cache::PreviewCache>,
|
||||
format: EditorFormat,
|
||||
mode_choice: Option<ModeChoice>,
|
||||
cacheable: bool,
|
||||
compiler: NativeCompiler,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let cache = cacheable.then(|| initial_preview_cache(&id, &run, &staged, &format)).flatten();
|
||||
let files = staged.editable.iter().filter_map(|(name, path)| {
|
||||
staged.files.get(path).map(|bytes| (name.as_str(), bytes.as_ref()))
|
||||
});
|
||||
let mut sources = project_payload(&run, &staged.entry, &staged.declared, files, 1, Some(&id))?;
|
||||
sources["preparing"] = json!(true);
|
||||
if !format.image.is_file() {
|
||||
sources["building_format"] = json!(true);
|
||||
}
|
||||
if let Some(choice) = mode_choice {
|
||||
sources["compile_mode"] = json!(choice);
|
||||
}
|
||||
if cache.as_ref().is_some_and(preview_cache::PreviewCache::exists) {
|
||||
sources["cached_preview"] = json!(true);
|
||||
}
|
||||
@@ -758,19 +822,38 @@ impl OpeningEditor {
|
||||
let superseded = opening.superseded.clone();
|
||||
let cache = opening.cache.clone();
|
||||
std::thread::Builder::new().name("texrra-open-project".into()).spawn(move || {
|
||||
let result = finish_prepare(staged, &run, &compiler, Some(&superseded), Some(&id))
|
||||
.map(|editor| {
|
||||
let mut session = EditorSession::new(run, editor, compiler, cache);
|
||||
session.id = Some(id);
|
||||
Arc::new(Mutex::new(session))
|
||||
})
|
||||
.map_err(|error| error.to_string());
|
||||
let result = (|| {
|
||||
format.ensure()?;
|
||||
if superseded.load(Ordering::Acquire) {
|
||||
return Err("The project has closed".to_owned());
|
||||
}
|
||||
let cache = cache.or_else(|| {
|
||||
cacheable.then(|| initial_preview_cache(&id, &run, &staged, &format)).flatten()
|
||||
});
|
||||
let editor = finish_prepare(staged, &run, &compiler, Some(&superseded), Some(&id))
|
||||
.map_err(|error| error.to_string())?;
|
||||
let mut session = EditorSession::new(run, editor, compiler, cache);
|
||||
session.id = Some(id);
|
||||
session.mode_choice = mode_choice;
|
||||
Ok(Arc::new(Mutex::new(session)))
|
||||
})();
|
||||
let _ = ready.set(result);
|
||||
})?;
|
||||
Ok(opening)
|
||||
}
|
||||
}
|
||||
|
||||
fn initial_preview_cache(
|
||||
id: &str,
|
||||
run: &Path,
|
||||
staged: &StagedProject,
|
||||
format: &EditorFormat,
|
||||
) -> Option<preview_cache::PreviewCache> {
|
||||
preview_cache::PreviewCache::for_project(
|
||||
run.parent()?, id, run, staged, &format.image, &format.manifest,
|
||||
)
|
||||
}
|
||||
|
||||
impl Drop for OpeningEditor {
|
||||
fn drop(&mut self) {
|
||||
if self.ready.get().is_none() {
|
||||
@@ -807,6 +890,7 @@ fn project_payload<'a>(
|
||||
|
||||
struct EditorSession {
|
||||
id: Option<String>,
|
||||
mode_choice: Option<ModeChoice>,
|
||||
cache: Option<preview_cache::PreviewCache>,
|
||||
run: PathBuf,
|
||||
compiler: NativeCompiler,
|
||||
@@ -845,6 +929,7 @@ impl EditorSession {
|
||||
});
|
||||
Self {
|
||||
id: None,
|
||||
mode_choice: None,
|
||||
cache,
|
||||
run,
|
||||
compiler,
|
||||
|
||||
Reference in new issue
Block a user