Skip to content

Commit

Permalink
Prepare cursive-syntect 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Aug 2, 2024
1 parent 15c06fb commit 1d83c2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cursive-syntect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include = ["src/lib.rs", "LICENSE", "README.md"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cursive_core = { path = "../cursive-core", version= "0.3.5"}
cursive_core = { path = "../cursive-core", version= "0.4.0"}
unicode-width = "0.1.9"

[dependencies.syntect]
Expand Down
20 changes: 10 additions & 10 deletions cursive-syntect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
//! [`syntect`]: https://docs.rs/syntect
#![deny(missing_docs)]

use cursive_core::theme;
use cursive_core::style;
use cursive_core::utils::markup::{StyledIndexedSpan, StyledString};
use cursive_core::utils::span::IndexedCow;

use unicode_width::UnicodeWidthStr;

/// Translate a syntect font style into a set of cursive effects.
pub fn translate_effects(font_style: syntect::highlighting::FontStyle) -> theme::Effects {
let mut effects = theme::Effects::empty();
pub fn translate_effects(font_style: syntect::highlighting::FontStyle) -> style::Effects {
let mut effects = style::Effects::empty();

for &(style, effect) in &[
(syntect::highlighting::FontStyle::BOLD, theme::Effect::Bold),
(syntect::highlighting::FontStyle::BOLD, style::Effect::Bold),
(
syntect::highlighting::FontStyle::UNDERLINE,
theme::Effect::Underline,
style::Effect::Underline,
),
(
syntect::highlighting::FontStyle::ITALIC,
theme::Effect::Italic,
style::Effect::Italic,
),
] {
if font_style.contains(style) {
Expand All @@ -36,16 +36,16 @@ pub fn translate_effects(font_style: syntect::highlighting::FontStyle) -> theme:
}

/// Translate a syntect color into a cursive color.
pub fn translate_color(color: syntect::highlighting::Color) -> theme::Color {
theme::Color::Rgb(color.r, color.g, color.b)
pub fn translate_color(color: syntect::highlighting::Color) -> style::Color {
style::Color::Rgb(color.r, color.g, color.b)
}

/// Translate a syntect style into a cursive style.
pub fn translate_style(style: syntect::highlighting::Style) -> theme::Style {
pub fn translate_style(style: syntect::highlighting::Style) -> style::Style {
let front = translate_color(style.foreground);
let back = translate_color(style.background);

theme::Style {
style::Style {
color: (front, back).into(),
effects: translate_effects(style.font_style),
}
Expand Down

0 comments on commit 1d83c2e

Please sign in to comment.