Skip to content

Commit

Permalink
reverse the dependency between helix-tui and helix-view by moving a f…
Browse files Browse the repository at this point in the history
…iew types to view
  • Loading branch information
Kethku committed Jun 24, 2021
1 parent 394629a commit 76806e0
Show file tree
Hide file tree
Showing 33 changed files with 576 additions and 653 deletions.
3 changes: 2 additions & 1 deletion 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
8 changes: 5 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 +33,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/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
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::{Rect, Color, Style},
Editor
};

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

use crossterm::{
Expand All @@ -22,9 +26,6 @@ use crossterm::{
use tui::{
backend::CrosstermBackend,
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Modifier, Style},
terminal::CursorKind,
};

pub struct EditorView {
Expand Down
7 changes: 4 additions & 3 deletions helix-term/src/ui/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ 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 std::{borrow::Cow, sync::Arc};

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

pub struct Markdown {
contents: String,
Expand Down
7 changes: 4 additions & 3 deletions helix-term/src/ui/menu.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::Table,
};

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

use helix_core::Position;
use helix_view::Editor;
use helix_view::{
graphics::{Rect, Color, 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::{Rect, Color, Modifier, 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::{CursorKind, Rect, Color, 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::{Rect, Color, 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,15 +1,18 @@
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::{
Position,
unicode::segmentation::{GraphemeCursor, GraphemeIncomplete},
unicode::width::UnicodeWidthStr,
};
use helix_view::{
graphics::{CursorKind, Margin, Rect, Color, Modifier, 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::{Rect, Color, 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" }
30 changes: 1 addition & 29 deletions helix-tui/src/backend/crossterm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::{
backend::Backend,
buffer::Cell,
layout::Rect,
style::{Color, Modifier},
terminal::CursorKind,
};
use crossterm::{
cursor::{CursorShape, Hide, MoveTo, SetCursorShape, Show},
Expand All @@ -15,6 +12,7 @@ use crossterm::{
terminal::{self, Clear, ClearType},
};
use std::io::{self, Write};
use helix_view::graphics::{CursorKind, Rect, Color, Modifier};

pub struct CrosstermBackend<W: Write> {
buffer: W,
Expand Down Expand Up @@ -133,32 +131,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,11 +1,10 @@
use crate::{
backend::Backend,
buffer::{Buffer, Cell},
layout::Rect,
terminal::CursorKind,
};
use std::{fmt::Write, io};
use unicode_width::UnicodeWidthStr;
use helix_view::graphics::{CursorKind, Rect};

/// A backend used for the integration tests.
#[derive(Debug)]
Expand Down
8 changes: 3 additions & 5 deletions helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Span, Spans},
};
use crate::text::{Span, Spans};
use std::cmp::min;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;

use helix_view::graphics::{Rect, Color, Modifier, Style};

/// A buffer cell
#[derive(Debug, Clone, PartialEq)]
pub struct Cell {
Expand Down
Loading

0 comments on commit 76806e0

Please sign in to comment.