Move ui modules under a ui:: namespace.

pull/6/head
Blaž Hrastnik 4 years ago
parent ef0d062b1f
commit 7dc24a25ba

@ -2,9 +2,8 @@ use clap::ArgMatches as Args;
use helix_view::{document::Mode, Document, Editor, Theme, View};
use crate::compositor::{Component, Compositor, EventResult};
use crate::editor_view::EditorView;
use crate::prompt::Prompt;
use crate::compositor::Compositor;
use crate::ui;
use log::{debug, info};
@ -19,18 +18,11 @@ use smol::prelude::*;
use anyhow::Error;
use crossterm::{
cursor,
event::{read, Event, EventStream, KeyCode, KeyEvent},
execute, queue,
terminal::{self, disable_raw_mode, enable_raw_mode},
event::{Event, EventStream},
execute, terminal,
};
use tui::{
backend::CrosstermBackend,
buffer::Buffer as Surface,
layout::Rect,
style::{Color, Modifier, Style},
};
use tui::{backend::CrosstermBackend, layout::Rect};
type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
@ -43,12 +35,6 @@ pub struct Application {
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 {
pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
let backend = CrosstermBackend::new(stdout());
@ -61,14 +47,13 @@ impl Application {
}
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 mut app = Self {
editor,
terminal,
// TODO; move to state
compositor,
executor,
@ -213,7 +198,7 @@ impl Application {
}
pub async fn run(&mut self) -> Result<(), Error> {
enable_raw_mode()?;
terminal::enable_raw_mode()?;
let mut stdout = stdout();
@ -223,7 +208,7 @@ impl Application {
let hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
disable_raw_mode();
terminal::disable_raw_mode();
hook(info);
}));
@ -234,7 +219,7 @@ impl Application {
execute!(stdout, terminal::LeaveAlternateScreen)?;
disable_raw_mode()?;
terminal::disable_raw_mode()?;
Ok(())
}

@ -10,7 +10,7 @@ use helix_core::{
use once_cell::sync::Lazy;
use crate::compositor::Compositor;
use crate::prompt::Prompt;
use crate::ui::Prompt;
use helix_view::{
document::Mode,

@ -3,10 +3,9 @@
mod application;
mod commands;
mod compositor;
mod editor_view;
mod keymap;
mod prompt;
mod terminal;
mod ui;
use application::Application;

@ -1,13 +1,16 @@
use crate::application::text_color;
use crate::commands;
use crate::compositor::{Component, Compositor, EventResult};
use crate::compositor::{Component, Compositor, Context, EventResult};
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::{
cursor,
event::{read, Event, EventStream, KeyCode, KeyEvent},
};
use helix_view::{document::Mode, Document, Editor, Theme, View};
use std::borrow::Cow;
use tui::{
backend::CrosstermBackend,
buffer::Buffer as Surface,
@ -15,8 +18,6 @@ use tui::{
style::{Color, Modifier, Style},
};
use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
pub struct EditorView {
keymap: Keymaps,
}
@ -212,6 +213,7 @@ impl EditorView {
surface: &mut Surface,
theme: &Theme,
) {
let text_color = text_color();
let mode = match view.doc.mode() {
Mode::Insert => "INS",
Mode::Normal => "NOR",
@ -222,23 +224,21 @@ impl EditorView {
Rect::new(0, viewport.y, viewport.width, 1),
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() {
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(
viewport.width - 10,
viewport.y,
format!("{}", view.doc.diagnostics.len()),
text_color(),
text_color,
);
}
}
use crate::compositor::Context;
impl Component for EditorView {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
match event {

@ -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 @@ use tui::{
};
const BASE_WIDTH: u16 = 30;
use crate::application::text_color;
use crate::ui::text_color;
impl Prompt {
pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
let text_color = text_color();
// completion
if !self.completion.is_empty() {
// TODO: find out better way of clearing individual lines of the screen
@ -108,7 +109,7 @@ impl Prompt {
0,
area.height - i as u16,
" ".repeat(area.width as usize),
text_color(),
text_color,
);
}
surface.set_style(
@ -121,7 +122,7 @@ impl Prompt {
{
Style::default().bg(Color::Rgb(104, 060, 232))
} else {
text_color()
text_color
};
surface.set_stringn(
1 + col * BASE_WIDTH,
@ -141,8 +142,8 @@ impl Prompt {
}
}
// render buffer text
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(1, area.height - 1, &self.prompt, text_color);
surface.set_string(2, area.height - 1, &self.line, text_color);
}
}
Loading…
Cancel
Save