Skip to content

Commit

Permalink
Mpult warning parse (#33)
Browse files Browse the repository at this point in the history
* Added rudementary warning/error parsing

* move parsing code to programs where it belongs

* Now parsing errors that cross two lines

* fix bug where clean sometimes fails

* Merge something, idk

* Improve info module (#15)

* Version checker (#18)

* Added version checker

* fix bug that makes in not work

* remove itex-version-info.toml from list

* merge

* improve tex_filename (#20)

* update deps and change default build_artifacts path to itex-build

* change version to 1.4.0-dev

* Merge better errors (#27)

* Merge global ITex settings (#29)

* Add the safe-build command (#30)

* fix some bugs

* Merge release infra (#19)

* fix formating

* fix an oopsie

* windows env var fix

* merge

* merge

* use RUST_LOG when in a debug build

* fix debug printing and triple printing

* fix formating

---------

Co-authored-by: Maximilian Pult <it@optik-riede.de>
  • Loading branch information
oneElectron and MPult committed Nov 22, 2023
1 parent 6c95c95 commit a3e2ca2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::clean::clean_build_artifacts_folder;
use crate::prelude::*;

use std::io::{stdout, Write};

pub fn build(debug: bool, draft_mode: bool, settings: Option<Settings>) {
Expand All @@ -15,12 +16,12 @@ pub fn build(debug: bool, draft_mode: bool, settings: Option<Settings>) {
let pdflatex = PDFLatex::from_settings(settings.clone());
let bibtex = Bibtex::from_settings(settings.clone());

pdflatex.run();
let bibtex_output = bibtex.run();
pdflatex.run();
let pdflatex_output = pdflatex.run();
pdflatex.run(false);
let bibtex_output = bibtex.run(true);
pdflatex.run(false);
let pdflatex_output = pdflatex.run(true);

if debug || settings.debug() || !pdflatex_output.status.success() {
if debug || settings.debug() {
println!("{}", console::style("--- PDFLatex Output ---").blue().bold());
stdout().write_all(&pdflatex_output.stdout).unwrap();
println!("{}", console::style("--- Bibtex Output ---").blue().bold());
Expand Down
2 changes: 1 addition & 1 deletion src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn count() {

let texcount = Texcount::from_settings(settings);

let output = texcount.run();
let output = texcount.run(true);

std::io::stdout().write_all(&output.stdout).unwrap();
}
2 changes: 1 addition & 1 deletion src/programs/bibtex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Executable for Bibtex {
}
}

fn run(&self) -> std::process::Output {
fn run(&self, _print_errors: bool) -> std::process::Output {
let output = std::process::Command::new(self.exe_path.clone()).args(self.args.clone()).output();

if output.is_err() {
Expand Down
2 changes: 1 addition & 1 deletion src/programs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ use std::path::PathBuf;

pub trait Executable {
fn from_settings(settings: crate::Settings) -> Self;
fn run(&self) -> std::process::Output;
fn run(&self, print_error: bool) -> std::process::Output;
fn set_executable_path(&mut self, path: PathBuf);
}
37 changes: 36 additions & 1 deletion src/programs/pdflatex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Executable for PDFLatex {
}
}

fn run(&self) -> std::process::Output {
fn run(&self, print_errors: bool) -> std::process::Output {
let output = std::process::Command::new(self.exe_path.clone()).args(self.args.clone()).output();

if output.is_err() {
Expand All @@ -45,6 +45,10 @@ impl Executable for PDFLatex {

let output = unwrap_result!(output, "Failed to read output of pdflatex");

if print_errors {
Self::check_error(&output);
}

output
}

Expand All @@ -63,3 +67,34 @@ impl Executable for PDFLatex {
}
}
}

impl PDFLatex {
fn check_error(output: &std::process::Output) {
let stdout = std::str::from_utf8(&output.stdout);
if stdout.is_err() {
return;
}
let stdout = stdout.unwrap().to_lowercase();
let mut buffer: &str = "";

for line in stdout.lines() {
// check buffer to see if this iteration is a continuation of last error line
if !buffer.is_empty() {
// This is the continuation
println!("{}{}", style(buffer).yellow().bold(), style(line).yellow().bold());
buffer = "";
} else {
// This is new
if line.to_ascii_lowercase().contains("warning") || line.to_ascii_lowercase().contains("error") {
buffer = line;
}
}
}

let stderr = std::str::from_utf8(&output.stderr);
if stderr.is_err() {
return;
}
let stderr = stderr.unwrap();
}
}
2 changes: 1 addition & 1 deletion src/programs/texcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Executable for Texcount {
}
}

fn run(&self) -> std::process::Output {
fn run(&self, _print_errors: bool) -> std::process::Output {
let output = std::process::Command::new(self.exe_path.clone()).args(self.args.clone()).output();

if output.is_err() {
Expand Down

0 comments on commit a3e2ca2

Please sign in to comment.