fork of https://github.com/tree-sitter/tree-sitter-graph

Merge pull request #153 from tree-sitter/term-colors

authored by Hendrik van Antwerpen and committed by GitHub 68504d72 14484897

Changed files
+25 -17
src
+8
CHANGELOG.md
··· 5 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 6 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 7 8 + ## v0.11.3 -- 2024-05-29 9 + 10 + ### Library 11 + 12 + #### Fixed 13 + 14 + - Excerpts shown as part of errors now use formatting that works both in light and dark mode. 15 + 8 16 ## v0.11.2 -- 2024-03-08 9 17 10 18 ### DSL
+1 -1
Cargo.toml
··· 1 1 [package] 2 2 name = "tree-sitter-graph" 3 - version = "0.11.2" 3 + version = "0.11.3" 4 4 description = "Construct graphs from parsed source code" 5 5 homepage = "https://github.com/tree-sitter/tree-sitter-graph/" 6 6 repository = "https://github.com/tree-sitter/tree-sitter-graph/"
+16 -16
src/parse_error.rs
··· 396 396 f, 397 397 "{}{}:{}:{}:", 398 398 " ".repeat(self.indent), 399 - white_bold(&self.path.to_string_lossy()), 400 - white_bold(&format!("{}", self.row + 1)), 401 - white_bold(&format!("{}", self.columns.start + 1)), 399 + header_style(&self.path.to_string_lossy()), 400 + header_style(&format!("{}", self.row + 1)), 401 + header_style(&format!("{}", self.columns.start + 1)), 402 402 )?; 403 403 if let Some(source) = self.source { 404 404 // first line: line number & source ··· 406 406 f, 407 407 "{}{}{}{}", 408 408 " ".repeat(self.indent), 409 - blue(&format!("{}", self.row + 1)), 410 - blue(" | "), 409 + prefix_style(&format!("{}", self.row + 1)), 410 + prefix_style(" | "), 411 411 source, 412 412 )?; 413 413 // second line: caret ··· 416 416 "{}{}{}{}{}", 417 417 " ".repeat(self.indent), 418 418 " ".repeat(self.gutter_width()), 419 - blue(" | "), 419 + prefix_style(" | "), 420 420 " ".repeat(self.columns.start), 421 - green_bold(&"^".repeat(self.columns.len())) 421 + underline_style(&"^".repeat(self.columns.len())), 422 422 )?; 423 423 } else { 424 424 writeln!(f, "{}{}", " ".repeat(self.indent), "<missing source>",)?; ··· 430 430 // coloring functions 431 431 432 432 #[cfg(feature = "term-colors")] 433 - fn blue(str: &str) -> impl std::fmt::Display { 434 - str.blue() 433 + fn header_style(str: &str) -> impl std::fmt::Display { 434 + str.bold() 435 435 } 436 436 #[cfg(not(feature = "term-colors"))] 437 - fn blue<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 437 + fn header_style<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 438 438 str 439 439 } 440 440 441 441 #[cfg(feature = "term-colors")] 442 - fn green_bold(str: &str) -> impl std::fmt::Display { 443 - str.green().bold() 442 + fn prefix_style(str: &str) -> impl std::fmt::Display { 443 + str.dimmed() 444 444 } 445 445 #[cfg(not(feature = "term-colors"))] 446 - fn green_bold<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 446 + fn prefix_style<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 447 447 str 448 448 } 449 449 450 450 #[cfg(feature = "term-colors")] 451 - fn white_bold(str: &str) -> impl std::fmt::Display { 452 - str.white().bold() 451 + fn underline_style(str: &str) -> impl std::fmt::Display { 452 + str.green() 453 453 } 454 454 #[cfg(not(feature = "term-colors"))] 455 - fn white_bold<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 455 + fn underline_style<'a>(str: &'a str) -> impl std::fmt::Display + 'a { 456 456 str 457 457 }