#![doc = include_str!("../readme.md")] #![warn(missing_docs)] mod display; mod draw; mod style; mod write; mod characters; mod windows; use crate::{characters::Draw, display::*}; pub use crate::{ characters::{BuiltinDrawer, DrawElements}, draw::{Console, Palette}, style::{color::Color, paint::Paint, style::Style}, windows::enable_ansi_color, }; use core::{ cmp::{Eq, PartialEq}, fmt::{Debug, Display, Formatter}, hash::Hash, }; pub use source_cache::{SourceCache, SourceID, SourceSpan}; use std::io::Write; use unicode_width::UnicodeWidthChar; /// A type that represents a labelled section of identifier code. #[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct Label { span: SourceSpan, msg: Option, color: Option, order: i32, priority: i32, } impl Label { /// Create a new [`Label`]. pub fn new(span: SourceSpan) -> Self { Self { span, msg: None, color: None, order: 0, priority: 0 } } /// Give this label a message. pub fn with_message(mut self, msg: M) -> Self { self.msg = Some(msg.to_string()); self } /// Give this label a highlight colour. pub fn with_color(mut self, color: Color) -> Self { self.color = Some(color); self } /// Specify the order of this label relative to other labels. /// /// Lower values correspond to this label having an earlier order. /// /// If unspecified, labels default to an order of `0`. /// /// When labels are displayed after a line the crate needs to decide which labels should be displayed first. By /// Default, the orders labels based on where their associated line meets the text (see [`LabelAttach`]). /// Additionally, multi-line labels are ordered before inline labels. You can use this function to override this /// behaviour. pub fn with_order(mut self, order: i32) -> Self { self.order = order; self } /// Specify the priority of this label relative to other labels. /// /// Higher values correspond to this label having a higher priority. /// /// If unspecified, labels default to a priority of `0`. /// /// Label spans can overlap. When this happens, the crate needs to decide which labels to prioritise for various /// purposes such as highlighting. By default, spans with a smaller length get a higher priority. You can use this /// function to override this behaviour. pub fn with_priority(mut self, priority: i32) -> Self { self.priority = priority; self } } /// A type representing a diagnostic that is ready to be written to output. pub struct Diagnostic { kind: Box, code: Option, message: String, note: Option, help: Option, file: SourceID, location: Option, labels: Vec