mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-24 10:26:18 +04:00
Extract compositor & jobs into helix-view
This commit is contained in:
parent
18381fcbc8
commit
11b8f068da
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -827,6 +827,15 @@ dependencies = [
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "helix-graphics"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crossterm",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "helix-loader"
|
||||
version = "0.6.0"
|
||||
@ -906,7 +915,7 @@ dependencies = [
|
||||
"cassowary",
|
||||
"crossterm",
|
||||
"helix-core",
|
||||
"helix-view",
|
||||
"helix-graphics",
|
||||
"serde",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
@ -937,7 +946,9 @@ dependencies = [
|
||||
"futures-util",
|
||||
"helix-core",
|
||||
"helix-dap",
|
||||
"helix-graphics",
|
||||
"helix-lsp",
|
||||
"helix-tui",
|
||||
"log",
|
||||
"once_cell",
|
||||
"serde",
|
||||
|
@ -4,6 +4,7 @@ members = [
|
||||
"helix-view",
|
||||
"helix-term",
|
||||
"helix-tui",
|
||||
"helix-graphics",
|
||||
"helix-ui",
|
||||
"helix-lsp",
|
||||
"helix-dap",
|
||||
|
23
helix-graphics/Cargo.toml
Normal file
23
helix-graphics/Cargo.toml
Normal file
@ -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.23", 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" }
|
@ -15,13 +15,16 @@
|
||||
|
||||
use crate::{
|
||||
args::Args,
|
||||
compositor::{Compositor, Event},
|
||||
config::Config,
|
||||
job::Jobs,
|
||||
keymap::Keymaps,
|
||||
ui::{self, overlay::overlayed},
|
||||
};
|
||||
|
||||
use helix_view::{
|
||||
compositor::{Compositor, Event},
|
||||
job::Jobs,
|
||||
};
|
||||
|
||||
use std::{
|
||||
io::{stdin, stdout, Write},
|
||||
sync::Arc,
|
||||
@ -233,7 +236,7 @@ fn render(&mut self) {
|
||||
|
||||
// let area = *surface.area();
|
||||
|
||||
let mut render_cx = crate::compositor::RenderContext {
|
||||
let mut render_cx = helix_view::compositor::RenderContext {
|
||||
editor: &self.editor,
|
||||
surface,
|
||||
scroll: None,
|
||||
@ -384,13 +387,13 @@ pub async fn handle_signals(&mut self, signal: i32) {
|
||||
}
|
||||
|
||||
pub fn handle_idle_timeout(&mut self) {
|
||||
use crate::compositor::EventResult;
|
||||
use helix_view::compositor::EventResult;
|
||||
let editor_view = self
|
||||
.compositor
|
||||
.find::<ui::EditorView>()
|
||||
.expect("expected at least one EditorView");
|
||||
|
||||
let mut cx = crate::compositor::Context {
|
||||
let mut cx = helix_view::compositor::Context {
|
||||
editor: &mut self.editor,
|
||||
jobs: &mut self.jobs,
|
||||
};
|
||||
@ -403,7 +406,7 @@ pub fn handle_terminal_events(
|
||||
&mut self,
|
||||
event: Option<Result<CrosstermEvent, crossterm::ErrorKind>>,
|
||||
) {
|
||||
let mut cx = crate::compositor::Context {
|
||||
let mut cx = helix_view::compositor::Context {
|
||||
editor: &mut self.editor,
|
||||
jobs: &mut self.jobs,
|
||||
};
|
||||
|
@ -40,6 +40,11 @@
|
||||
Document, DocumentId, Editor, ViewId,
|
||||
};
|
||||
|
||||
use helix_view::{
|
||||
compositor::{self, Component, Compositor},
|
||||
job::{self, Job, Jobs},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, bail, ensure, Context as _};
|
||||
use fuzzy_matcher::FuzzyMatcher;
|
||||
use insert::*;
|
||||
@ -47,11 +52,9 @@
|
||||
|
||||
use crate::{
|
||||
args,
|
||||
compositor::{self, Component, Compositor},
|
||||
ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent},
|
||||
};
|
||||
|
||||
use crate::job::{self, Job, Jobs};
|
||||
use futures_util::{FutureExt, StreamExt};
|
||||
use std::{collections::HashMap, fmt, future::Future};
|
||||
use std::{collections::HashSet, num::NonZeroUsize};
|
||||
@ -74,7 +77,7 @@ pub struct Context<'a> {
|
||||
pub count: Option<NonZeroUsize>,
|
||||
pub editor: &'a mut Editor,
|
||||
|
||||
pub callback: Option<crate::compositor::Callback>,
|
||||
pub callback: Option<helix_view::compositor::Callback>,
|
||||
pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
|
||||
pub jobs: &'a mut Jobs,
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use super::{Context, Editor};
|
||||
use crate::{
|
||||
compositor::{self, Compositor},
|
||||
job::{Callback, Jobs},
|
||||
ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent, Text},
|
||||
};
|
||||
use crate::ui::{self, overlay::overlayed, FilePicker, Picker, Popup, Prompt, PromptEvent, Text};
|
||||
use helix_core::syntax::{DebugArgumentValue, DebugConfigCompletion};
|
||||
use helix_dap::{self as dap, Client};
|
||||
use helix_lsp::block_on;
|
||||
use helix_view::editor::Breakpoint;
|
||||
use helix_view::{
|
||||
compositor::{self, Compositor},
|
||||
job::{Callback, Jobs},
|
||||
};
|
||||
|
||||
use serde_json::{to_value, Value};
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
|
@ -9,10 +9,8 @@
|
||||
use helix_core::Selection;
|
||||
use helix_view::editor::Action;
|
||||
|
||||
use crate::{
|
||||
compositor::{self, Compositor},
|
||||
ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, PromptEvent},
|
||||
};
|
||||
use crate::ui::{self, overlay::overlayed, FileLocation, FilePicker, Popup, PromptEvent};
|
||||
use helix_view::compositor::{self, Compositor};
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
@ -4,10 +4,8 @@
|
||||
pub mod application;
|
||||
pub mod args;
|
||||
pub mod commands;
|
||||
pub mod compositor;
|
||||
pub mod config;
|
||||
pub mod health;
|
||||
pub mod job;
|
||||
pub mod keymap;
|
||||
pub mod ui;
|
||||
pub use keymap::macros::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use helix_view::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use helix_view::editor::CompleteAction;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
commands,
|
||||
compositor::{Component, Context, Event, EventResult, RenderContext},
|
||||
key,
|
||||
commands, key,
|
||||
keymap::{KeymapResult, Keymaps},
|
||||
ui::{Completion, ProgressSpinners},
|
||||
};
|
||||
|
||||
use helix_view::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
|
||||
use helix_core::{
|
||||
coords_at_pos, encoding,
|
||||
graphemes::{
|
||||
@ -928,7 +928,7 @@ pub fn clear_completion(&mut self, editor: &mut Editor) {
|
||||
editor.clear_idle_timer(); // don't retrigger
|
||||
}
|
||||
|
||||
pub fn handle_idle_timeout(&mut self, cx: &mut crate::compositor::Context) -> EventResult {
|
||||
pub fn handle_idle_timeout(&mut self, cx: &mut helix_view::compositor::Context) -> EventResult {
|
||||
if self.completion.is_some()
|
||||
|| !cx.editor.config().auto_completion
|
||||
|| doc!(cx.editor).mode != Mode::Insert
|
||||
@ -1163,7 +1163,7 @@ impl Component for EditorView {
|
||||
fn handle_event(
|
||||
&mut self,
|
||||
event: Event,
|
||||
context: &mut crate::compositor::Context,
|
||||
context: &mut helix_view::compositor::Context,
|
||||
) -> EventResult {
|
||||
let mut cx = commands::Context {
|
||||
editor: context.editor,
|
||||
|
@ -1,40 +0,0 @@
|
||||
use crate::compositor::{Component, RenderContext};
|
||||
use helix_view::graphics::{Margin, Rect};
|
||||
use helix_view::info::Info;
|
||||
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
||||
|
||||
impl Component for Info {
|
||||
fn render(&mut self, viewport: Rect, cx: &mut RenderContext<'_>) {
|
||||
let text_style = cx.editor.theme.get("ui.text.info");
|
||||
let popup_style = cx.editor.theme.get("ui.popup.info");
|
||||
|
||||
// Calculate the area of the terminal to modify. Because we want to
|
||||
// render at the bottom right, we use the viewport's width and height
|
||||
// which evaluate to the most bottom right coordinate.
|
||||
let width = self.width + 2 + 2; // +2 for border, +2 for margin
|
||||
let height = self.height + 2; // +2 for border
|
||||
let area = viewport.intersection(Rect::new(
|
||||
viewport.width.saturating_sub(width),
|
||||
viewport.height.saturating_sub(height + 2), // +2 for statusline
|
||||
width,
|
||||
height,
|
||||
));
|
||||
cx.surface.clear_with(area, popup_style);
|
||||
|
||||
let block = Block::default()
|
||||
.title(self.title.as_str())
|
||||
.borders(Borders::ALL)
|
||||
.border_style(popup_style);
|
||||
|
||||
let margin = Margin {
|
||||
vertical: 0,
|
||||
horizontal: 1,
|
||||
};
|
||||
let inner = block.inner(area).inner(&margin);
|
||||
block.render(area, cx.surface);
|
||||
|
||||
Paragraph::new(self.text.as_str())
|
||||
.style(text_style)
|
||||
.render(inner, cx.surface);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
use crate::compositor::{Component, RenderContext};
|
||||
use helix_view::compositor::{Component, RenderContext};
|
||||
use tui::text::{Span, Spans, Text};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
compositor::{Callback, Component, Compositor, Context, Event, EventResult, RenderContext},
|
||||
ctrl, key, shift,
|
||||
use crate::{ctrl, key, shift};
|
||||
use helix_view::compositor::{
|
||||
Callback, Component, Compositor, Context, Event, EventResult, RenderContext,
|
||||
};
|
||||
use tui::widgets::Table;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
mod completion;
|
||||
pub(crate) mod editor;
|
||||
mod info;
|
||||
mod markdown;
|
||||
pub mod menu;
|
||||
pub mod overlay;
|
||||
@ -31,7 +30,7 @@ pub fn prompt(
|
||||
prompt: std::borrow::Cow<'static, str>,
|
||||
history_register: Option<char>,
|
||||
completion_fn: impl FnMut(&Editor, &str) -> Vec<prompt::Completion> + 'static,
|
||||
callback_fn: impl FnMut(&mut crate::compositor::Context, &str, PromptEvent) + 'static,
|
||||
callback_fn: impl FnMut(&mut helix_view::compositor::Context, &str, PromptEvent) + 'static,
|
||||
) {
|
||||
let mut prompt = Prompt::new(prompt, history_register, completion_fn, callback_fn);
|
||||
// Calculate initial completion
|
||||
@ -56,7 +55,7 @@ pub fn regex_prompt(
|
||||
prompt,
|
||||
history_register,
|
||||
completion_fn,
|
||||
move |cx: &mut crate::compositor::Context, input: &str, event: PromptEvent| {
|
||||
move |cx: &mut helix_view::compositor::Context, input: &str, event: PromptEvent| {
|
||||
match event {
|
||||
PromptEvent::Abort => {
|
||||
let (view, doc) = current!(cx.editor);
|
||||
|
@ -4,7 +4,7 @@
|
||||
Editor,
|
||||
};
|
||||
|
||||
use crate::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
use helix_view::compositor::{Component, Context, Event, EventResult, RenderContext};
|
||||
|
||||
/// Contains a component placed in the center of the parent component
|
||||
pub struct Overlay<T> {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
compositor::{Component, Compositor, Context, Event, EventResult, RenderContext},
|
||||
ctrl, key, shift,
|
||||
ui::{self, EditorView},
|
||||
};
|
||||
use helix_view::compositor::{Component, Compositor, Context, Event, EventResult, RenderContext};
|
||||
use tui::widgets::{Block, BorderType, Borders};
|
||||
|
||||
use fuzzy_matcher::skim::SkimMatcherV2 as Matcher;
|
||||
|
@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
compositor::{Callback, Component, Context, Event, EventResult, RenderContext},
|
||||
ctrl, key,
|
||||
};
|
||||
use crate::{ctrl, key};
|
||||
use helix_view::compositor::{Callback, Component, Context, Event, EventResult, RenderContext};
|
||||
|
||||
use helix_core::Position;
|
||||
use helix_view::{
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::compositor::{Component, Compositor, Context, Event, EventResult, RenderContext};
|
||||
use helix_view::compositor::{Component, Compositor, Context, Event, EventResult, RenderContext};
|
||||
use crate::{alt, ctrl, key, shift, ui};
|
||||
use helix_view::input::KeyEvent;
|
||||
use helix_view::keyboard::KeyCode;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::compositor::{Component, RenderContext};
|
||||
use helix_view::compositor::{Component, RenderContext};
|
||||
|
||||
use helix_view::graphics::Rect;
|
||||
|
||||
|
@ -21,5 +21,5 @@ cassowary = "0.3"
|
||||
unicode-segmentation = "1.9"
|
||||
crossterm = { version = "0.23", optional = true }
|
||||
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" }
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
terminal::{self, Clear, ClearType},
|
||||
};
|
||||
use helix_view::graphics::{Color, CursorKind, Modifier, Rect};
|
||||
use helix_graphics::{Color, CursorKind, Modifier, Rect};
|
||||
use std::io::{self, Write};
|
||||
|
||||
pub struct CrosstermBackend<W: Write> {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::buffer::Cell;
|
||||
|
||||
use helix_view::graphics::{CursorKind, Rect};
|
||||
use helix_graphics::{CursorKind, Rect};
|
||||
|
||||
#[cfg(feature = "crossterm")]
|
||||
mod crossterm;
|
||||
|
@ -3,7 +3,7 @@
|
||||
buffer::{Buffer, Cell},
|
||||
};
|
||||
use helix_core::unicode::width::UnicodeWidthStr;
|
||||
use helix_view::graphics::{CursorKind, Rect};
|
||||
use helix_graphics::{CursorKind, Rect};
|
||||
use std::{fmt::Write, io};
|
||||
|
||||
/// A backend used for the integration tests.
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std::cmp::min;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use helix_view::graphics::{Color, Modifier, Rect, Style};
|
||||
use helix_graphics::{Color, Modifier, Rect, Style};
|
||||
|
||||
/// A buffer cell
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@ -87,7 +87,7 @@ fn default() -> Cell {
|
||||
///
|
||||
/// ```
|
||||
/// use helix_tui::buffer::{Buffer, Cell};
|
||||
/// use helix_view::graphics::{Rect, Color, Style, Modifier};
|
||||
/// use helix_graphics::{Rect, Color, Style, Modifier};
|
||||
///
|
||||
/// let mut buf = Buffer::empty(Rect{x: 0, y: 0, width: 10, height: 5});
|
||||
/// buf[(0, 2)].set_symbol("x");
|
||||
@ -179,7 +179,7 @@ pub fn get_mut(&mut self, x: u16, y: u16) -> Option<&mut Cell> {
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_tui::buffer::Buffer;
|
||||
/// # use helix_view::graphics::Rect;
|
||||
/// # use helix_graphics::Rect;
|
||||
/// let rect = Rect::new(200, 100, 10, 10);
|
||||
/// let buffer = Buffer::empty(rect);
|
||||
/// // Global coordinates inside the Buffer's area
|
||||
@ -204,7 +204,7 @@ pub fn in_bounds(&self, x: u16, y: u16) -> bool {
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_tui::buffer::Buffer;
|
||||
/// # use helix_view::graphics::Rect;
|
||||
/// # use helix_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
|
||||
@ -243,7 +243,7 @@ fn index_of_opt(&self, x: u16, y: u16) -> Option<usize> {
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_tui::buffer::Buffer;
|
||||
/// # use helix_view::graphics::Rect;
|
||||
/// # use helix_graphics::Rect;
|
||||
/// let rect = Rect::new(200, 100, 10, 10);
|
||||
/// let buffer = Buffer::empty(rect);
|
||||
/// assert_eq!(buffer.pos_of(0), (200, 100));
|
||||
|
@ -5,7 +5,7 @@
|
||||
use cassowary::WeightedRelation::*;
|
||||
use cassowary::{Constraint as CassowaryConstraint, Expression, Solver, Variable};
|
||||
|
||||
use helix_view::graphics::{Margin, Rect};
|
||||
use helix_graphics::{Margin, Rect};
|
||||
|
||||
#[derive(Debug, Hash, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Corner {
|
||||
@ -115,7 +115,7 @@ pub fn direction(mut self, direction: Direction) -> Layout {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # use helix_tui::layout::{Constraint, Direction, Layout};
|
||||
/// # use helix_view::graphics::Rect;
|
||||
/// # use helix_graphics::Rect;
|
||||
/// let chunks = Layout::default()
|
||||
/// .direction(Direction::Vertical)
|
||||
/// .constraints([Constraint::Length(5), Constraint::Min(0)].as_ref())
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{backend::Backend, buffer::Buffer};
|
||||
use helix_view::graphics::{CursorKind, Rect};
|
||||
use helix_graphics::{CursorKind, Rect};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -21,7 +21,7 @@
|
||||
//! ```rust
|
||||
//! # use helix_tui::widgets::Block;
|
||||
//! # use helix_tui::text::{Span, Spans};
|
||||
//! # use helix_view::graphics::{Color, Style};
|
||||
//! # use helix_graphics::{Color, Style};
|
||||
//! // A simple string with no styling.
|
||||
//! // Converted to Spans(vec![
|
||||
//! // Span { content: Cow::Borrowed("My title"), style: Style { .. } }
|
||||
@ -48,7 +48,7 @@
|
||||
//! ```
|
||||
use helix_core::line_ending::str_is_line_ending;
|
||||
use helix_core::unicode::width::UnicodeWidthStr;
|
||||
use helix_view::graphics::Style;
|
||||
use helix_graphics::Style;
|
||||
use std::borrow::Cow;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
@ -92,7 +92,7 @@ pub fn raw<T>(content: T) -> Span<'a>
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::Span;
|
||||
/// # use helix_view::graphics::{Color, Modifier, Style};
|
||||
/// # use helix_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);
|
||||
@ -121,7 +121,7 @@ pub fn width(&self) -> usize {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::{Span, StyledGrapheme};
|
||||
/// # use helix_view::graphics::{Color, Modifier, Style};
|
||||
/// # use helix_graphics::{Color, Modifier, Style};
|
||||
/// # use std::iter::Iterator;
|
||||
/// let style = Style::default().fg(Color::Yellow);
|
||||
/// let span = Span::styled("Text", style);
|
||||
@ -205,7 +205,7 @@ impl<'a> Spans<'a> {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::{Span, Spans};
|
||||
/// # use helix_view::graphics::{Color, Style};
|
||||
/// # use helix_graphics::{Color, Style};
|
||||
/// let spans = Spans::from(vec![
|
||||
/// Span::styled("My", Style::default().fg(Color::Yellow)),
|
||||
/// Span::raw(" text"),
|
||||
@ -259,7 +259,7 @@ fn from(line: Spans<'a>) -> String {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::Text;
|
||||
/// # use helix_view::graphics::{Color, Modifier, Style};
|
||||
/// # use helix_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`
|
||||
@ -307,7 +307,7 @@ pub fn raw<T>(content: T) -> Text<'a>
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::Text;
|
||||
/// # use helix_view::graphics::{Color, Modifier, Style};
|
||||
/// # use helix_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);
|
||||
@ -357,7 +357,7 @@ pub fn height(&self) -> usize {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use helix_tui::text::Text;
|
||||
/// # use helix_view::graphics::{Color, Modifier, Style};
|
||||
/// # use helix_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);
|
||||
|
@ -4,7 +4,7 @@
|
||||
text::{Span, Spans},
|
||||
widgets::{Borders, Widget},
|
||||
};
|
||||
use helix_view::graphics::{Rect, Style};
|
||||
use helix_graphics::{Rect, Style};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum BorderType {
|
||||
@ -32,7 +32,7 @@ pub fn line_symbols(border_type: Self) -> line::Set {
|
||||
///
|
||||
/// ```
|
||||
/// # use helix_tui::widgets::{Block, BorderType, Borders};
|
||||
/// # use helix_view::graphics::{Style, Color};
|
||||
/// # use helix_graphics::{Style, Color};
|
||||
/// Block::default()
|
||||
/// .title("Block")
|
||||
/// .borders(Borders::LEFT | Borders::RIGHT)
|
||||
|
@ -23,7 +23,7 @@
|
||||
use crate::buffer::Buffer;
|
||||
use bitflags::bitflags;
|
||||
|
||||
use helix_view::graphics::Rect;
|
||||
use helix_graphics::Rect;
|
||||
|
||||
bitflags! {
|
||||
/// Bitflags that can be composed to set the visible borders essentially on the block widget.
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
};
|
||||
use helix_core::unicode::width::UnicodeWidthStr;
|
||||
use helix_view::graphics::{Rect, Style};
|
||||
use helix_graphics::{Rect, Style};
|
||||
use std::iter;
|
||||
|
||||
fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 {
|
||||
@ -27,7 +27,7 @@ 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::layout::{Alignment};
|
||||
/// # use helix_view::graphics::{Style, Color, Modifier};
|
||||
/// # use helix_graphics::{Style, Color, Modifier};
|
||||
/// let text = vec![
|
||||
/// Spans::from(vec![
|
||||
/// Span::raw("First"),
|
||||
|
@ -10,7 +10,7 @@
|
||||
{Expression, Solver},
|
||||
};
|
||||
use helix_core::unicode::width::UnicodeWidthStr;
|
||||
use helix_view::graphics::{Rect, Style};
|
||||
use helix_graphics::{Rect, Style};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A [`Cell`] contains the [`Text`] to be displayed in a [`Row`] of a [`Table`].
|
||||
@ -19,7 +19,7 @@
|
||||
/// ```rust
|
||||
/// # use helix_tui::widgets::Cell;
|
||||
/// # use helix_tui::text::{Span, Spans, Text};
|
||||
/// # use helix_view::graphics::{Style, Modifier};
|
||||
/// # use helix_graphics::{Style, Modifier};
|
||||
/// Cell::from("simple string");
|
||||
///
|
||||
/// Cell::from(Span::from("span"));
|
||||
@ -71,7 +71,7 @@ fn from(content: T) -> Cell<'a> {
|
||||
/// But if you need a bit more control over individual cells, you can explicitly create [`Cell`]s:
|
||||
/// ```rust
|
||||
/// # use helix_tui::widgets::{Row, Cell};
|
||||
/// # use helix_view::graphics::{Style, Color};
|
||||
/// # use helix_graphics::{Style, Color};
|
||||
/// Row::new(vec![
|
||||
/// Cell::from("Cell1"),
|
||||
/// Cell::from("Cell2").style(Style::default().fg(Color::Yellow)),
|
||||
@ -134,7 +134,7 @@ fn total_height(&self) -> u16 {
|
||||
/// ```rust
|
||||
/// # use helix_tui::widgets::{Block, Borders, Table, Row, Cell};
|
||||
/// # use helix_tui::layout::Constraint;
|
||||
/// # use helix_view::graphics::{Style, Color, Modifier};
|
||||
/// # use helix_graphics::{Style, Color, Modifier};
|
||||
/// # use helix_tui::text::{Text, Spans, Span};
|
||||
/// Table::new(vec![
|
||||
/// // Row can be created from simple strings.
|
||||
|
@ -14,18 +14,20 @@ homepage = "https://helix-editor.com"
|
||||
lsp = ["helix-lsp", "tokio-runtime"]
|
||||
dap = ["helix-dap", "tokio-stream", "tokio-runtime"]
|
||||
tokio-runtime = ["tokio"]
|
||||
term = ["crossterm"]
|
||||
term = ["crossterm", "tui"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.3"
|
||||
anyhow = "1"
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-graphics = { version = "0.6", path = "../helix-graphics" }
|
||||
helix-lsp = { version = "0.6", path = "../helix-lsp", optional = true }
|
||||
helix-dap = { version = "0.6", path = "../helix-dap", optional = true }
|
||||
tokio-stream = { version = "0.1", optional = true }
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"], optional = true }
|
||||
|
||||
crossterm = { version = "0.23", optional = true }
|
||||
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"], optional = true }
|
||||
|
||||
# Conversion traits
|
||||
once_cell = "1.10"
|
||||
@ -49,7 +51,3 @@ which = "4.2"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
clipboard-win = { version = "4.4", features = ["std"] }
|
||||
|
||||
# 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" }
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Each component declares it's own size constraints and gets fitted based on it's parent.
|
||||
// Q: how does this work with popups?
|
||||
// cursive does compositor.screen_mut().add_layer_at(pos::absolute(x, y), <component>)
|
||||
use crate::graphics::{CursorKind, Rect};
|
||||
use helix_core::Position;
|
||||
use helix_view::graphics::{CursorKind, Rect};
|
||||
|
||||
pub type Callback = Box<dyn FnOnce(&mut Compositor, &mut Context)>;
|
||||
|
||||
@ -13,15 +13,16 @@ pub enum EventResult {
|
||||
}
|
||||
|
||||
use crate::job::Jobs;
|
||||
use helix_view::Editor;
|
||||
use crate::Editor;
|
||||
|
||||
pub use helix_view::input::Event;
|
||||
pub use crate::input::Event;
|
||||
|
||||
pub struct Context<'a> {
|
||||
pub editor: &'a mut Editor,
|
||||
pub jobs: &'a mut Jobs,
|
||||
}
|
||||
|
||||
#[cfg(feature = "term")]
|
||||
mod term {
|
||||
use super::*;
|
||||
pub use tui::buffer::Buffer as Surface;
|
||||
@ -33,6 +34,7 @@ pub struct RenderContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "term")]
|
||||
pub use term::*;
|
||||
|
||||
pub trait Component: Any + AnyComponent {
|
||||
@ -76,7 +78,8 @@ pub struct Compositor {
|
||||
layers: Vec<Box<dyn Component>>,
|
||||
area: Rect,
|
||||
|
||||
pub(crate) last_picker: Option<Box<dyn Component>>,
|
||||
// TODO: remove pub
|
||||
pub last_picker: Option<Box<dyn Component>>,
|
||||
}
|
||||
|
||||
impl Compositor {
|
@ -73,3 +73,47 @@ pub fn from_registers(registers: &Registers) -> Self {
|
||||
infobox
|
||||
}
|
||||
}
|
||||
|
||||
// term
|
||||
|
||||
use crate::{
|
||||
compositor::{Component, RenderContext},
|
||||
graphics::{Margin, Rect},
|
||||
};
|
||||
use tui::widgets::{Block, Borders, Paragraph, Widget};
|
||||
|
||||
impl Component for Info {
|
||||
fn render(&mut self, viewport: Rect, cx: &mut RenderContext<'_>) {
|
||||
let text_style = cx.editor.theme.get("ui.text.info");
|
||||
let popup_style = cx.editor.theme.get("ui.popup.info");
|
||||
|
||||
// Calculate the area of the terminal to modify. Because we want to
|
||||
// render at the bottom right, we use the viewport's width and height
|
||||
// which evaluate to the most bottom right coordinate.
|
||||
let width = self.width + 2 + 2; // +2 for border, +2 for margin
|
||||
let height = self.height + 2; // +2 for border
|
||||
let area = viewport.intersection(Rect::new(
|
||||
viewport.width.saturating_sub(width),
|
||||
viewport.height.saturating_sub(height + 2), // +2 for statusline
|
||||
width,
|
||||
height,
|
||||
));
|
||||
cx.surface.clear_with(area, popup_style);
|
||||
|
||||
let block = Block::default()
|
||||
.title(self.title.as_str())
|
||||
.borders(Borders::ALL)
|
||||
.border_style(popup_style);
|
||||
|
||||
let margin = Margin {
|
||||
vertical: 0,
|
||||
horizontal: 1,
|
||||
};
|
||||
let inner = block.inner(area).inner(&margin);
|
||||
block.render(area, cx.surface);
|
||||
|
||||
Paragraph::new(self.text.as_str())
|
||||
.style(text_style)
|
||||
.render(inner, cx.surface);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use helix_view::Editor;
|
||||
|
||||
use crate::compositor::Compositor;
|
||||
use crate::Editor;
|
||||
|
||||
use futures_util::future::{self, BoxFuture, Future, FutureExt};
|
||||
use futures_util::stream::{FuturesUnordered, StreamExt};
|
@ -6,10 +6,12 @@ pub mod backend {
|
||||
pub mod term;
|
||||
}
|
||||
pub mod clipboard;
|
||||
pub mod compositor;
|
||||
pub mod document;
|
||||
pub mod editor;
|
||||
pub mod graphics;
|
||||
pub use helix_graphics as graphics;
|
||||
pub mod gutter;
|
||||
pub mod job;
|
||||
pub mod handlers {
|
||||
#[cfg(feature = "dap")]
|
||||
pub mod dap;
|
||||
|
Loading…
Reference in New Issue
Block a user