Skip to content

Commit

Permalink
Don't underline inherited references
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Sep 14, 2024
1 parent 341118c commit d74eb74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
48 changes: 28 additions & 20 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,38 @@ use std::fmt::{Debug, Display, Write};

use crate::*;

use colored::Colorize;
#[cfg(target_arch = "wasm32")]
mod colored {
pub trait Colorize {
fn dimmed(&self) -> String;
fn underline(&self) -> String;
}
impl Colorize for &str {
fn dimmed(&self) -> String {
pub trait Style {
fn dimmed(&self) -> String;
fn tooltip(&self, text: &str) -> String;
}

impl Style for &str {
fn dimmed(&self) -> String {
if cfg!(target_arch = "wasm32") {
format!("<span style=\"color: gray\">{self}</span>")
}
fn underline(&self) -> String {
format!("<span style=\"text-decoration: underline\" title=\"inherited reference\">{self}</span>")
} else {
use colored::Colorize;
<Self as Colorize>::dimmed(self).to_string()
}
}
impl Colorize for String {
fn dimmed(&self) -> String {
self.as_str().dimmed()
}
fn underline(&self) -> String {
self.as_str().underline()
fn tooltip(&self, text: &str) -> String {
if cfg!(target_arch = "wasm32") {
format!("<span title=\"{text}\">{self}</span>")
} else {
self.to_string()
}
}
}

impl Style for String {
fn dimmed(&self) -> String {
self.as_str().dimmed()
}
fn tooltip(&self, text: &str) -> String {
self.as_str().tooltip(text)
}
}

impl BindingMode {
pub fn name(self) -> &'static str {
match self {
Expand Down Expand Up @@ -60,9 +67,10 @@ impl<'a> TypingPredicate<'a> {
let bm = match self.expr.binding_mode().ok() {
Some(BindingMode::ByRef(_)) => {
if let Some(rest) = ty.strip_prefix("&mut") {
ty = format!("{}{rest}", "&mut".dimmed().underline());
ty =
format!("{}{rest}", "&mut".dimmed().tooltip("inherited reference"));
} else if let Some(rest) = ty.strip_prefix("&") {
ty = format!("{}{rest}", "&".dimmed().underline());
ty = format!("{}{rest}", "&".dimmed().tooltip("inherited reference"));
}
&"inh".dimmed().to_string()
}
Expand Down
1 change: 0 additions & 1 deletion web/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ const base = import.meta.env.BASE_URL === "/" ? "" : import.meta.env.BASE_URL;
}
.inherited-ref {
color: gray;
text-decoration: underline;
}
</style>

0 comments on commit d74eb74

Please sign in to comment.