aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-12 08:44:57 +0000
committerBlaž Hrastnik2020-09-12 08:44:57 +0000
commita106be94f140918fa392bea660a87197b66390f0 (patch)
treefbe621a69913f1e1115893a531f85bd3313eff9f /helix-term/src
parentb17a77b8b84b1dfdbc1615a652e9718d847ea0de (diff)
Refactor a little bit.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/editor.rs41
-rw-r--r--helix-term/src/theme.rs37
2 files changed, 41 insertions, 37 deletions
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
+ }
}