-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
876975e
commit 1558121
Showing
6 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use thiserror::Error; | ||
|
||
|
||
#[derive(Error, Debug)] | ||
pub enum CodeScreenshotError { | ||
#[error("The range is invalid")] | ||
InvalidRange, | ||
#[error("The expected format for {0} is {1}")] | ||
InvalidFormat(&'static str, &'static str), | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
use cli::get_args; | ||
use syntect::easy::HighlightLines; | ||
use syntect::highlighting::{ScopeSelectors, Style, Theme, ThemeItem, ThemeSet}; | ||
use syntect::highlighting::{Style, ThemeSet}; | ||
use syntect::parsing::SyntaxSet; | ||
use syntect::util::{as_24_bit_terminal_escaped, LinesWithEndings}; | ||
use theme::load_themes; | ||
|
||
mod cli; | ||
mod error; | ||
mod highlight; | ||
mod theme; | ||
|
||
fn main() { | ||
let args = get_args(); | ||
load_themes(); | ||
// Load these once at the start of your program | ||
let ps = SyntaxSet::load_defaults_newlines(); | ||
let themes = ThemeSet::default(); | ||
|
||
let syntax = ps.find_syntax_by_extension("rs").unwrap(); | ||
let mut h = HighlightLines::new(syntax, &theme); | ||
let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}"; | ||
for line in LinesWithEndings::from(s) { | ||
let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps).unwrap(); | ||
ranges.iter().for_each(|(style, content)| { | ||
println!("Style: {style:?}\nContent: '{content}'"); | ||
// let escaped = as_24_bit_terminal_escaped(&ranges[..], true); | ||
// print!("{}", escaped); | ||
}); | ||
} | ||
// let themes = ThemeSet::default(); | ||
// | ||
// let syntax = ps.find_syntax_by_extension("rs").unwrap(); | ||
// let mut h = HighlightLines::new(syntax, &theme); | ||
// let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}"; | ||
// for line in LinesWithEndings::from(s) { | ||
// let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps).unwrap(); | ||
// ranges.iter().for_each(|(style, content)| { | ||
// println!("Style: {style:?}\nContent: '{content}'"); | ||
// // let escaped = as_24_bit_terminal_escaped(&ranges[..], true); | ||
// // print!("{}", escaped); | ||
// }); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::fs::{self, read_dir}; | ||
use std::path::PathBuf; | ||
|
||
use lewp_css::domain::{CssRuleType, StyleRule}; | ||
use lewp_css::Stylesheet; | ||
use syntect::highlighting::{Theme, ThemeSet, ThemeSettings}; | ||
|
||
fn load_from_css(file: &PathBuf) -> (String, Theme) { | ||
let file_name = file.file_name().unwrap().to_str().unwrap().to_string(); | ||
let file_name = file_name.split(".").next().unwrap().to_string(); | ||
let content = fs::read_to_string(file).unwrap(); | ||
let style = Stylesheet::parse(&content).unwrap(); | ||
let style = style.rules.0.iter(); | ||
let theme = Theme { | ||
name: Some(file_name.clone()), | ||
author: None, | ||
settings: ThemeSettings { | ||
foreground: style.find_map(|s| { | ||
if let CssRuleType::Style(StyleRule {selectors, property_declarations}) = s.rule_type() { | ||
} else { | ||
None | ||
} | ||
}), | ||
background: todo!(), | ||
caret: todo!(), | ||
line_highlight: todo!(), | ||
misspelling: todo!(), | ||
minimap_border: todo!(), | ||
accent: todo!(), | ||
popup_css: todo!(), | ||
phantom_css: todo!(), | ||
bracket_contents_foreground: todo!(), | ||
bracket_contents_options: todo!(), | ||
brackets_foreground: todo!(), | ||
brackets_background: todo!(), | ||
brackets_options: todo!(), | ||
tags_foreground: todo!(), | ||
tags_options: todo!(), | ||
highlight: todo!(), | ||
find_highlight: todo!(), | ||
find_highlight_foreground: todo!(), | ||
gutter: todo!(), | ||
gutter_foreground: todo!(), | ||
selection: todo!(), | ||
selection_foreground: todo!(), | ||
selection_border: todo!(), | ||
inactive_selection: todo!(), | ||
inactive_selection_foreground: todo!(), | ||
guide: todo!(), | ||
active_guide: todo!(), | ||
stack_guide: todo!(), | ||
shadow: todo!(), | ||
}, | ||
scopes: todo!(), | ||
}; | ||
|
||
(file_name, theme) | ||
} | ||
|
||
pub fn load_themes() { | ||
let mut themes = ThemeSet::load_defaults(); | ||
// themes.add_from_folder("./assets").unwrap_or_default(); | ||
|
||
let dir_content = read_dir("./assets").unwrap(); | ||
|
||
for file in dir_content { | ||
let Ok(file) = file else { | ||
continue; | ||
}; | ||
let (theme_name, theme) = load_from_css(&file.path()); | ||
themes.themes.insert(theme_name, theme); | ||
} | ||
|
||
syntect::dumps::dump_to_file(&themes, "./assets/themes.themedump").unwrap(); | ||
} |