diff --git a/Cargo.lock b/Cargo.lock index d2e70242697d..7e2c96d6aee8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1208,13 +1208,9 @@ dependencies = [ "anyhow", "arc-swap", "chrono", - "content_inspector", "crossterm", "fern", "futures-util", - "fuzzy-matcher", - "grep-regex", - "grep-searcher", "helix-core", "helix-dap", "helix-loader", @@ -1222,11 +1218,9 @@ dependencies = [ "helix-tui", "helix-vcs", "helix-view", - "ignore", "indoc", "log", "once_cell", - "pulldown-cmark", "serde", "serde_json", "signal-hook", @@ -1275,8 +1269,12 @@ dependencies = [ "bitflags", "chardetng", "clipboard-win", + "content_inspector", "crossterm", "futures-util", + "fuzzy-matcher", + "grep-regex", + "grep-searcher", "helix-core", "helix-dap", "helix-graphics", @@ -1284,11 +1282,14 @@ dependencies = [ "helix-lsp", "helix-tui", "helix-vcs", + "ignore", "libc", "log", "once_cell", + "pulldown-cmark", "serde", "serde_json", + "signal-hook", "slotmap", "tokio", "tokio-stream", diff --git a/helix-core/src/path.rs b/helix-core/src/path.rs index d59a6baad604..d4ebe3233439 100644 --- a/helix-core/src/path.rs +++ b/helix-core/src/path.rs @@ -1,6 +1,8 @@ use etcetera::home_dir; use std::path::{Component, Path, PathBuf}; +use crate::Position; + /// Replaces users home directory from `path` with tilde `~` if the directory /// is available, otherwise returns the path unchanged. pub fn fold_home_dir(path: &Path) -> PathBuf { @@ -141,3 +143,37 @@ pub fn get_truncated_path>(path: P) -> PathBuf { ret.push(file); ret } + +/// Parse arg into [`PathBuf`] and position. +pub fn parse_file(s: &str) -> (PathBuf, Position) { + let def = || (PathBuf::from(s), Position::default()); + if Path::new(s).exists() { + return def(); + } + split_path_row_col(s) + .or_else(|| split_path_row(s)) + .unwrap_or_else(def) +} + +/// Split file.rs:10:2 into [`PathBuf`], row and col. +/// +/// Does not validate if file.rs is a file or directory. +fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> { + let mut s = s.rsplitn(3, ':'); + let col: usize = s.next()?.parse().ok()?; + let row: usize = s.next()?.parse().ok()?; + let path = s.next()?.into(); + let pos = Position::new(row.saturating_sub(1), col.saturating_sub(1)); + Some((path, pos)) +} + +/// Split file.rs:10 into [`PathBuf`] and row. +/// +/// Does not validate if file.rs is a file or directory. +fn split_path_row(s: &str) -> Option<(PathBuf, Position)> { + let (path, row) = s.rsplit_once(':')?; + let row: usize = row.parse().ok()?; + let path = path.into(); + let pos = Position::new(row.saturating_sub(1), 0); + Some((path, pos)) +} diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index f0664322203c..81c3f01cd4a9 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -52,23 +52,12 @@ fern = "0.6" chrono = { version = "0.4", default-features = false, features = ["clock"] } log = "0.4" -# File picker -fuzzy-matcher = "0.3" -ignore = "0.4" -# markdown doc rendering -pulldown-cmark = { version = "0.9", default-features = false } -# file type detection -content_inspector = "0.2.4" - # config toml = "0.5" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -# ripgrep for global search -grep-regex = "0.1.10" -grep-searcher = "0.1.10" [target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100 signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } diff --git a/helix-term/src/args.rs b/helix-term/src/args.rs index dd787f1fd18c..5a24bb43fe4b 100644 --- a/helix-term/src/args.rs +++ b/helix-term/src/args.rs @@ -1,7 +1,8 @@ use anyhow::Result; +use helix_core::path::parse_file; use helix_core::Position; use helix_view::tree::Layout; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; #[derive(Default)] pub struct Args { @@ -85,37 +86,3 @@ impl Args { Ok(args) } } - -/// Parse arg into [`PathBuf`] and position. -pub(crate) fn parse_file(s: &str) -> (PathBuf, Position) { - let def = || (PathBuf::from(s), Position::default()); - if Path::new(s).exists() { - return def(); - } - split_path_row_col(s) - .or_else(|| split_path_row(s)) - .unwrap_or_else(def) -} - -/// Split file.rs:10:2 into [`PathBuf`], row and col. -/// -/// Does not validate if file.rs is a file or directory. -fn split_path_row_col(s: &str) -> Option<(PathBuf, Position)> { - let mut s = s.rsplitn(3, ':'); - let col: usize = s.next()?.parse().ok()?; - let row: usize = s.next()?.parse().ok()?; - let path = s.next()?.into(); - let pos = Position::new(row.saturating_sub(1), col.saturating_sub(1)); - Some((path, pos)) -} - -/// Split file.rs:10 into [`PathBuf`] and row. -/// -/// Does not validate if file.rs is a file or directory. -fn split_path_row(s: &str) -> Option<(PathBuf, Position)> { - let (path, row) = s.rsplit_once(':')?; - let row: usize = row.parse().ok()?; - let path = path.into(); - let pos = Position::new(row.saturating_sub(1), 0); - Some((path, pos)) -} diff --git a/helix-term/src/lib.rs b/helix-term/src/lib.rs index 616a14b1d0c2..fb0da75cf6d5 100644 --- a/helix-term/src/lib.rs +++ b/helix-term/src/lib.rs @@ -3,13 +3,13 @@ extern crate helix_view; pub mod application; pub mod args; -pub mod commands; +pub use helix_view::commands; pub use helix_view::compositor; -pub mod config; +pub use helix_view::config; pub mod health; pub use helix_view::job; -pub mod keymap; -pub mod ui; +pub use helix_view::keymap; +pub use helix_view::ui; pub use keymap::macros::*; #[cfg(not(windows))] diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index 5393c0ced209..005b841984b1 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -46,6 +46,19 @@ log = "~0.4" which = "4.2" +# File picker +fuzzy-matcher = "0.3" +ignore = "0.4" +# markdown doc rendering +pulldown-cmark = { version = "0.9", default-features = false } +# file type detection +content_inspector = "0.2.4" + +# ripgrep for global search +grep-regex = "0.1.10" +grep-searcher = "0.1.10" + +signal-hook = "0.3" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "4.5", features = ["std"] } diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index e773a2c789d8..edf9c473df0f 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -3,11 +3,22 @@ pub(crate) mod lsp; pub(crate) mod typed; pub use dap::*; +use helix_tui::widgets::Row; use helix_vcs::Hunk; pub use lsp::*; -use tui::widgets::Row; pub use typed::*; +use crate::{ + clipboard::ClipboardType, + document::{FormatterError, Mode, SCRATCH_BUFFER_NAME}, + editor::{Action, Motion}, + info::Info, + input::KeyEvent, + keyboard::KeyCode, + tree, + view::View, + Document, DocumentId, Editor, ViewId, +}; use helix_core::{ comment, coords_at_pos, encoding, find_first_non_whitespace_char, find_root, graphemes, history::UndoKind, @@ -25,17 +36,6 @@ use helix_core::{ visual_coords_at_pos, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, Transaction, }; -use helix_view::{ - clipboard::ClipboardType, - document::{FormatterError, Mode, SCRATCH_BUFFER_NAME}, - editor::{Action, Motion}, - info::Info, - input::KeyEvent, - keyboard::KeyCode, - tree, - view::View, - Document, DocumentId, Editor, ViewId, -}; use anyhow::{anyhow, bail, ensure, Context as _}; use fuzzy_matcher::FuzzyMatcher; @@ -43,7 +43,6 @@ use insert::*; use movement::Movement; use crate::{ - args, compositor::{self, Component, Compositor}, job::Callback, keymap::ReverseKeymap, @@ -123,7 +122,7 @@ impl<'a> Context<'a> { } } -use helix_view::{align_view, Align}; +use crate::{align_view, Align}; /// A MappableCommand is either a static command like "jump_view_up" or a Typable command like /// :format. It causes a side-effect on the state (usually by creating and applying a transaction). @@ -4882,7 +4881,7 @@ async fn shell_impl_async( let output = if let Some(mut stdin) = process.stdin.take() { let input_task = tokio::spawn(async move { if let Some(input) = input { - helix_view::document::to_writer(&mut stdin, encoding::UTF_8, &input).await?; + crate::document::to_writer(&mut stdin, encoding::UTF_8, &input).await?; } Ok::<_, anyhow::Error>(()) }); @@ -5152,7 +5151,7 @@ fn replay_macro(cx: &mut Context) { } let keys: Vec = if let Some([keys_str]) = cx.editor.registers.read(reg) { - match helix_view::input::parse_macro(keys_str) { + match crate::input::parse_macro(keys_str) { Ok(keys) => keys, Err(err) => { cx.editor.set_error(format!("Invalid macro: {}", err)); diff --git a/helix-view/src/commands/dap.rs b/helix-view/src/commands/dap.rs index b3166e395d90..14a55a88e34e 100644 --- a/helix-view/src/commands/dap.rs +++ b/helix-view/src/commands/dap.rs @@ -1,4 +1,5 @@ use super::{Context, Editor}; +use crate::editor::Breakpoint; use crate::{ compositor::{self, Compositor}, job::{Callback, Jobs}, @@ -8,11 +9,10 @@ use dap::{StackFrame, Thread, ThreadStates}; use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion, DebugTemplate}; use helix_dap::{self as dap, Client}; use helix_lsp::block_on; -use helix_view::editor::Breakpoint; +use helix_tui::{text::Spans, widgets::Row}; use serde_json::{to_value, Value}; use tokio_stream::wrappers::UnboundedReceiverStream; -use tui::{text::Spans, widgets::Row}; use std::collections::HashMap; use std::future::Future; @@ -20,7 +20,8 @@ use std::path::PathBuf; use anyhow::{anyhow, bail}; -use helix_view::handlers::dap::{breakpoints_changed, jump_to_stack_frame, select_thread_id}; +use crate::debugger; +use crate::handlers::dap::{breakpoints_changed, jump_to_stack_frame, select_thread_id}; impl ui::menu::Item for StackFrame { type Data = (); @@ -505,8 +506,8 @@ pub fn dap_variables(cx: &mut Context) { let text_style = theme.get("ui.text.focus"); for scope in scopes.iter() { - // use helix_view::graphics::Style; - use tui::text::Span; + // use crate::graphics::Style; + use helix_tui::text::Span; let response = block_on(debugger.variables(scope.variables_reference)); variables.push(Spans::from(Span::styled( @@ -531,7 +532,7 @@ pub fn dap_variables(cx: &mut Context) { } } - let contents = Text::from(tui::text::Text::from(variables)); + let contents = Text::from(helix_tui::text::Text::from(variables)); let popup = Popup::new("dap-variables", contents); cx.push_layer(Box::new(popup)); } diff --git a/helix-view/src/commands/lsp.rs b/helix-view/src/commands/lsp.rs index 578eb6084196..5dcb1671771a 100644 --- a/helix-view/src/commands/lsp.rs +++ b/helix-view/src/commands/lsp.rs @@ -5,15 +5,15 @@ use helix_lsp::{ util::{diagnostic_to_lsp_diagnostic, lsp_pos_to_pos, lsp_range_to_range, range_to_lsp_range}, OffsetEncoding, }; -use tui::{ +use helix_tui::{ text::{Span, Spans}, widgets::Row, }; use super::{align_view, push_jump, Align, Context, Editor, Open}; +use crate::{document::Mode, editor::Action, theme::Style}; use helix_core::{path, Selection}; -use helix_view::{document::Mode, editor::Action, theme::Style}; use crate::{ compositor::{self, Compositor}, diff --git a/helix-view/src/commands/typed.rs b/helix-view/src/commands/typed.rs index bd91df5ae62a..1d49f627fb5b 100644 --- a/helix-view/src/commands/typed.rs +++ b/helix-view/src/commands/typed.rs @@ -4,7 +4,8 @@ use crate::job::Job; use super::*; -use helix_view::editor::{Action, CloseError, ConfigEvent}; +use crate::editor::{Action, CloseError, ConfigEvent}; +use helix_core::path::parse_file; use ui::completers::{self, Completer}; #[derive(Clone)] @@ -61,7 +62,7 @@ fn open(cx: &mut compositor::Context, args: &[Cow], event: PromptEvent) -> ensure!(!args.is_empty(), "wrong argument count"); for arg in args { - let (path, pos) = args::parse_file(arg); + let (path, pos) = parse_file(arg); let path = helix_core::path::expand_tilde(&path); // If the path is a directory, open a file picker on that directory and update the status // message @@ -767,7 +768,7 @@ fn theme( args: &[Cow], event: PromptEvent, ) -> anyhow::Result<()> { - let true_color = cx.editor.config.load().true_color || crate::true_color(); + let true_color = cx.editor.config.load().true_color || crate::theme::true_color(); match event { PromptEvent::Abort => { cx.editor.unset_theme_preview(); diff --git a/helix-view/src/config.rs b/helix-view/src/config.rs index 4407a882f838..a0447dc27ba6 100644 --- a/helix-view/src/config.rs +++ b/helix-view/src/config.rs @@ -1,5 +1,5 @@ +use crate::document::Mode; use crate::keymap::{default::default, merge_keys, Keymap}; -use helix_view::document::Mode; use serde::Deserialize; use std::collections::HashMap; use std::fmt::Display; @@ -14,7 +14,7 @@ pub struct Config { #[serde(default = "default")] pub keys: HashMap, #[serde(default)] - pub editor: helix_view::editor::Config, + pub editor: crate::editor::Config, } impl Default for Config { @@ -22,7 +22,7 @@ impl Default for Config { Config { theme: None, keys: default(), - editor: helix_view::editor::Config::default(), + editor: crate::editor::Config::default(), } } } @@ -63,10 +63,10 @@ mod tests { #[test] fn parsing_keymaps_config_file() { + use crate::document::Mode; use crate::keymap; use crate::keymap::Keymap; use helix_core::hashmap; - use helix_view::document::Mode; let sample_keymaps = r#" [keys.insert] diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index 4a131f0a5217..2ddb4852c5e0 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -3,11 +3,11 @@ pub mod macros; pub use crate::commands::MappableCommand; use crate::config::Config; +use crate::{document::Mode, info::Info, input::KeyEvent}; use arc_swap::{ access::{DynAccess, DynGuard}, ArcSwap, }; -use helix_view::{document::Mode, info::Info, input::KeyEvent}; use serde::Deserialize; use std::{ borrow::Cow, diff --git a/helix-view/src/keymap/macros.rs b/helix-view/src/keymap/macros.rs index c4a1bfbb3064..873f51c8952c 100644 --- a/helix-view/src/keymap/macros.rs +++ b/helix-view/src/keymap/macros.rs @@ -1,15 +1,15 @@ #[macro_export] macro_rules! key { ($key:ident) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::$key, - modifiers: ::helix_view::keyboard::KeyModifiers::NONE, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::$key, + modifiers: $crate::keyboard::KeyModifiers::NONE, } }; ($($ch:tt)*) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::Char($($ch)*), - modifiers: ::helix_view::keyboard::KeyModifiers::NONE, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::Char($($ch)*), + modifiers: $crate::keyboard::KeyModifiers::NONE, } }; } @@ -17,15 +17,15 @@ macro_rules! key { #[macro_export] macro_rules! shift { ($key:ident) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::$key, - modifiers: ::helix_view::keyboard::KeyModifiers::SHIFT, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::$key, + modifiers: $crate::keyboard::KeyModifiers::SHIFT, } }; ($($ch:tt)*) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::Char($($ch)*), - modifiers: ::helix_view::keyboard::KeyModifiers::SHIFT, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::Char($($ch)*), + modifiers: $crate::keyboard::KeyModifiers::SHIFT, } }; } @@ -33,15 +33,15 @@ macro_rules! shift { #[macro_export] macro_rules! ctrl { ($key:ident) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::$key, - modifiers: ::helix_view::keyboard::KeyModifiers::CONTROL, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::$key, + modifiers: $crate::keyboard::KeyModifiers::CONTROL, } }; ($($ch:tt)*) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::Char($($ch)*), - modifiers: ::helix_view::keyboard::KeyModifiers::CONTROL, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::Char($($ch)*), + modifiers: $crate::keyboard::KeyModifiers::CONTROL, } }; } @@ -49,15 +49,15 @@ macro_rules! ctrl { #[macro_export] macro_rules! alt { ($key:ident) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::$key, - modifiers: ::helix_view::keyboard::KeyModifiers::ALT, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::$key, + modifiers: $crate::keyboard::KeyModifiers::ALT, } }; ($($ch:tt)*) => { - ::helix_view::input::KeyEvent { - code: ::helix_view::keyboard::KeyCode::Char($($ch)*), - modifiers: ::helix_view::keyboard::KeyModifiers::ALT, + $crate::input::KeyEvent { + code: $crate::keyboard::KeyCode::Char($($ch)*), + modifiers: $crate::keyboard::KeyModifiers::ALT, } }; } @@ -66,8 +66,8 @@ macro_rules! alt { /// /// ``` /// # use helix_core::hashmap; -/// # use helix_term::keymap; -/// # use helix_term::keymap::Keymap; +/// # use helix_view::keymap; +/// # use helix_view::keymap::Keymap; /// let normal_mode = keymap!({ "Normal mode" /// "i" => insert_mode, /// "g" => { "Goto" @@ -104,7 +104,7 @@ macro_rules! keymap { let mut _order = ::std::vec::Vec::with_capacity(_cap); $( $( - let _key = $key.parse::<::helix_view::input::KeyEvent>().unwrap(); + let _key = $key.parse::<$crate::input::KeyEvent>().unwrap(); let _duplicate = _map.insert( _key, keymap!(@trie $value) diff --git a/helix-view/src/lib.rs b/helix-view/src/lib.rs index 9653ca0f0910..0c3826df7b96 100644 --- a/helix-view/src/lib.rs +++ b/helix-view/src/lib.rs @@ -12,14 +12,18 @@ pub mod handlers { pub mod lsp; } pub mod base64; +pub mod commands; +pub mod compositor; +pub mod config; pub mod info; pub mod input; +pub mod job; pub mod keyboard; +pub mod keymap; pub mod theme; pub mod tree; +pub mod ui; pub mod view; -pub mod compositor; -pub mod job; use std::num::NonZeroUsize; diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index cb0d3ac46d34..71f8f354bc1b 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -475,6 +475,18 @@ impl TryFrom for ThemePalette { } } +#[cfg(not(windows))] +pub fn true_color() -> bool { + std::env::var("COLORTERM") + .map(|v| matches!(v.as_str(), "truecolor" | "24bit")) + .unwrap_or(false) +} + +#[cfg(windows)] +pub fn true_color() -> bool { + true +} + #[cfg(test)] mod tests { use super::*; diff --git a/helix-view/src/ui/completion.rs b/helix-view/src/ui/completion.rs index 2eca709d181b..79a0984332be 100644 --- a/helix-view/src/ui/completion.rs +++ b/helix-view/src/ui/completion.rs @@ -1,15 +1,15 @@ use crate::compositor::{Component, Context, Event, EventResult}; -use helix_view::{editor::CompleteAction, ViewId}; -use tui::buffer::Buffer as Surface; +use crate::{editor::CompleteAction, ViewId}; +use helix_tui::buffer::Buffer as Surface; use std::borrow::Cow; -use helix_core::{Change, Transaction}; -use helix_view::{ +use crate::{ graphics::Rect, input::{KeyCode, KeyEvent}, Document, Editor, }; +use helix_core::{Change, Transaction}; use crate::commands; use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent}; diff --git a/helix-view/src/ui/editor.rs b/helix-view/src/ui/editor.rs index a0518964e2a7..5c9fcb2d73ea 100644 --- a/helix-view/src/ui/editor.rs +++ b/helix-view/src/ui/editor.rs @@ -7,6 +7,14 @@ use crate::{ ui::{Completion, ProgressSpinners}, }; +use crate::{ + document::{Mode, SCRATCH_BUFFER_NAME}, + editor::{CompleteAction, CursorShapeConfig}, + graphics::{Color, CursorKind, Modifier, Rect, Style}, + input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, + keyboard::{KeyCode, KeyModifiers}, + Document, Editor, Theme, View, +}; use helix_core::{ graphemes::{ ensure_grapheme_boundary_next_byte, next_grapheme_boundary, prev_grapheme_boundary, @@ -16,17 +24,9 @@ use helix_core::{ unicode::width::UnicodeWidthStr, visual_coords_at_pos, LineEnding, Position, Range, Selection, Transaction, }; -use helix_view::{ - document::{Mode, SCRATCH_BUFFER_NAME}, - editor::{CompleteAction, CursorShapeConfig}, - graphics::{Color, CursorKind, Modifier, Rect, Style}, - input::{KeyEvent, MouseButton, MouseEvent, MouseEventKind}, - keyboard::{KeyCode, KeyModifiers}, - Document, Editor, Theme, View, -}; use std::{borrow::Cow, cmp::min, num::NonZeroUsize, path::PathBuf}; -use tui::buffer::Buffer as Surface; +use helix_tui::buffer::Buffer as Surface; use super::lsp::SignatureHelp; use super::statusline; @@ -162,7 +162,7 @@ impl EditorView { let border_style = theme.get("ui.window"); for y in area.top()..area.bottom() { surface[(x, y)] - .set_symbol(tui::symbols::line::VERTICAL) + .set_symbol(helix_tui::symbols::line::VERTICAL) //.set_symbol(" ") .set_style(border_style); } @@ -431,10 +431,10 @@ impl EditorView { surface: &mut Surface, theme: &Theme, highlights: H, - config: &helix_view::editor::Config, + config: &crate::editor::Config, ) { let whitespace = &config.whitespace; - use helix_view::editor::WhitespaceRenderValue; + use crate::editor::WhitespaceRenderValue; // It's slightly more efficient to produce a full RopeSlice from the Rope, then slice that a bunch // of times than it is to always call Rope::slice/get_slice (it will internally always hit RSEnum::Light). @@ -793,7 +793,7 @@ impl EditorView { theme: &Theme, ) { use helix_core::diagnostic::Severity; - use tui::{ + use helix_tui::{ layout::Alignment, text::Text, widgets::{Paragraph, Widget, Wrap}, @@ -1469,7 +1469,7 @@ impl Component for EditorView { let config = cx.editor.config(); // check if bufferline should be rendered - use helix_view::editor::BufferLine; + use crate::editor::BufferLine; let use_bufferline = match config.bufferline { BufferLine::Always => true, BufferLine::Multiple if cx.editor.documents.len() > 1 => true, @@ -1507,7 +1507,7 @@ impl Component for EditorView { // render status msg if let Some((status_msg, severity)) = &cx.editor.status_msg { status_msg_width = status_msg.width(); - use helix_view::editor::Severity; + use crate::editor::Severity; let style = if *severity == Severity::Error { cx.editor.theme.get("error") } else { @@ -1549,7 +1549,7 @@ impl Component for EditorView { if let Some((reg, _)) = cx.editor.macro_recording { let disp = format!("[{}]", reg); let style = style - .fg(helix_view::graphics::Color::Yellow) + .fg(crate::graphics::Color::Yellow) .add_modifier(Modifier::BOLD); surface.set_string( area.x + area.width.saturating_sub(3), diff --git a/helix-view/src/ui/info.rs b/helix-view/src/ui/info.rs index cc6b7483f887..de528969ac8d 100644 --- a/helix-view/src/ui/info.rs +++ b/helix-view/src/ui/info.rs @@ -1,8 +1,8 @@ use crate::compositor::{Component, Context}; -use helix_view::graphics::{Margin, Rect}; -use helix_view::info::Info; -use tui::buffer::Buffer as Surface; -use tui::widgets::{Block, Borders, Paragraph, Widget}; +use crate::graphics::{Margin, Rect}; +use crate::info::Info; +use helix_tui::buffer::Buffer as Surface; +use helix_tui::widgets::{Block, Borders, Paragraph, Widget}; impl Component for Info { fn render(&mut self, viewport: Rect, surface: &mut Surface, cx: &mut Context) { diff --git a/helix-view/src/ui/lsp.rs b/helix-view/src/ui/lsp.rs index 393d24c467bc..5147e11fafbf 100644 --- a/helix-view/src/ui/lsp.rs +++ b/helix-view/src/ui/lsp.rs @@ -1,9 +1,9 @@ use std::sync::Arc; +use crate::graphics::{Margin, Rect, Style}; use helix_core::syntax; -use helix_view::graphics::{Margin, Rect, Style}; -use tui::buffer::Buffer; -use tui::widgets::{BorderType, Paragraph, Widget, Wrap}; +use helix_tui::buffer::Buffer; +use helix_tui::widgets::{BorderType, Paragraph, Widget, Wrap}; use crate::compositor::{Component, Compositor, Context}; diff --git a/helix-view/src/ui/markdown.rs b/helix-view/src/ui/markdown.rs index 923dd73a16ab..9962457e07f5 100644 --- a/helix-view/src/ui/markdown.rs +++ b/helix-view/src/ui/markdown.rs @@ -1,5 +1,5 @@ use crate::compositor::{Component, Context}; -use tui::{ +use helix_tui::{ buffer::Buffer as Surface, text::{Span, Spans, Text}, }; @@ -8,14 +8,14 @@ use std::sync::Arc; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag}; +use crate::{ + graphics::{Margin, Rect, Style}, + Theme, +}; use helix_core::{ syntax::{self, HighlightEvent, Syntax}, Rope, }; -use helix_view::{ - graphics::{Margin, Rect, Style}, - Theme, -}; fn styled_multiline_text<'a>(text: String, style: Style) -> Text<'a> { let spans: Vec<_> = text @@ -144,7 +144,7 @@ impl Markdown { } } - pub fn parse(&self, theme: Option<&Theme>) -> tui::text::Text<'_> { + pub fn parse(&self, theme: Option<&Theme>) -> helix_tui::text::Text<'_> { fn push_line<'a>(spans: &mut Vec>, lines: &mut Vec>) { let spans = std::mem::take(spans); if !spans.is_empty() { @@ -264,14 +264,14 @@ impl Markdown { CodeBlockKind::Fenced(language) => language, CodeBlockKind::Indented => "", }; - let tui_text = highlighted_code_block( + let helix_tui_text = highlighted_code_block( text.to_string(), language, theme, Arc::clone(&self.config_loader), None, ); - lines.extend(tui_text.lines.into_iter()); + lines.extend(helix_tui_text.lines.into_iter()); } else { let style = if let Some(Tag::Heading(level, ..)) = tags.last() { match level { @@ -308,7 +308,7 @@ impl Markdown { log::warn!("unhandled markdown event {:?}", event); } } - // build up a vec of Paragraph tui widgets + // build up a vec of Paragraph helix_tui widgets } if !spans.is_empty() { @@ -328,7 +328,7 @@ impl Markdown { impl Component for Markdown { fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) { - use tui::widgets::{Paragraph, Widget, Wrap}; + use helix_tui::widgets::{Paragraph, Widget, Wrap}; let text = self.parse(Some(&cx.editor.theme)); diff --git a/helix-view/src/ui/menu.rs b/helix-view/src/ui/menu.rs index e92578c5a136..cedaf2732eea 100644 --- a/helix-view/src/ui/menu.rs +++ b/helix-view/src/ui/menu.rs @@ -4,15 +4,15 @@ use crate::{ compositor::{Callback, Component, Compositor, Context, Event, EventResult}, ctrl, key, shift, }; -use tui::{buffer::Buffer as Surface, widgets::Table}; +use helix_tui::{buffer::Buffer as Surface, widgets::Table}; -pub use tui::widgets::{Cell, Row}; +pub use helix_tui::widgets::{Cell, Row}; use fuzzy_matcher::skim::SkimMatcherV2 as Matcher; use fuzzy_matcher::FuzzyMatcher; -use helix_view::{graphics::Rect, Editor}; -use tui::layout::Constraint; +use crate::{graphics::Rect, Editor}; +use helix_tui::layout::Constraint; pub trait Item { /// Additional editor state that is used for label calculation. @@ -336,7 +336,7 @@ impl Component for Menu { .column_spacing(1) .widths(&self.widths); - use tui::widgets::TableState; + use helix_tui::widgets::TableState; table.render_table( area.clip_left(Self::LEFT_PADDING as u16).clip_right(1), @@ -374,10 +374,10 @@ impl Component for Menu { if scroll_line <= i && i < scroll_line + scroll_height { // Draw scroll thumb - cell.set_fg(scroll_style.fg.unwrap_or(helix_view::theme::Color::Reset)); + cell.set_fg(scroll_style.fg.unwrap_or(crate::theme::Color::Reset)); } else { // Draw scroll track - cell.set_fg(scroll_style.bg.unwrap_or(helix_view::theme::Color::Reset)); + cell.set_fg(scroll_style.bg.unwrap_or(crate::theme::Color::Reset)); } } } diff --git a/helix-view/src/ui/mod.rs b/helix-view/src/ui/mod.rs index eb4807581e8c..d6119bcdf62c 100644 --- a/helix-view/src/ui/mod.rs +++ b/helix-view/src/ui/mod.rs @@ -25,9 +25,9 @@ pub use prompt::{Prompt, PromptEvent}; pub use spinner::{ProgressSpinners, Spinner}; pub use text::Text; +use crate::Editor; use helix_core::regex::Regex; use helix_core::regex::RegexBuilder; -use helix_view::Editor; use std::path::PathBuf; @@ -156,7 +156,7 @@ pub fn regex_prompt( cx.push_layer(Box::new(prompt)); } -pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePicker { +pub fn file_picker(root: PathBuf, config: &crate::editor::Config) -> FilePicker { use ignore::{types::TypesBuilder, WalkBuilder}; use std::time::Instant; @@ -236,12 +236,12 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi } pub mod completers { + use crate::document::SCRATCH_BUFFER_NAME; + use crate::theme; use crate::ui::prompt::Completion; + use crate::{editor::Config, Editor}; use fuzzy_matcher::skim::SkimMatcherV2 as Matcher; use fuzzy_matcher::FuzzyMatcher; - use helix_view::document::SCRATCH_BUFFER_NAME; - use helix_view::theme; - use helix_view::{editor::Config, Editor}; use once_cell::sync::Lazy; use std::borrow::Cow; use std::cmp::Reverse; diff --git a/helix-view/src/ui/overlay.rs b/helix-view/src/ui/overlay.rs index 5b2bc806093d..59ad145640f7 100644 --- a/helix-view/src/ui/overlay.rs +++ b/helix-view/src/ui/overlay.rs @@ -1,9 +1,9 @@ -use helix_core::Position; -use helix_view::{ +use crate::{ graphics::{CursorKind, Rect}, Editor, }; -use tui::buffer::Buffer; +use helix_core::Position; +use helix_tui::buffer::Buffer; use crate::compositor::{Component, Context, Event, EventResult}; diff --git a/helix-view/src/ui/picker.rs b/helix-view/src/ui/picker.rs index ccf37eb2bac5..066c62c94655 100644 --- a/helix-view/src/ui/picker.rs +++ b/helix-view/src/ui/picker.rs @@ -5,7 +5,7 @@ use crate::{ ui::{self, fuzzy_match::FuzzyQuery, EditorView}, }; use futures_util::future::BoxFuture; -use tui::{ +use helix_tui::{ buffer::Buffer as Surface, layout::Constraint, text::{Span, Spans}, @@ -13,19 +13,19 @@ use tui::{ }; use fuzzy_matcher::skim::SkimMatcherV2 as Matcher; -use tui::widgets::Widget; +use helix_tui::widgets::Widget; use std::cmp::{self, Ordering}; use std::{collections::HashMap, io::Read, path::PathBuf}; use crate::ui::{Prompt, PromptEvent}; -use helix_core::{movement::Direction, unicode::segmentation::UnicodeSegmentation, Position}; -use helix_view::{ +use crate::{ editor::Action, graphics::{CursorKind, Margin, Modifier, Rect}, theme::Style, Document, DocumentId, Editor, }; +use helix_core::{movement::Direction, unicode::segmentation::UnicodeSegmentation, Position}; use super::{menu::Item, overlay::Overlay}; @@ -823,7 +823,7 @@ impl Component for Picker { .column_spacing(1) .widths(&self.widths); - use tui::widgets::TableState; + use helix_tui::widgets::TableState; table.render_table( inner, diff --git a/helix-view/src/ui/popup.rs b/helix-view/src/ui/popup.rs index 5a95c1bbae79..8263b520a9ce 100644 --- a/helix-view/src/ui/popup.rs +++ b/helix-view/src/ui/popup.rs @@ -3,10 +3,10 @@ use crate::{ compositor::{Callback, Component, Context, Event, EventResult}, ctrl, key, }; -use tui::buffer::Buffer as Surface; +use helix_tui::buffer::Buffer as Surface; +use crate::graphics::{Margin, Rect}; use helix_core::Position; -use helix_view::graphics::{Margin, Rect}; // TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return // a width/height hint. maybe Popup(Box) @@ -274,10 +274,10 @@ impl Component for Popup { if scroll_line <= i && i < scroll_line + scroll_height { // Draw scroll thumb - cell.set_fg(scroll_style.fg.unwrap_or(helix_view::theme::Color::Reset)); + cell.set_fg(scroll_style.fg.unwrap_or(crate::theme::Color::Reset)); } else { // Draw scroll track - cell.set_fg(scroll_style.bg.unwrap_or(helix_view::theme::Color::Reset)); + cell.set_fg(scroll_style.bg.unwrap_or(crate::theme::Color::Reset)); } } } diff --git a/helix-view/src/ui/prompt.rs b/helix-view/src/ui/prompt.rs index 5fb6745a90e5..708f7402a5d4 100644 --- a/helix-view/src/ui/prompt.rs +++ b/helix-view/src/ui/prompt.rs @@ -1,18 +1,18 @@ use crate::compositor::{Component, Compositor, Context, Event, EventResult}; +use crate::input::KeyEvent; +use crate::keyboard::KeyCode; use crate::{alt, ctrl, key, shift, ui}; -use helix_view::input::KeyEvent; -use helix_view::keyboard::KeyCode; +use helix_tui::buffer::Buffer as Surface; +use helix_tui::widgets::{Block, Borders, Widget}; use std::{borrow::Cow, ops::RangeFrom}; -use tui::buffer::Buffer as Surface; -use tui::widgets::{Block, Borders, Widget}; -use helix_core::{ - unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position, -}; -use helix_view::{ +use crate::{ graphics::{CursorKind, Margin, Rect}, Editor, }; +use helix_core::{ + unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position, +}; pub type Completion = (RangeFrom, Cow<'static, str>); type PromptCharHandler = Box; diff --git a/helix-view/src/ui/statusline.rs b/helix-view/src/ui/statusline.rs index a25b4540d1f9..2e4263bc6899 100644 --- a/helix-view/src/ui/statusline.rs +++ b/helix-view/src/ui/statusline.rs @@ -1,17 +1,17 @@ -use helix_core::{coords_at_pos, encoding, Position}; -use helix_lsp::lsp::DiagnosticSeverity; -use helix_view::{ +use crate::{ document::{Mode, SCRATCH_BUFFER_NAME}, graphics::Rect, theme::Style, Document, Editor, View, }; +use helix_core::{coords_at_pos, encoding, Position}; +use helix_lsp::lsp::DiagnosticSeverity; use crate::ui::ProgressSpinners; -use helix_view::editor::StatusLineElement as StatusLineElementID; -use tui::buffer::Buffer as Surface; -use tui::text::{Span, Spans}; +use crate::editor::StatusLineElement as StatusLineElementID; +use helix_tui::buffer::Buffer as Surface; +use helix_tui::text::{Span, Spans}; pub struct RenderContext<'a> { pub editor: &'a Editor, @@ -137,24 +137,22 @@ where F: Fn(&mut RenderContext, String, Option