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

reverse the dependency between helix-tui and helix-view #366

Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ path = "src/main.rs"

[dependencies]
helix-core = { version = "0.2", path = "../helix-core" }
helix-view = { version = "0.2", path = "../helix-view", features = ["term"]}
helix-lsp = { version = "0.2", path = "../helix-lsp"}
helix-view = { version = "0.2", path = "../helix-view" }
helix-lsp = { version = "0.2", path = "../helix-lsp" }

anyhow = "1"
once_cell = "1.8"
Expand Down
4 changes: 1 addition & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use helix_core::syntax;
use helix_lsp::{lsp, LspProgressMap};
use helix_view::{document::Mode, theme, Document, Editor, Theme, View};
use helix_view::{document::Mode, graphics::Rect, theme, Document, Editor, Theme, View};

use crate::{
args::Args,
Expand Down Expand Up @@ -29,8 +29,6 @@ use crossterm::{
execute, terminal,
};

use tui::layout::Rect;

use futures_util::{future, stream::FuturesUnordered};

type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
Expand Down
3 changes: 2 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use helix_core::{

use helix_view::{
document::{IndentStyle, Mode},
input::{KeyCode, KeyEvent},
input::KeyEvent,
keyboard::KeyCode,
view::{View, PADDING},
Document, DocumentId, Editor, ViewId,
};
Expand Down
3 changes: 2 additions & 1 deletion helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
use helix_core::Position;
use helix_lsp::LspProgressMap;
use helix_view::graphics::{CursorKind, Rect};

use crossterm::event::Event;
use tui::{buffer::Buffer as Surface, layout::Rect, terminal::CursorKind};
use tui::buffer::Buffer as Surface;

pub type Callback = Box<dyn FnOnce(&mut Compositor)>;

Expand Down
7 changes: 5 additions & 2 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ pub struct LspConfig {
#[test]
fn parsing_keymaps_config_file() {
use helix_core::hashmap;
use helix_view::document::Mode;
use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
use helix_view::{
document::Mode,
input::KeyEvent,
keyboard::{KeyCode, KeyModifiers},
};

let sample_keymaps = r#"
[keys.insert]
Expand Down
7 changes: 5 additions & 2 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ pub use crate::commands::Command;
use crate::config::Config;
use anyhow::{anyhow, Error, Result};
use helix_core::hashmap;
use helix_view::document::Mode;
use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
use helix_view::{
document::Mode,
input::KeyEvent,
keyboard::{KeyCode, KeyModifiers},
};
use serde::Deserialize;
use std::{
collections::HashMap,
Expand Down
11 changes: 5 additions & 6 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
};
use tui::buffer::Buffer as Surface;

use std::borrow::Cow;

use helix_core::{Position, Transaction};
use helix_view::Editor;
use helix_view::{
graphics::{Color, Rect, Style},
Editor,
};

use crate::commands;
use crate::ui::{menu, Markdown, Menu, Popup, PromptEvent};
Expand Down
17 changes: 8 additions & 9 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ use helix_core::{
LineEnding, Position, Range,
};
use helix_lsp::LspProgressMap;
use helix_view::input::{KeyCode, KeyEvent, KeyModifiers};
use helix_view::{document::Mode, Document, Editor, Theme, View};
use helix_view::{
document::Mode,
graphics::{Color, CursorKind, Modifier, Rect, Style},
input::KeyEvent,
keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View,
};
use std::borrow::Cow;

use crossterm::{
cursor,
event::{read, Event, EventStream},
};
use tui::{
backend::CrosstermBackend,
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Modifier, Style},
terminal::CursorKind,
};
use tui::{backend::CrosstermBackend, buffer::Buffer as Surface};

pub struct EditorView {
keymaps: Keymaps,
Expand Down
12 changes: 5 additions & 7 deletions helix-term/src/ui/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
text::Text,
};
use tui::{buffer::Buffer as Surface, text::Text};

use std::{borrow::Cow, sync::Arc};

use helix_core::{syntax, Position};
use helix_view::{Editor, Theme};
use helix_view::{
graphics::{Color, Rect, Style},
Editor, Theme,
};

pub struct Markdown {
contents: String,
Expand Down
12 changes: 5 additions & 7 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
widgets::Table,
};
use tui::{buffer::Buffer as Surface, widgets::Table};

pub use tui::widgets::{Cell, Row};

Expand All @@ -15,7 +10,10 @@ use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
use fuzzy_matcher::FuzzyMatcher;

use helix_core::Position;
use helix_view::Editor;
use helix_view::{
graphics::{Color, Rect, Style},
Editor,
};

pub trait Item {
// TODO: sort_text
Expand Down
8 changes: 4 additions & 4 deletions helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub use prompt::{Prompt, PromptEvent};
pub use spinner::{ProgressSpinners, Spinner};
pub use text::Text;

pub use tui::layout::Rect;
pub use tui::style::{Color, Modifier, Style};

use helix_core::regex::Regex;
use helix_core::register::Registers;
use helix_view::{Document, Editor, View};
use helix_view::{
graphics::{Color, Modifier, Rect, Style},
Document, Editor, View,
};

use std::path::{Path, PathBuf};

Expand Down
10 changes: 5 additions & 5 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
widgets::{Block, BorderType, Borders},
};

Expand All @@ -14,9 +12,11 @@ use std::borrow::Cow;

use crate::ui::{Prompt, PromptEvent};
use helix_core::Position;
use helix_view::editor::Action;
use helix_view::Editor;
use tui::terminal::CursorKind;
use helix_view::{
editor::Action,
graphics::{Color, CursorKind, Rect, Style},
Editor,
};

pub struct Picker<T> {
options: Vec<T>,
Expand Down
11 changes: 5 additions & 6 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
};
use tui::buffer::Buffer as Surface;

use std::borrow::Cow;

use helix_core::Position;
use helix_view::Editor;
use helix_view::{
graphics::{Color, Rect, Style},
Editor,
};

// TODO: share logic with Menu, it's essentially Popup(render_fn), but render fn needs to return
// a width/height hint. maybe Popup(Box<Component>)
Expand Down
16 changes: 6 additions & 10 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crate::ui;
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use helix_core::Position;
use helix_view::{Editor, Theme};
use std::{borrow::Cow, ops::RangeFrom};
use tui::terminal::CursorKind;
use tui::buffer::Buffer as Surface;

use helix_core::{
unicode::segmentation::{GraphemeCursor, GraphemeIncomplete},
unicode::width::UnicodeWidthStr,
Position,
};
use helix_view::{
graphics::{Color, CursorKind, Margin, Modifier, Rect, Style},
Editor, Theme,
};

pub type Completion = (RangeFrom<usize>, Cow<'static, str>);
Expand Down Expand Up @@ -251,12 +254,6 @@ impl Prompt {
}
}

use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Modifier, Style},
};

const BASE_WIDTH: u16 = 30;

impl Prompt {
Expand Down Expand Up @@ -343,7 +340,6 @@ impl Prompt {
let background = theme.get("ui.help");
surface.clear_with(area, background);

use tui::layout::Margin;
text.render(
area.inner(&Margin {
vertical: 1,
Expand Down
11 changes: 5 additions & 6 deletions helix-term/src/ui/text.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::compositor::{Component, Compositor, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use tui::{
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Style},
};
use tui::buffer::Buffer as Surface;

use std::borrow::Cow;

use helix_core::Position;
use helix_view::Editor;
use helix_view::{
graphics::{Color, Rect, Style},
Editor,
};

pub struct Text {
contents: String,
Expand Down
1 change: 1 addition & 0 deletions helix-tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ unicode-segmentation = "1.2"
unicode-width = "0.1"
crossterm = { version = "0.20", optional = true }
serde = { version = "1", "optional" = true, features = ["derive"]}
helix-view = { path = "../helix-view", features = ["term"] }
helix-core = { version = "0.2", path = "../helix-core" }
35 changes: 2 additions & 33 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use crate::{
backend::Backend,
buffer::Cell,
layout::Rect,
style::{Color, Modifier},
terminal::CursorKind,
};
use crate::{backend::Backend, buffer::Cell};
use crossterm::{
cursor::{CursorShape, Hide, MoveTo, SetCursorShape, Show},
execute, queue,
Expand All @@ -14,6 +8,7 @@ use crossterm::{
},
terminal::{self, Clear, ClearType},
};
use helix_view::graphics::{Color, CursorKind, Modifier, Rect};
use std::io::{self, Write};

pub struct CrosstermBackend<W: Write> {
Expand Down Expand Up @@ -133,32 +128,6 @@ fn map_error(error: crossterm::Result<()>) -> io::Result<()> {
error.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
}

impl From<Color> for CColor {
fn from(color: Color) -> Self {
match color {
Color::Reset => CColor::Reset,
Color::Black => CColor::Black,
Color::Red => CColor::DarkRed,
Color::Green => CColor::DarkGreen,
Color::Yellow => CColor::DarkYellow,
Color::Blue => CColor::DarkBlue,
Color::Magenta => CColor::DarkMagenta,
Color::Cyan => CColor::DarkCyan,
Color::Gray => CColor::Grey,
Color::DarkGray => CColor::DarkGrey,
Color::LightRed => CColor::Red,
Color::LightGreen => CColor::Green,
Color::LightBlue => CColor::Blue,
Color::LightYellow => CColor::Yellow,
Color::LightMagenta => CColor::Magenta,
Color::LightCyan => CColor::Cyan,
Color::White => CColor::White,
Color::Indexed(i) => CColor::AnsiValue(i),
Color::Rgb(r, g, b) => CColor::Rgb { r, g, b },
}
}
}

#[derive(Debug)]
struct ModifierDiff {
pub from: Modifier,
Expand Down
4 changes: 2 additions & 2 deletions helix-tui/src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io;

use crate::buffer::Cell;
use crate::layout::Rect;
use crate::terminal::CursorKind;

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

#[cfg(feature = "crossterm")]
mod crossterm;
Expand Down
3 changes: 1 addition & 2 deletions helix-tui/src/backend/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{
backend::Backend,
buffer::{Buffer, Cell},
layout::Rect,
terminal::CursorKind,
};
use helix_view::graphics::{CursorKind, Rect};
use std::{fmt::Write, io};
use unicode_width::UnicodeWidthStr;

Expand Down
Loading