TUI #1
@ -19,6 +19,7 @@ pub struct Editor {
|
||||
pub state: EditorState,
|
||||
pub event_handler: EditorEventHandler,
|
||||
pub file_path: Option<std::path::PathBuf>,
|
||||
syntax_set: SyntaxSet,
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
@ -27,6 +28,7 @@ impl Editor {
|
||||
state: EditorState::default(),
|
||||
event_handler: EditorEventHandler::default(),
|
||||
file_path: None,
|
||||
syntax_set: SyntaxSet::load_defaults_nonewlines(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,10 +61,11 @@ impl Widget for &mut Editor {
|
||||
.and_then(|p| p.extension())
|
||||
.map(|e| e.to_str().unwrap_or("md"))
|
||||
.unwrap_or("md");
|
||||
let lang_name = SyntaxSet::load_defaults_nonewlines()
|
||||
let lang_name = self
|
||||
.syntax_set
|
||||
.find_syntax_by_extension(lang)
|
||||
.map(|s| s.name.to_string())
|
||||
.unwrap_or_else(|| "Unknown".to_string());
|
||||
.unwrap_or("Unknown".to_string());
|
||||
|
||||
EditorView::new(&mut self.state)
|
||||
.wrap(true)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user