summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2025-12-07 21:23:43 -0500
committerMica White <botahamec@outlook.com>2025-12-07 21:23:43 -0500
commitc04c581fdeb0e42c5e41bb372b827a5b3ac033fb (patch)
tree120fe9484fe57c757ad123d52cdd4e316097dcbd /src/main.rs
parentbe691f0a1af3e7c2226eefabea9f3e656472fe32 (diff)
First program
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..596c073 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,36 @@
+use std::io::Read;
+use std::path::{Path, PathBuf};
+
+use syntect::highlighting::ThemeSet;
+use syntect::html::{
+ css_for_theme_with_class_style, highlighted_html_for_string, line_tokens_to_classed_spans,
+ ClassStyle,
+};
+use syntect::parsing::{ScopeStack, SyntaxSet};
+
+const CLASS_STYLE: ClassStyle = ClassStyle::Spaced;
+
fn main() {
- println!("Hello, world!");
+ let syntax_set = SyntaxSet::load_defaults_newlines();
+ let theme_set = ThemeSet::load_defaults();
+ let theme = &theme_set.themes["base16-ocean.dark"];
+
+ let filename = std::env::args().nth(1).map(PathBuf::from);
+ let extension = filename
+ .as_ref()
+ .and_then(|p| p.extension())
+ .and_then(|s| s.to_str());
+ let syntax = extension.and_then(|extension| syntax_set.find_syntax_by_extension(extension));
+
+ let mut file = String::new();
+ let _ = std::io::stdin().read_to_string(&mut file);
+
+ let Some(syntax) = syntax else {
+ print!("{file}");
+ return;
+ };
+
+ let highlighted_file =
+ highlighted_html_for_string(&file, &syntax_set, syntax, theme).unwrap_or(file);
+ println!("{highlighted_file}");
}