summaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/Cargo.toml3
-rw-r--r--helix-term/src/editor.rs41
-rw-r--r--helix-term/src/theme.rs37
-rw-r--r--helix-term/test.txt3
4 files changed, 41 insertions, 43 deletions
diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml
index ce3add5c..b7a58e3e 100644
--- a/helix-term/Cargo.toml
+++ b/helix-term/Cargo.toml
@@ -11,9 +11,6 @@ name = "hx"
path = "src/main.rs"
[dependencies]
-# termwiz = { git = "https://github.com/wez/wezterm", features = ["widgets"] }
-# termwiz = { path = "../../wezterm/termwiz", default-features = false, features = ["widgets"] }
-
helix-syntax = { path = "../helix-syntax" }
anyhow = "1"
diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs
index af18842d..0c58ac9b 100644
--- a/helix-term/src/editor.rs
+++ b/helix-term/src/editor.rs
@@ -1,6 +1,6 @@
use crate::{keymap, theme::Theme, Args};
use helix_core::{
- language_mode::{HighlightConfiguration, HighlightEvent, Highlighter},
+ syntax::{HighlightConfiguration, HighlightEvent, Highlighter},
state::coords_at_pos,
state::Mode,
State,
@@ -40,7 +40,6 @@ pub struct Editor {
theme: Theme,
highlighter: Highlighter,
highlight_config: HighlightConfiguration,
- highlight_names: Vec<String>,
}
impl Editor {
@@ -51,36 +50,7 @@ impl Editor {
let size = terminal::size().unwrap();
let area = Rect::new(0, 0, size.0, size.1);
- let highlight_names: Vec<String> = [
- "attribute",
- "constant.builtin",
- "constant",
- "function.builtin",
- "function.macro",
- "function",
- "keyword",
- "operator",
- "property",
- "punctuation",
- "comment",
- "escape",
- "label",
- // "punctuation.bracket",
- "punctuation.delimiter",
- "string",
- "string.special",
- "tag",
- "type",
- "type.builtin",
- "constructor",
- "variable",
- "variable.builtin",
- "variable.parameter",
- "path",
- ]
- .iter()
- .map(|s| s.to_string())
- .collect();
+ let theme = Theme::default();
// let mut parser = tree_sitter::Parser::new();
// parser.set_language(language).unwrap();
@@ -104,7 +74,7 @@ impl Editor {
)
.unwrap();
- highlight_config.configure(&highlight_names);
+ highlight_config.configure(theme.scopes());
let mut editor = Editor {
terminal,
@@ -112,11 +82,10 @@ impl Editor {
first_line: 0,
size,
surface: Surface::empty(area),
- theme: Theme::default(),
+ theme,
// TODO; move to state
highlighter,
highlight_config,
- highlight_names,
};
if let Some(file) = args.files.pop() {
@@ -178,7 +147,7 @@ impl Editor {
use tui::style::Color;
let style = match spans.first() {
- Some(span) => self.theme.get(self.highlight_names[span.0].as_str()),
+ Some(span) => self.theme.get(self.theme.scopes()[span.0].as_str()),
None => Style::default().fg(Color::Rgb(164, 160, 232)), // lavender
};
diff --git a/helix-term/src/theme.rs b/helix-term/src/theme.rs
index 0353f0e6..5b6eb7de 100644
--- a/helix-term/src/theme.rs
+++ b/helix-term/src/theme.rs
@@ -3,9 +3,38 @@ use tui::style::{Color, Style};
/// Color theme for syntax highlighting.
pub struct Theme {
+ scopes: Vec<String>,
mapping: HashMap<&'static str, Style>,
}
+// let highlight_names: Vec<String> = [
+// "attribute",
+// "constant.builtin",
+// "constant",
+// "function.builtin",
+// "function.macro",
+// "function",
+// "keyword",
+// "operator",
+// "property",
+// "punctuation",
+// "comment",
+// "escape",
+// "label",
+// // "punctuation.bracket",
+// "punctuation.delimiter",
+// "string",
+// "string.special",
+// "tag",
+// "type",
+// "type.builtin",
+// "constructor",
+// "variable",
+// "variable.builtin",
+// "variable.parameter",
+// "path",
+// ];
+
impl Default for Theme {
fn default() -> Self {
let mapping = hashmap! {
@@ -45,7 +74,9 @@ impl Default for Theme {
"function.builtin" => Style::default().fg(Color::Rgb(255, 0, 0)), // white
};
- Self { mapping }
+ let scopes = mapping.keys().map(ToString::to_string).collect();
+
+ Self { mapping, scopes }
}
}
@@ -56,4 +87,8 @@ impl Theme {
.copied()
.unwrap_or_else(|| Style::default().fg(Color::Rgb(0, 0, 255)))
}
+
+ pub fn scopes(&self) -> &[String] {
+ &self.scopes
+ }
}
diff --git a/helix-term/test.txt b/helix-term/test.txt
deleted file mode 100644
index 1802a747..00000000
--- a/helix-term/test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-aaa
-bbb
-ccc