use crate::{DocumentTree, PrettyPrint};
use alloc::borrow::Cow;
use core::fmt::{Debug, Formatter};
use termcolor::{Color, ColorSpec};
pub struct PrettyProvider {
keyword: ColorSpec,
string: ColorSpec,
number: ColorSpec,
macros: ColorSpec,
argument: ColorSpec,
argument_mut: ColorSpec,
local: ColorSpec,
local_mut: ColorSpec,
operator: ColorSpec,
structure: ColorSpec,
interface: ColorSpec,
}
impl<'a> Debug for PrettyProvider {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("PrettyProvider").finish()
}
}
impl PrettyProvider {
pub fn new() -> Self {
let argument = Color::Rgb(239, 112, 117);
let purple = Color::Rgb(197, 119, 207);
let local = Color::Rgb(152, 195, 121);
let green = Color::Rgb(152, 195, 121);
PrettyProvider {
keyword: ColorSpec::new().set_fg(Some(purple)).clone(),
string: ColorSpec::new().set_fg(Some(green)).clone(),
number: ColorSpec::new().set_fg(Some(Color::Rgb(206, 153, 100))).clone(),
macros: ColorSpec::new().set_fg(Some(Color::Rgb(87, 182, 194))).clone(),
argument: ColorSpec::new().set_fg(Some(argument)).clone(),
argument_mut: ColorSpec::new().set_fg(Some(argument)).set_underline(true).clone(),
local: ColorSpec::new().set_fg(Some(local)).clone(),
local_mut: ColorSpec::new().set_fg(Some(local)).set_underline(true).clone(),
operator: ColorSpec::new().set_fg(Some(Color::Rgb(90, 173, 238))).clone(),
structure: ColorSpec::new().set_fg(Some(Color::Rgb(197, 119, 207))).clone(),
interface: ColorSpec::new().set_fg(Some(Color::Rgb(197, 119, 207))).clone(),
}
}
}
impl<'a> PrettyProvider {
pub fn text<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
todo!()
}
pub fn keyword<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.keyword.clone())
}
pub fn identifier<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.operator(text)
}
pub fn generic<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.macros.clone())
}
pub fn variable<'i, S>(&'a self, text: S, mutable: bool) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
if mutable { self.text(text).annotate(self.local_mut.clone()) } else { self.text(text).annotate(self.local.clone()) }
}
pub fn argument<'i, S>(&'a self, text: S, mutable: bool) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
if mutable {
self.text(text).annotate(self.argument_mut.clone())
}
else {
self.text(text).annotate(self.argument.clone())
}
}
pub fn operator<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.operator.clone())
}
pub fn string<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.string.clone())
}
pub fn metadata<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.macros.clone())
}
pub fn number<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.number.clone())
}
pub fn structure<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.structure.clone())
}
pub fn interface<'i, S>(&'a self, text: S) -> DocumentTree
where
S: Into<Cow<'i, str>>,
'i: 'a,
{
self.text(text).annotate(self.interface.clone())
}
}
impl<'a> PrettyProvider {
#[inline]
pub fn concat<I>(&'a self, docs: I) -> DocumentTree {
todo!()
}
#[inline]
pub fn intersperse<T, S>(&'a self, terms: &[T], joint: S) -> DocumentTree
where
T: PrettyPrint,
{
todo!()
}
#[inline]
pub fn join<T>(&'a self, terms: &[T], joint: &'static str) -> DocumentTree
where
T: PrettyPrint,
{
todo!()
}
}