Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsim-msft committed Jun 24, 2021
1 parent 7235edd commit 3e0b7fe
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 41 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

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
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
3 changes: 2 additions & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use helix_core::{
use helix_lsp::LspProgressMap;
use helix_view::{
document::Mode,
input::{KeyCode, KeyEvent, KeyModifiers}
graphics::{CursorKind, Rect, Color, Modifier, Style},
input::KeyEvent,
keyboard::{KeyCode, KeyModifiers},
Document, Editor, Theme, View
};
use std::borrow::Cow;
Expand Down
7 changes: 3 additions & 4 deletions helix-tui/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ impl Default for Cell {
///
/// ```
/// use helix_tui::buffer::{Buffer, Cell};
/// use helix_tui::layout::Rect;
/// use helix_tui::style::{Color, Style, Modifier};
/// use helix_view::graphics::{Rect, Color, Style, Modifier};
///
/// let mut buf = Buffer::empty(Rect{x: 0, y: 0, width: 10, height: 5});
/// buf.get_mut(0, 2).set_symbol("x");
Expand Down Expand Up @@ -191,7 +190,7 @@ impl Buffer {
///
/// ```
/// # use helix_tui::buffer::Buffer;
/// # use helix_tui::layout::Rect;
/// # use helix_view::graphics::Rect;
/// let rect = Rect::new(200, 100, 10, 10);
/// let buffer = Buffer::empty(rect);
/// // Global coordinates to the top corner of this buffer's area
Expand Down Expand Up @@ -223,7 +222,7 @@ impl Buffer {
///
/// ```
/// # use helix_tui::buffer::Buffer;
/// # use helix_tui::layout::Rect;
/// # use helix_view::graphics::Rect;
/// let rect = Rect::new(200, 100, 10, 10);
/// let buffer = Buffer::empty(rect);
/// assert_eq!(buffer.pos_of(0), (200, 100));
Expand Down
3 changes: 2 additions & 1 deletion helix-tui/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl Layout {
///
/// # Examples
/// ```
/// # use helix_tui::layout::{Rect, Constraint, Direction, Layout};
/// # use helix_tui::layout::{Constraint, Direction, Layout};
/// # use helix_view::graphics::Rect;
/// let chunks = Layout::default()
/// .direction(Direction::Vertical)
/// .constraints([Constraint::Length(5), Constraint::Min(0)].as_ref())
Expand Down
14 changes: 7 additions & 7 deletions helix-tui/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! ```rust
//! # use helix_tui::widgets::Block;
//! # use helix_tui::text::{Span, Spans};
//! # use helix_tui::style::{Color, Style};
//! # use helix_view::graphics::{Color, Style};
//! // A simple string with no styling.
//! // Converted to Spans(vec![
//! // Span { content: Cow::Borrowed("My title"), style: Style { .. } }
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<'a> Span<'a> {
///
/// ```rust
/// # use helix_tui::text::Span;
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
/// Span::styled("My text", style);
/// Span::styled(String::from("My text"), style);
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<'a> Span<'a> {
///
/// ```rust
/// # use helix_tui::text::{Span, StyledGrapheme};
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// # use std::iter::Iterator;
/// let style = Style::default().fg(Color::Yellow);
/// let span = Span::styled("Text", style);
Expand Down Expand Up @@ -211,7 +211,7 @@ impl<'a> Spans<'a> {
///
/// ```rust
/// # use helix_tui::text::{Span, Spans};
/// # use helix_tui::style::{Color, Style};
/// # use helix_view::graphics::{Color, Style};
/// let spans = Spans::from(vec![
/// Span::styled("My", Style::default().fg(Color::Yellow)),
/// Span::raw(" text"),
Expand Down Expand Up @@ -265,7 +265,7 @@ impl<'a> From<Spans<'a>> for String {
///
/// ```rust
/// # use helix_tui::text::Text;
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
///
/// // An initial two lines of `Text` built from a `&str`
Expand Down Expand Up @@ -319,7 +319,7 @@ impl<'a> Text<'a> {
///
/// ```rust
/// # use helix_tui::text::Text;
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
/// Text::styled("The first line\nThe second line", style);
/// Text::styled(String::from("The first line\nThe second line"), style);
Expand Down Expand Up @@ -369,7 +369,7 @@ impl<'a> Text<'a> {
///
/// ```rust
/// # use helix_tui::text::Text;
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// let style = Style::default().fg(Color::Yellow).add_modifier(Modifier::ITALIC);
/// let mut raw_text = Text::raw("The first line\nThe second line");
/// let styled_text = Text::styled(String::from("The first line\nThe second line"), style);
Expand Down
3 changes: 1 addition & 2 deletions helix-tui/src/widgets/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl BorderType {
///
/// ```
/// # use helix_tui::widgets::{Block, BorderType, Borders};
/// # use helix_tui::style::{Style, Color};
/// # use helix_view::graphics::{Style, Color};
/// Block::default()
/// .title("Block")
/// .borders(Borders::LEFT | Borders::RIGHT)
Expand Down Expand Up @@ -211,7 +211,6 @@ impl<'a> Widget for Block<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::layout::Rect;

#[test]
fn inner_takes_into_account_the_borders() {
Expand Down
2 changes: 1 addition & 1 deletion helix-tui/src/widgets/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment)
/// ```
/// # use helix_tui::text::{Text, Spans, Span};
/// # use helix_tui::widgets::{Block, Borders, Paragraph, Wrap};
/// # use helix_tui::style::{Style, Color, Modifier};
/// # use helix_tui::layout::{Alignment};
/// # use helix_view::graphics::{Style, Color, Modifier};
/// let text = vec![
/// Spans::from(vec![
/// Span::raw("First"),
Expand Down
6 changes: 3 additions & 3 deletions helix-tui/src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use helix_view::graphics::{Rect, Style};
/// It can be created from anything that can be converted to a [`Text`].
/// ```rust
/// # use helix_tui::widgets::Cell;
/// # use helix_tui::style::{Style, Modifier};
/// # use helix_tui::text::{Span, Spans, Text};
/// # use helix_view::graphics::{Style, Modifier};
/// Cell::from("simple string");
///
/// Cell::from(Span::from("span"));
Expand Down Expand Up @@ -74,7 +74,7 @@ where
/// But if you need a bit more control over individual cells, you can explicity create [`Cell`]s:
/// ```rust
/// # use helix_tui::widgets::{Row, Cell};
/// # use helix_tui::style::{Style, Color};
/// # use helix_view::graphics::{Style, Color};
/// Row::new(vec![
/// Cell::from("Cell1"),
/// Cell::from("Cell2").style(Style::default().fg(Color::Yellow)),
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'a> Row<'a> {
/// ```rust
/// # use helix_tui::widgets::{Block, Borders, Table, Row, Cell};
/// # use helix_tui::layout::Constraint;
/// # use helix_tui::style::{Style, Color, Modifier};
/// # use helix_view::graphics::{Style, Color, Modifier};
/// # use helix_tui::text::{Text, Spans, Span};
/// Table::new(vec![
/// // Row can be created from simple strings.
Expand Down
3 changes: 3 additions & 0 deletions helix-view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ toml = "0.5"
log = "~0.4"

which = "4.1"

[dev-dependencies]
helix-tui = { path = "../helix-tui" }
20 changes: 9 additions & 11 deletions helix-view/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bitflags! {
/// ## Examples
///
/// ```rust
/// # use helix_tui::style::Modifier;
/// # use helix_view::graphics::Modifier;
///
/// let m = Modifier::BOLD | Modifier::ITALIC;
/// ```
Expand All @@ -213,7 +213,7 @@ bitflags! {
/// Style let you control the main characteristics of the displayed elements.
///
/// ```rust
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Color, Modifier, Style};
/// Style::default()
/// .fg(Color::Black)
/// .bg(Color::Green)
Expand All @@ -225,9 +225,8 @@ bitflags! {
/// just S3.
///
/// ```rust
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Rect, Color, Modifier, Style};
/// # use helix_tui::buffer::Buffer;
/// # use helix_tui::layout::Rect;
/// let styles = [
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
/// Style::default().bg(Color::Red),
Expand All @@ -252,9 +251,8 @@ bitflags! {
/// reset all properties until that point use [`Style::reset`].
///
/// ```
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::graphics::{Rect, Color, Modifier, Style};
/// # use helix_tui::buffer::Buffer;
/// # use helix_tui::layout::Rect;
/// let styles = [
/// Style::default().fg(Color::Blue).add_modifier(Modifier::BOLD | Modifier::ITALIC),
/// Style::reset().fg(Color::Yellow),
Expand Down Expand Up @@ -309,7 +307,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_tui::style::{Color, Style};
/// # use helix_view::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 @@ -324,7 +322,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_tui::style::{Color, Style};
/// # use helix_view::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 @@ -341,7 +339,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::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 @@ -361,7 +359,7 @@ impl Style {
/// ## Examples
///
/// ```rust
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::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 @@ -379,7 +377,7 @@ impl Style {
///
/// ## Examples
/// ```
/// # use helix_tui::style::{Color, Modifier, Style};
/// # use helix_view::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: 8 additions & 5 deletions helix-view/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Input event handling, currently backed by crossterm.
use anyhow::{anyhow, Error};
use crossterm::event;
use serde::de::{self, Deserialize, Deserializer};
use std::fmt;

pub use crossterm::event::{KeyCode, KeyModifiers};
use crate::keyboard::{KeyCode, KeyModifiers};

/// Represents a key event.
// We use a newtype here because we want to customize Deserialize and Display.
Expand Down Expand Up @@ -132,9 +131,13 @@ impl<'de> Deserialize<'de> for KeyEvent {
}
}

impl From<event::KeyEvent> for KeyEvent {
fn from(event::KeyEvent { code, modifiers }: event::KeyEvent) -> KeyEvent {
KeyEvent { code, modifiers }
#[cfg(feature = "term")]
impl From<crossterm::event::KeyEvent> for KeyEvent {
fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> KeyEvent {
KeyEvent {
code: code.into(),
modifiers: modifiers.into()
}
}
}

Expand Down
Loading

0 comments on commit 3e0b7fe

Please sign in to comment.