aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-13 04:35:30 +0000
committerBlaž Hrastnik2020-12-13 04:44:51 +0000
commit7dc24a25ba148a9cd7c936e02cc03873ed6a467b (patch)
treeaf38e8d0d65741946c52b5b12824971da7537136 /helix-term
parentef0d062b1fd202fe89bc4bbd33826c46f660ef70 (diff)
Move ui modules under a ui:: namespace.
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/application.rs33
-rw-r--r--helix-term/src/commands.rs2
-rw-r--r--helix-term/src/helix.log0
-rw-r--r--helix-term/src/main.rs3
-rw-r--r--helix-term/src/ui/editor.rs (renamed from helix-term/src/editor_view.rs)22
-rw-r--r--helix-term/src/ui/mod.rs14
-rw-r--r--helix-term/src/ui/prompt.rs (renamed from helix-term/src/prompt.rs)11
7 files changed, 42 insertions, 43 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index c25871c7..dc37612a 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -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(())
}
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 04482ef7..b345d2e8 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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,
diff --git a/helix-term/src/helix.log b/helix-term/src/helix.log
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/helix-term/src/helix.log
diff --git a/helix-term/src/main.rs b/helix-term/src/main.rs
index 63fbe52d..f350b4c1 100644
--- a/helix-term/src/main.rs
+++ b/helix-term/src/main.rs
@@ -3,10 +3,9 @@
mod application;
mod commands;
mod compositor;
-mod editor_view;
mod keymap;
-mod prompt;
mod terminal;
+mod ui;
use application::Application;
diff --git a/helix-term/src/editor_view.rs b/helix-term/src/ui/editor.rs
index b778e79b..ceb5a442 100644
--- a/helix-term/src/editor_view.rs
+++ b/helix-term/src/ui/editor.rs
@@ -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 {
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
new file mode 100644
index 00000000..bc79e09c
--- /dev/null
+++ b/helix-term/src/ui/mod.rs
@@ -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
+}
diff --git a/helix-term/src/prompt.rs b/helix-term/src/ui/prompt.rs
index 7f473ebc..071cac90 100644
--- a/helix-term/src/prompt.rs
+++ b/helix-term/src/ui/prompt.rs
@@ -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);
}
}