mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 19:03:30 +04:00
Move ui modules under a ui:: namespace.
This commit is contained in:
parent
ef0d062b1f
commit
7dc24a25ba
@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
||||||
|
|
||||||
use crate::compositor::{Component, Compositor, EventResult};
|
use crate::compositor::Compositor;
|
||||||
use crate::editor_view::EditorView;
|
use crate::ui;
|
||||||
use crate::prompt::Prompt;
|
|
||||||
|
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
|
||||||
@ -19,18 +18,11 @@
|
|||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
event::{Event, EventStream},
|
||||||
event::{read, Event, EventStream, KeyCode, KeyEvent},
|
execute, terminal,
|
||||||
execute, queue,
|
|
||||||
terminal::{self, disable_raw_mode, enable_raw_mode},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use tui::{
|
use tui::{backend::CrosstermBackend, layout::Rect};
|
||||||
backend::CrosstermBackend,
|
|
||||||
buffer::Buffer as Surface,
|
|
||||||
layout::Rect,
|
|
||||||
style::{Color, Modifier, Style},
|
|
||||||
};
|
|
||||||
|
|
||||||
type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
|
type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
|
||||||
|
|
||||||
@ -43,12 +35,6 @@ pub struct Application {
|
|||||||
language_server: helix_lsp::Client,
|
language_server: helix_lsp::Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: temp
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn text_color() -> Style {
|
|
||||||
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
|
pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
|
||||||
let backend = CrosstermBackend::new(stdout());
|
let backend = CrosstermBackend::new(stdout());
|
||||||
@ -61,14 +47,13 @@ pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut compositor = Compositor::new();
|
let mut compositor = Compositor::new();
|
||||||
compositor.push(Box::new(EditorView::new()));
|
compositor.push(Box::new(ui::EditorView::new()));
|
||||||
|
|
||||||
let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
|
let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
|
||||||
|
|
||||||
let mut app = Self {
|
let mut app = Self {
|
||||||
editor,
|
editor,
|
||||||
terminal,
|
terminal,
|
||||||
// TODO; move to state
|
|
||||||
compositor,
|
compositor,
|
||||||
|
|
||||||
executor,
|
executor,
|
||||||
@ -213,7 +198,7 @@ pub async fn handle_language_server_message(&mut self, call: Option<helix_lsp::C
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&mut self) -> Result<(), Error> {
|
pub async fn run(&mut self) -> Result<(), Error> {
|
||||||
enable_raw_mode()?;
|
terminal::enable_raw_mode()?;
|
||||||
|
|
||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
|
||||||
@ -223,7 +208,7 @@ pub async fn run(&mut self) -> Result<(), Error> {
|
|||||||
let hook = std::panic::take_hook();
|
let hook = std::panic::take_hook();
|
||||||
std::panic::set_hook(Box::new(move |info| {
|
std::panic::set_hook(Box::new(move |info| {
|
||||||
execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
|
execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
|
||||||
disable_raw_mode();
|
terminal::disable_raw_mode();
|
||||||
hook(info);
|
hook(info);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -234,7 +219,7 @@ pub async fn run(&mut self) -> Result<(), Error> {
|
|||||||
|
|
||||||
execute!(stdout, terminal::LeaveAlternateScreen)?;
|
execute!(stdout, terminal::LeaveAlternateScreen)?;
|
||||||
|
|
||||||
disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::compositor::Compositor;
|
use crate::compositor::Compositor;
|
||||||
use crate::prompt::Prompt;
|
use crate::ui::Prompt;
|
||||||
|
|
||||||
use helix_view::{
|
use helix_view::{
|
||||||
document::Mode,
|
document::Mode,
|
||||||
|
0
helix-term/src/helix.log
Normal file
0
helix-term/src/helix.log
Normal file
@ -3,10 +3,9 @@
|
|||||||
mod application;
|
mod application;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod compositor;
|
mod compositor;
|
||||||
mod editor_view;
|
|
||||||
mod keymap;
|
mod keymap;
|
||||||
mod prompt;
|
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
use application::Application;
|
use application::Application;
|
||||||
|
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
use crate::application::text_color;
|
|
||||||
use crate::commands;
|
use crate::commands;
|
||||||
use crate::compositor::{Component, Compositor, EventResult};
|
use crate::compositor::{Component, Compositor, Context, EventResult};
|
||||||
use crate::keymap::{self, Keymaps};
|
use crate::keymap::{self, Keymaps};
|
||||||
|
use crate::ui::text_color;
|
||||||
|
|
||||||
|
use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
|
||||||
|
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
cursor,
|
||||||
event::{read, Event, EventStream, KeyCode, KeyEvent},
|
event::{read, Event, EventStream, KeyCode, KeyEvent},
|
||||||
};
|
};
|
||||||
use helix_view::{document::Mode, Document, Editor, Theme, View};
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use tui::{
|
use tui::{
|
||||||
backend::CrosstermBackend,
|
backend::CrosstermBackend,
|
||||||
buffer::Buffer as Surface,
|
buffer::Buffer as Surface,
|
||||||
@ -15,8 +18,6 @@
|
|||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
};
|
};
|
||||||
|
|
||||||
use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
|
|
||||||
|
|
||||||
pub struct EditorView {
|
pub struct EditorView {
|
||||||
keymap: Keymaps,
|
keymap: Keymaps,
|
||||||
}
|
}
|
||||||
@ -212,6 +213,7 @@ pub fn render_statusline(
|
|||||||
surface: &mut Surface,
|
surface: &mut Surface,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) {
|
) {
|
||||||
|
let text_color = text_color();
|
||||||
let mode = match view.doc.mode() {
|
let mode = match view.doc.mode() {
|
||||||
Mode::Insert => "INS",
|
Mode::Insert => "INS",
|
||||||
Mode::Normal => "NOR",
|
Mode::Normal => "NOR",
|
||||||
@ -222,23 +224,21 @@ pub fn render_statusline(
|
|||||||
Rect::new(0, viewport.y, viewport.width, 1),
|
Rect::new(0, viewport.y, viewport.width, 1),
|
||||||
theme.get("ui.statusline"),
|
theme.get("ui.statusline"),
|
||||||
);
|
);
|
||||||
surface.set_string(1, viewport.y, mode, text_color());
|
surface.set_string(1, viewport.y, mode, text_color);
|
||||||
|
|
||||||
if let Some(path) = view.doc.path() {
|
if let Some(path) = view.doc.path() {
|
||||||
surface.set_string(6, viewport.y, path.to_string_lossy(), text_color());
|
surface.set_string(6, viewport.y, path.to_string_lossy(), text_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
surface.set_string(
|
surface.set_string(
|
||||||
viewport.width - 10,
|
viewport.width - 10,
|
||||||
viewport.y,
|
viewport.y,
|
||||||
format!("{}", view.doc.diagnostics.len()),
|
format!("{}", view.doc.diagnostics.len()),
|
||||||
text_color(),
|
text_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::compositor::Context;
|
|
||||||
|
|
||||||
impl Component for EditorView {
|
impl Component for EditorView {
|
||||||
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
|
||||||
match event {
|
match event {
|
14
helix-term/src/ui/mod.rs
Normal file
14
helix-term/src/ui/mod.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
mod editor;
|
||||||
|
mod prompt;
|
||||||
|
|
||||||
|
pub use editor::EditorView;
|
||||||
|
pub use prompt::Prompt;
|
||||||
|
|
||||||
|
pub use tui::layout::Rect;
|
||||||
|
pub use tui::style::{Color, Modifier, Style};
|
||||||
|
|
||||||
|
// TODO: temp
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn text_color() -> Style {
|
||||||
|
Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
|
||||||
|
}
|
@ -91,10 +91,11 @@ pub fn exit_selection(&mut self) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const BASE_WIDTH: u16 = 30;
|
const BASE_WIDTH: u16 = 30;
|
||||||
use crate::application::text_color;
|
use crate::ui::text_color;
|
||||||
|
|
||||||
impl Prompt {
|
impl Prompt {
|
||||||
pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
|
pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
|
||||||
|
let text_color = text_color();
|
||||||
// completion
|
// completion
|
||||||
if !self.completion.is_empty() {
|
if !self.completion.is_empty() {
|
||||||
// TODO: find out better way of clearing individual lines of the screen
|
// TODO: find out better way of clearing individual lines of the screen
|
||||||
@ -108,7 +109,7 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
|
|||||||
0,
|
0,
|
||||||
area.height - i as u16,
|
area.height - i as u16,
|
||||||
" ".repeat(area.width as usize),
|
" ".repeat(area.width as usize),
|
||||||
text_color(),
|
text_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
surface.set_style(
|
surface.set_style(
|
||||||
@ -121,7 +122,7 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
|
|||||||
{
|
{
|
||||||
Style::default().bg(Color::Rgb(104, 060, 232))
|
Style::default().bg(Color::Rgb(104, 060, 232))
|
||||||
} else {
|
} else {
|
||||||
text_color()
|
text_color
|
||||||
};
|
};
|
||||||
surface.set_stringn(
|
surface.set_stringn(
|
||||||
1 + col * BASE_WIDTH,
|
1 + col * BASE_WIDTH,
|
||||||
@ -141,8 +142,8 @@ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// render buffer text
|
// render buffer text
|
||||||
surface.set_string(1, area.height - 1, &self.prompt, text_color());
|
surface.set_string(1, area.height - 1, &self.prompt, text_color);
|
||||||
surface.set_string(2, area.height - 1, &self.line, text_color());
|
surface.set_string(2, area.height - 1, &self.line, text_color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user