2020-07-04 21:41:32 -04:00
|
|
|
#![allow(clippy::needless_update)]
|
|
|
|
|
2020-11-04 22:14:59 -05:00
|
|
|
use std::borrow::Cow;
|
2019-06-22 11:12:54 -04:00
|
|
|
use std::io::{self, Write};
|
2020-11-16 21:02:10 -05:00
|
|
|
use std::sync::atomic;
|
2019-06-22 11:12:54 -04:00
|
|
|
|
2019-08-07 09:20:18 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_more::From)]
|
2019-07-16 21:16:54 -04:00
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
#[serde(tag = "type")]
|
2020-03-24 07:11:31 -04:00
|
|
|
#[non_exhaustive]
|
2019-07-16 21:16:54 -04:00
|
|
|
pub enum Message<'m> {
|
|
|
|
BinaryFile(BinaryFile<'m>),
|
2020-11-04 22:14:59 -05:00
|
|
|
Typo(Typo<'m>),
|
2019-10-30 09:26:59 -04:00
|
|
|
File(File<'m>),
|
|
|
|
Parse(Parse<'m>),
|
2020-11-23 12:20:12 -05:00
|
|
|
Error(Error<'m>),
|
2019-07-16 21:16:54 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 22:08:38 -04:00
|
|
|
impl<'m> Message<'m> {
|
|
|
|
pub fn is_correction(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Message::BinaryFile(_) => false,
|
2020-11-04 22:14:59 -05:00
|
|
|
Message::Typo(c) => c.corrections.is_correction(),
|
2020-06-30 22:08:38 -04:00
|
|
|
Message::File(_) => false,
|
|
|
|
Message::Parse(_) => false,
|
|
|
|
Message::Error(_) => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_error(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
Message::BinaryFile(_) => false,
|
2020-11-04 22:14:59 -05:00
|
|
|
Message::Typo(_) => false,
|
2020-06-30 22:08:38 -04:00
|
|
|
Message::File(_) => false,
|
|
|
|
Message::Parse(_) => false,
|
|
|
|
Message::Error(_) => true,
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 07:01:01 -05:00
|
|
|
|
2020-11-11 13:19:22 -05:00
|
|
|
pub fn context(self, context: Option<Context<'m>>) -> Self {
|
2020-11-10 07:01:01 -05:00
|
|
|
match self {
|
|
|
|
Message::Typo(typo) => {
|
|
|
|
let typo = typo.context(context);
|
|
|
|
Message::Typo(typo)
|
|
|
|
}
|
|
|
|
Message::Parse(parse) => {
|
|
|
|
let parse = parse.context(context);
|
|
|
|
Message::Parse(parse)
|
|
|
|
}
|
2020-11-23 12:20:12 -05:00
|
|
|
Message::Error(error) => {
|
|
|
|
let error = error.context(context);
|
|
|
|
Message::Error(error)
|
|
|
|
}
|
2020-11-10 07:01:01 -05:00
|
|
|
_ => self,
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 22:08:38 -04:00
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_more::Display, derive_setters::Setters)]
|
2019-08-07 09:25:55 -04:00
|
|
|
#[display(fmt = "Skipping binary file {}", "path.display()")]
|
2020-03-24 07:11:31 -04:00
|
|
|
#[non_exhaustive]
|
2019-07-16 21:16:54 -04:00
|
|
|
pub struct BinaryFile<'m> {
|
|
|
|
pub path: &'m std::path::Path,
|
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
2020-11-04 22:14:59 -05:00
|
|
|
pub struct Typo<'m> {
|
2020-11-10 07:10:23 -05:00
|
|
|
#[serde(flatten)]
|
2020-11-11 13:19:22 -05:00
|
|
|
pub context: Option<Context<'m>>,
|
2019-01-24 10:24:20 -05:00
|
|
|
#[serde(skip)]
|
2020-11-04 22:14:59 -05:00
|
|
|
pub buffer: Cow<'m, [u8]>,
|
2020-03-31 20:55:07 -04:00
|
|
|
pub byte_offset: usize,
|
2019-06-23 00:01:27 -04:00
|
|
|
pub typo: &'m str,
|
2020-12-30 20:41:08 -05:00
|
|
|
pub corrections: typos::Status<'m>,
|
2019-01-24 10:24:20 -05:00
|
|
|
}
|
|
|
|
|
2020-11-04 22:14:59 -05:00
|
|
|
impl<'m> Default for Typo<'m> {
|
2020-03-24 07:11:31 -04:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-11-11 13:19:22 -05:00
|
|
|
context: None,
|
2020-11-04 22:14:59 -05:00
|
|
|
buffer: Cow::Borrowed(&[]),
|
2020-03-24 07:11:31 -04:00
|
|
|
byte_offset: 0,
|
|
|
|
typo: "",
|
2020-12-30 20:41:08 -05:00
|
|
|
corrections: typos::Status::Invalid,
|
2020-03-24 07:11:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 22:14:59 -05:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_more::From)]
|
2020-11-10 07:10:23 -05:00
|
|
|
#[serde(untagged)]
|
2020-11-04 22:14:59 -05:00
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum Context<'m> {
|
|
|
|
File(FileContext<'m>),
|
|
|
|
Path(PathContext<'m>),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'m> std::fmt::Display for Context<'m> {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
|
|
|
match self {
|
|
|
|
Context::File(c) => write!(f, "{}:{}", c.path.display(), c.line_num),
|
|
|
|
Context::Path(c) => write!(f, "{}", c.path.display()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
2020-11-04 22:14:59 -05:00
|
|
|
pub struct FileContext<'m> {
|
2019-07-18 22:20:45 -04:00
|
|
|
pub path: &'m std::path::Path,
|
2020-11-04 22:14:59 -05:00
|
|
|
pub line_num: usize,
|
2020-03-24 07:11:31 -04:00
|
|
|
}
|
|
|
|
|
2020-11-04 22:14:59 -05:00
|
|
|
impl<'m> Default for FileContext<'m> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: std::path::Path::new("-"),
|
|
|
|
line_num: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub struct PathContext<'m> {
|
|
|
|
pub path: &'m std::path::Path,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'m> Default for PathContext<'m> {
|
2020-03-24 07:11:31 -04:00
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
path: std::path::Path::new("-"),
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 22:20:45 -04:00
|
|
|
}
|
|
|
|
|
2019-10-30 09:26:59 -04:00
|
|
|
#[derive(Copy, Clone, Debug, serde::Serialize)]
|
2020-11-10 07:10:23 -05:00
|
|
|
#[serde(rename_all = "snake_case")]
|
2020-03-24 07:11:31 -04:00
|
|
|
#[non_exhaustive]
|
2019-10-30 09:26:59 -04:00
|
|
|
pub enum ParseKind {
|
|
|
|
Identifier,
|
|
|
|
Word,
|
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
2019-10-30 09:26:59 -04:00
|
|
|
pub struct File<'m> {
|
|
|
|
pub path: &'m std::path::Path,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'m> File<'m> {
|
|
|
|
pub fn new(path: &'m std::path::Path) -> Self {
|
2020-03-24 07:11:31 -04:00
|
|
|
Self { path }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'m> Default for File<'m> {
|
|
|
|
fn default() -> Self {
|
2019-10-30 09:26:59 -04:00
|
|
|
Self {
|
2020-03-24 07:11:31 -04:00
|
|
|
path: std::path::Path::new("-"),
|
2019-10-30 09:26:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
2019-10-30 09:26:59 -04:00
|
|
|
pub struct Parse<'m> {
|
2020-11-10 07:10:23 -05:00
|
|
|
#[serde(flatten)]
|
2020-11-11 13:19:22 -05:00
|
|
|
pub context: Option<Context<'m>>,
|
2019-10-30 09:26:59 -04:00
|
|
|
pub kind: ParseKind,
|
2020-12-30 19:58:35 -05:00
|
|
|
pub data: &'m str,
|
2019-10-30 09:26:59 -04:00
|
|
|
}
|
|
|
|
|
2020-03-24 07:11:31 -04:00
|
|
|
impl<'m> Default for Parse<'m> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-11-11 13:19:22 -05:00
|
|
|
context: None,
|
2020-03-24 07:11:31 -04:00
|
|
|
kind: ParseKind::Identifier,
|
2020-12-30 19:58:35 -05:00
|
|
|
data: "",
|
2020-03-24 07:11:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize, derive_setters::Setters)]
|
|
|
|
#[non_exhaustive]
|
2020-11-23 12:20:12 -05:00
|
|
|
pub struct Error<'m> {
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub context: Option<Context<'m>>,
|
2019-10-26 22:31:10 -04:00
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:20:12 -05:00
|
|
|
impl<'m> Error<'m> {
|
2019-10-26 22:31:10 -04:00
|
|
|
pub fn new(msg: String) -> Self {
|
2020-11-23 12:20:12 -05:00
|
|
|
Self { context: None, msg }
|
2020-03-24 07:11:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-23 12:20:12 -05:00
|
|
|
impl<'m> Default for Error<'m> {
|
2020-03-24 07:11:31 -04:00
|
|
|
fn default() -> Self {
|
2020-11-23 12:20:12 -05:00
|
|
|
Self {
|
|
|
|
context: None,
|
|
|
|
msg: "".to_owned(),
|
|
|
|
}
|
2019-10-26 22:31:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 19:21:29 -04:00
|
|
|
pub trait Report: Send + Sync {
|
2020-11-16 21:02:10 -05:00
|
|
|
fn report(&self, msg: Message) -> Result<(), std::io::Error>;
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2019-01-24 10:24:20 -05:00
|
|
|
|
2020-11-16 21:02:10 -05:00
|
|
|
pub struct MessageStatus<'r> {
|
|
|
|
typos_found: atomic::AtomicBool,
|
|
|
|
errors_found: atomic::AtomicBool,
|
|
|
|
reporter: &'r dyn Report,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'r> MessageStatus<'r> {
|
|
|
|
pub fn new(reporter: &'r dyn Report) -> Self {
|
|
|
|
Self {
|
|
|
|
typos_found: atomic::AtomicBool::new(false),
|
|
|
|
errors_found: atomic::AtomicBool::new(false),
|
|
|
|
reporter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn typos_found(&self) -> bool {
|
|
|
|
self.typos_found.load(atomic::Ordering::Relaxed)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn errors_found(&self) -> bool {
|
|
|
|
self.errors_found.load(atomic::Ordering::Relaxed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'r> Report for MessageStatus<'r> {
|
|
|
|
fn report(&self, msg: Message) -> Result<(), std::io::Error> {
|
2021-01-02 14:17:15 -05:00
|
|
|
let _ = self.typos_found.compare_exchange(
|
|
|
|
false,
|
|
|
|
msg.is_correction(),
|
|
|
|
atomic::Ordering::Relaxed,
|
|
|
|
atomic::Ordering::Relaxed,
|
|
|
|
);
|
|
|
|
let _ = self
|
|
|
|
.errors_found
|
|
|
|
.compare_exchange(
|
|
|
|
false,
|
|
|
|
msg.is_error(),
|
|
|
|
atomic::Ordering::Relaxed,
|
|
|
|
atomic::Ordering::Relaxed,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2020-11-16 21:02:10 -05:00
|
|
|
self.reporter.report(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
2020-03-23 19:21:29 -04:00
|
|
|
pub struct PrintSilent;
|
2019-01-24 10:24:20 -05:00
|
|
|
|
2020-03-23 19:21:29 -04:00
|
|
|
impl Report for PrintSilent {
|
2020-11-16 21:02:10 -05:00
|
|
|
fn report(&self, _msg: Message) -> Result<(), std::io::Error> {
|
|
|
|
Ok(())
|
2020-06-30 22:08:38 -04:00
|
|
|
}
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
|
|
|
|
2020-03-23 21:27:37 -04:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2020-03-23 19:21:29 -04:00
|
|
|
pub struct PrintBrief;
|
|
|
|
|
|
|
|
impl Report for PrintBrief {
|
2020-11-16 21:02:10 -05:00
|
|
|
fn report(&self, msg: Message) -> Result<(), std::io::Error> {
|
2020-06-30 22:08:38 -04:00
|
|
|
match &msg {
|
2020-03-23 19:21:29 -04:00
|
|
|
Message::BinaryFile(msg) => {
|
2020-04-02 19:14:24 -04:00
|
|
|
log::info!("{}", msg);
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
Message::Typo(msg) => print_brief_correction(msg)?,
|
2020-03-23 19:21:29 -04:00
|
|
|
Message::File(msg) => {
|
2020-11-16 21:02:10 -05:00
|
|
|
writeln!(io::stdout(), "{}", msg.path.display())?;
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
|
|
|
Message::Parse(msg) => {
|
2020-12-30 19:58:35 -05:00
|
|
|
writeln!(io::stdout(), "{}", msg.data)?;
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
|
|
|
Message::Error(msg) => {
|
2020-11-23 12:20:12 -05:00
|
|
|
log::error!("{}: {}", context_display(&msg.context), msg.msg);
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2019-10-30 09:26:59 -04:00
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
Ok(())
|
2019-07-16 21:16:54 -04:00
|
|
|
}
|
2019-01-24 10:24:20 -05:00
|
|
|
}
|
|
|
|
|
2020-03-23 21:27:37 -04:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2020-03-23 19:21:29 -04:00
|
|
|
pub struct PrintLong;
|
|
|
|
|
|
|
|
impl Report for PrintLong {
|
2020-11-16 21:02:10 -05:00
|
|
|
fn report(&self, msg: Message) -> Result<(), std::io::Error> {
|
2020-06-30 22:08:38 -04:00
|
|
|
match &msg {
|
2020-03-23 19:21:29 -04:00
|
|
|
Message::BinaryFile(msg) => {
|
2020-04-02 19:14:24 -04:00
|
|
|
log::info!("{}", msg);
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
Message::Typo(msg) => print_long_correction(msg)?,
|
2020-03-23 19:21:29 -04:00
|
|
|
Message::File(msg) => {
|
2020-11-16 21:02:10 -05:00
|
|
|
writeln!(io::stdout(), "{}", msg.path.display())?;
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
|
|
|
Message::Parse(msg) => {
|
2020-12-30 19:58:35 -05:00
|
|
|
writeln!(io::stdout(), "{}", msg.data)?;
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
|
|
|
Message::Error(msg) => {
|
2020-11-23 12:20:12 -05:00
|
|
|
log::error!("{}: {}", context_display(&msg.context), msg.msg);
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2019-10-30 09:26:59 -04:00
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
Ok(())
|
2019-07-16 21:16:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 21:02:10 -05:00
|
|
|
fn print_brief_correction(msg: &Typo) -> Result<(), std::io::Error> {
|
2020-11-24 19:52:19 -05:00
|
|
|
let line = String::from_utf8_lossy(msg.buffer.as_ref());
|
|
|
|
let line = line.replace("\t", " ");
|
|
|
|
let column = unicode_segmentation::UnicodeSegmentation::graphemes(
|
|
|
|
line.get(0..msg.byte_offset).unwrap(),
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
.count();
|
2020-11-04 22:14:59 -05:00
|
|
|
match &msg.corrections {
|
2020-12-30 20:41:08 -05:00
|
|
|
typos::Status::Valid => {}
|
|
|
|
typos::Status::Invalid => {
|
2020-11-16 21:02:10 -05:00
|
|
|
writeln!(
|
|
|
|
io::stdout(),
|
2020-11-24 19:52:19 -05:00
|
|
|
"{}:{}: `{}` is disallowed",
|
2020-11-11 13:19:22 -05:00
|
|
|
context_display(&msg.context),
|
2020-11-24 19:52:19 -05:00
|
|
|
column,
|
2020-11-11 13:19:22 -05:00
|
|
|
msg.typo,
|
2020-11-16 21:02:10 -05:00
|
|
|
)?;
|
2020-11-04 22:14:59 -05:00
|
|
|
}
|
2020-12-30 20:41:08 -05:00
|
|
|
typos::Status::Corrections(corrections) => {
|
2020-11-16 21:02:10 -05:00
|
|
|
writeln!(
|
|
|
|
io::stdout(),
|
2020-11-24 19:52:19 -05:00
|
|
|
"{}:{}: `{}` -> {}",
|
2020-11-11 13:19:22 -05:00
|
|
|
context_display(&msg.context),
|
2020-11-24 19:52:19 -05:00
|
|
|
column,
|
2020-11-04 22:14:59 -05:00
|
|
|
msg.typo,
|
2020-11-24 19:52:19 -05:00
|
|
|
itertools::join(corrections.iter().map(|s| format!("`{}`", s)), ", ")
|
2020-11-16 21:02:10 -05:00
|
|
|
)?;
|
2020-11-04 22:14:59 -05:00
|
|
|
}
|
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
|
|
|
|
Ok(())
|
2020-11-04 22:14:59 -05:00
|
|
|
}
|
2019-06-22 11:18:03 -04:00
|
|
|
|
2020-11-16 21:02:10 -05:00
|
|
|
fn print_long_correction(msg: &Typo) -> Result<(), std::io::Error> {
|
2019-06-22 11:12:54 -04:00
|
|
|
let stdout = io::stdout();
|
|
|
|
let mut handle = stdout.lock();
|
2020-11-24 19:52:19 -05:00
|
|
|
|
|
|
|
let line = String::from_utf8_lossy(msg.buffer.as_ref());
|
|
|
|
let line = line.replace("\t", " ");
|
|
|
|
let column = unicode_segmentation::UnicodeSegmentation::graphemes(
|
|
|
|
line.get(0..msg.byte_offset).unwrap(),
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
.count();
|
2020-10-24 22:17:16 -04:00
|
|
|
match &msg.corrections {
|
2020-12-30 20:41:08 -05:00
|
|
|
typos::Status::Valid => {}
|
|
|
|
typos::Status::Invalid => {
|
2020-11-24 19:52:19 -05:00
|
|
|
writeln!(handle, "error: `{}` is disallowed`", msg.typo,)?;
|
2020-10-24 22:17:16 -04:00
|
|
|
}
|
2020-12-30 20:41:08 -05:00
|
|
|
typos::Status::Corrections(corrections) => {
|
2020-10-24 22:17:16 -04:00
|
|
|
writeln!(
|
|
|
|
handle,
|
|
|
|
"error: `{}` should be {}",
|
|
|
|
msg.typo,
|
2020-11-24 19:52:19 -05:00
|
|
|
itertools::join(corrections.iter().map(|s| format!("`{}`", s)), ", ")
|
2020-11-16 21:02:10 -05:00
|
|
|
)?;
|
2020-10-24 22:17:16 -04:00
|
|
|
}
|
|
|
|
}
|
2020-11-24 19:52:19 -05:00
|
|
|
writeln!(handle, " --> {}:{}", context_display(&msg.context), column)?;
|
2020-11-11 13:19:22 -05:00
|
|
|
|
|
|
|
if let Some(Context::File(context)) = &msg.context {
|
2020-11-04 22:14:59 -05:00
|
|
|
let line_num = context.line_num.to_string();
|
|
|
|
let line_indent: String = itertools::repeat_n(" ", line_num.len()).collect();
|
|
|
|
|
2020-11-24 19:52:19 -05:00
|
|
|
let hl_indent: String = itertools::repeat_n(" ", column).collect();
|
2020-11-04 22:14:59 -05:00
|
|
|
let hl: String = itertools::repeat_n("^", msg.typo.len()).collect();
|
|
|
|
|
2020-11-16 21:02:10 -05:00
|
|
|
writeln!(handle, "{} |", line_indent)?;
|
|
|
|
writeln!(handle, "{} | {}", line_num, line.trim_end())?;
|
|
|
|
writeln!(handle, "{} | {}{}", line_indent, hl_indent, hl)?;
|
|
|
|
writeln!(handle, "{} |", line_indent)?;
|
2020-11-04 22:14:59 -05:00
|
|
|
}
|
2020-11-16 21:02:10 -05:00
|
|
|
|
|
|
|
Ok(())
|
2019-01-24 10:24:20 -05:00
|
|
|
}
|
|
|
|
|
2020-11-11 13:19:22 -05:00
|
|
|
fn context_display<'c>(context: &'c Option<Context<'c>>) -> &'c dyn std::fmt::Display {
|
|
|
|
context
|
|
|
|
.as_ref()
|
|
|
|
.map(|c| c as &dyn std::fmt::Display)
|
|
|
|
.unwrap_or(&"")
|
|
|
|
}
|
|
|
|
|
2020-03-23 21:27:37 -04:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2020-03-23 19:21:29 -04:00
|
|
|
pub struct PrintJson;
|
|
|
|
|
|
|
|
impl Report for PrintJson {
|
2020-11-16 21:02:10 -05:00
|
|
|
fn report(&self, msg: Message) -> Result<(), std::io::Error> {
|
|
|
|
writeln!(io::stdout(), "{}", serde_json::to_string(&msg).unwrap())?;
|
|
|
|
Ok(())
|
2020-03-23 19:21:29 -04:00
|
|
|
}
|
2019-01-24 10:24:20 -05:00
|
|
|
}
|