Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move ui and commands to helix-view #5581

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"helix-view",
"helix-term",
"helix-tui",
"helix-graphics",
"helix-lsp",
"helix-dap",
"helix-loader",
Expand Down
36 changes: 36 additions & 0 deletions helix-core/src/path.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -141,3 +143,37 @@ pub fn get_truncated_path<P: AsRef<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))
}
23 changes: 23 additions & 0 deletions helix-graphics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "helix-graphics"
version = "0.6.0"
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
edition = "2021"
license = "MPL-2.0"
repository = "https://github.com/helix-editor/helix"
homepage = "https://helix-editor.com"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/

[features]
term = ["crossterm"]

[dependencies]
bitflags = "1.3"
serde = { version = "1.0", features = ["derive"] }

crossterm = { version = "0.25", optional = true }

# TODO: graphics.rs tests rely on this, but we should remove that
# [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
# helix-tui = { path = "../helix-tui" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all our cargo.tomls have newlines at the end

Suggested change
# helix-tui = { path = "../helix-tui" }
# helix-tui = { path = "../helix-tui" }

27 changes: 14 additions & 13 deletions helix-view/src/graphics.rs → helix-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl FromStr for UnderlineStyle {
}
}

#[cfg(feature = "term")]
impl From<UnderlineStyle> for crossterm::style::Attribute {
fn from(style: UnderlineStyle) -> Self {
match style {
Expand All @@ -349,7 +350,7 @@ bitflags! {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::Modifier;
/// # use helix_graphics::Modifier;
///
/// let m = Modifier::BOLD | Modifier::ITALIC;
/// ```
Expand Down Expand Up @@ -387,7 +388,7 @@ impl FromStr for Modifier {
/// Style let you control the main characteristics of the displayed elements.
///
/// ```rust
/// # use helix_view::graphics::{Color, Modifier, Style};
/// # use helix_graphics::{Color, Modifier, Style};
/// Style::default()
/// .fg(Color::Black)
/// .bg(Color::Green)
Expand All @@ -398,8 +399,8 @@ impl FromStr for Modifier {
/// terminal buffer, the style of this cell will be the result of the merge of S1, S2 and S3, not
/// just S3.
///
/// ```rust
/// # use helix_view::graphics::{Rect, Color, UnderlineStyle, Modifier, Style};
/// ```ignore
/// # use helix_graphics::{Rect, Color, UnderlineStyle, Modifier, Style};
/// # use helix_tui::buffer::Buffer;
/// let styles = [
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
Expand All @@ -426,8 +427,8 @@ impl FromStr for Modifier {
/// The default implementation returns a `Style` that does not modify anything. If you wish to
/// reset all properties until that point use [`Style::reset`].
///
/// ```
/// # use helix_view::graphics::{Rect, Color, UnderlineStyle, Modifier, Style};
/// ``` ignore
/// # use helix_graphics::{Rect, Color, UnderlineStyle, Modifier, Style};
/// # use helix_tui::buffer::Buffer;
/// let styles = [
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
Expand Down Expand Up @@ -491,7 +492,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Style};
/// # use helix_graphics::{Color, Style};
/// let style = Style::default().fg(Color::Blue);
/// let diff = Style::default().fg(Color::Red);
/// assert_eq!(style.patch(diff), Style::default().fg(Color::Red));
Expand All @@ -506,7 +507,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Style};
/// # use helix_graphics::{Color, Style};
/// let style = Style::default().bg(Color::Blue);
/// let diff = Style::default().bg(Color::Red);
/// assert_eq!(style.patch(diff), Style::default().bg(Color::Red));
Expand All @@ -521,7 +522,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Style};
/// # use helix_graphics::{Color, Style};
/// let style = Style::default().underline_color(Color::Blue);
/// let diff = Style::default().underline_color(Color::Red);
/// assert_eq!(style.patch(diff), Style::default().underline_color(Color::Red));
Expand All @@ -536,7 +537,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{UnderlineStyle, Style};
/// # use helix_graphics::{UnderlineStyle, Style};
/// let style = Style::default().underline_style(UnderlineStyle::Line);
/// let diff = Style::default().underline_style(UnderlineStyle::Curl);
/// assert_eq!(style.patch(diff), Style::default().underline_style(UnderlineStyle::Curl));
Expand All @@ -553,7 +554,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Modifier, Style};
/// # use helix_graphics::{Color, Modifier, Style};
/// let style = Style::default().add_modifier(Modifier::BOLD);
/// let diff = Style::default().add_modifier(Modifier::ITALIC);
/// let patched = style.patch(diff);
Expand All @@ -573,7 +574,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_view::graphics::{Color, Modifier, Style};
/// # use helix_graphics::{Color, Modifier, Style};
/// let style = Style::default().add_modifier(Modifier::BOLD | Modifier::ITALIC);
/// let diff = Style::default().remove_modifier(Modifier::ITALIC);
/// let patched = style.patch(diff);
Expand All @@ -591,7 +592,7 @@ impl Style {
///
/// ## Examples
/// ```
/// # use helix_view::graphics::{Color, Modifier, Style};
/// # use helix_graphics::{Color, Modifier, Style};
/// let style_1 = Style::default().fg(Color::Yellow);
/// let style_2 = Style::default().bg(Color::Red);
/// let combined = style_1.patch(style_2);
Expand Down
13 changes: 1 addition & 12 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ path = "src/main.rs"

[dependencies]
helix-core = { version = "0.6", path = "../helix-core" }
helix-view = { version = "0.6", path = "../helix-view" }
helix-view = { version = "0.6", path = "../helix-view", features = ["term"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
helix-view = { version = "0.6", path = "../helix-view", features = ["term"]}
helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }

helix-lsp = { version = "0.6", path = "../helix-lsp" }
helix-dap = { version = "0.6", path = "../helix-dap" }
helix-vcs = { version = "0.6", path = "../helix-vcs" }
Expand All @@ -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"] }
Expand Down
37 changes: 2 additions & 35 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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))
}
12 changes: 6 additions & 6 deletions helix-term/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ extern crate helix_view;

pub mod application;
pub mod args;
pub mod commands;
pub mod compositor;
pub mod config;
pub use helix_view::commands;
pub use helix_view::compositor;
pub use helix_view::config;
pub mod health;
pub mod job;
pub mod keymap;
pub mod ui;
pub use helix_view::job;
pub use helix_view::keymap;
pub use helix_view::ui;
pub use keymap::macros::*;

#[cfg(not(windows))]
Expand Down
2 changes: 1 addition & 1 deletion helix-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ unicode-segmentation = "1.10"
crossterm = { version = "0.25", optional = true }
termini = "0.1"
serde = { version = "1", "optional" = true, features = ["derive"]}
helix-view = { version = "0.6", path = "../helix-view", features = ["term"] }
helix-graphics = { version = "0.6", path = "../helix-graphics", features = ["term"] }
helix-core = { version = "0.6", path = "../helix-core" }
2 changes: 1 addition & 1 deletion helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crossterm::{
terminal::{self, Clear, ClearType},
Command,
};
use helix_view::graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
use helix_graphics::{Color, CursorKind, Modifier, Rect, UnderlineStyle};
use std::{
fmt,
io::{self, Write},
Expand Down
2 changes: 1 addition & 1 deletion helix-tui/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;

use crate::buffer::Cell;

use helix_view::graphics::{CursorKind, Rect};
use helix_graphics::{CursorKind, Rect};

#[cfg(feature = "crossterm")]
mod crossterm;
Expand Down
Loading