on master help sign in
Move ui modules under a ui:: namespace.
commit7dc24a25ba148a9cd7c936e02cc03873ed6a467b authorBlaž Hrastnik <blaz@mxxn.io> dateSun 13 Dec 2020, 13:35 (6 years ago) parentef0d062
7 files changed+42−43
helix-term/src/application.rs+9−24 helix-term/src/commands.rs+1−1 helix-term/src/helix.log helix-term/src/main.rs+1−2 helix-term/src/editor_view.rs → helix-term/src/ui/editor.rs+11−11 helix-term/src/ui/mod.rs+14 helix-term/src/prompt.rs → helix-term/src/ui/prompt.rs+6−5
helix-term/src/application.rs+9−24
@@ -2,9 +2,8 @@ use clap::ArgMatches as Args;
22
33use helix_view::{document::Mode, Document, Editor, Theme, View};
44
5−use crate::compositor::{Component, Compositor, EventResult};
6−use crate::editor_view::EditorView;
7−use crate::prompt::Prompt;
5+use crate::compositor::Compositor;
6+use crate::ui;
87
98use log::{debug, info};
109
@@ -19,18 +18,11 @@ use smol::prelude::*;
1918use anyhow::Error;
2019
2120use crossterm::{
22− cursor,
23− event::{read, Event, EventStream, KeyCode, KeyEvent},
24− execute, queue,
25− terminal::{self, disable_raw_mode, enable_raw_mode},
21+ event::{Event, EventStream},
22+ execute, terminal,
2623};
2724
28−use tui::{
29− backend::CrosstermBackend,
30− buffer::Buffer as Surface,
31− layout::Rect,
32− style::{Color, Modifier, Style},
33−};
25+use tui::{backend::CrosstermBackend, layout::Rect};
3426
3527type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
3628
@@ -43,12 +35,6 @@ pub struct Application {
4335 language_server: helix_lsp::Client,
4436}
4537
46−// TODO: temp
47−#[inline(always)]
48−pub fn text_color() -> Style {
49− Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
50−}
51−
5238impl Application {
5339 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
5440 let backend = CrosstermBackend::new(stdout());
@@ -61,14 +47,13 @@ impl Application {
6147 }
6248
6349 let mut compositor = Compositor::new();
64− compositor.push(Box::new(EditorView::new()));
50+ compositor.push(Box::new(ui::EditorView::new()));
6551
6652 let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
6753
6854 let mut app = Self {
6955 editor,
7056 terminal,
71− // TODO; move to state
7257 compositor,
7358
7459 executor,
@@ -213,7 +198,7 @@ impl Application {
213198 }
214199
215200 pub async fn run(&mut self) -> Result<(), Error> {
216− enable_raw_mode()?;
201+ terminal::enable_raw_mode()?;
217202
218203 let mut stdout = stdout();
219204
@@ -223,7 +208,7 @@ impl Application {
223208 let hook = std::panic::take_hook();
224209 std::panic::set_hook(Box::new(move |info| {
225210 execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
226− disable_raw_mode();
211+ terminal::disable_raw_mode();
227212 hook(info);
228213 }));
229214
@@ -234,7 +219,7 @@ impl Application {
234219
235220 execute!(stdout, terminal::LeaveAlternateScreen)?;
236221
237− disable_raw_mode()?;
222+ terminal::disable_raw_mode()?;
238223
239224 Ok(())
240225 }
helix-term/src/commands.rs+1−1
@@ -10,7 +10,7 @@ use helix_core::{
1010use once_cell::sync::Lazy;
1111
1212use crate::compositor::Compositor;
13−use crate::prompt::Prompt;
13+use crate::ui::Prompt;
1414
1515use helix_view::{
1616 document::Mode,
helix-term/src/helix.lognew file

No changes to the content.

helix-term/src/main.rs+1−2
@@ -3,10 +3,9 @@
33mod application;
44mod commands;
55mod compositor;
6−mod editor_view;
76mod keymap;
8−mod prompt;
97mod terminal;
8+mod ui;
109
1110use application::Application;
1211
helix-term/src/editor_view.rs → helix-term/src/ui/editor.rsrenamed+11−11
@@ -1,13 +1,16 @@
1−use crate::application::text_color;
21use crate::commands;
3−use crate::compositor::{Component, Compositor, EventResult};
2+use crate::compositor::{Component, Compositor, Context, EventResult};
43use crate::keymap::{self, Keymaps};
4+use crate::ui::text_color;
5+
6+use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
7+use helix_view::{document::Mode, Document, Editor, Theme, View};
8+use std::borrow::Cow;
9+
510use crossterm::{
611 cursor,
712 event::{read, Event, EventStream, KeyCode, KeyEvent},
813};
9−use helix_view::{document::Mode, Document, Editor, Theme, View};
10−use std::borrow::Cow;
1114use tui::{
1215 backend::CrosstermBackend,
1316 buffer::Buffer as Surface,
@@ -15,8 +18,6 @@ use tui::{
1518 style::{Color, Modifier, Style},
1619};
1720
18−use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
19−
2021pub struct EditorView {
2122 keymap: Keymaps,
2223}
@@ -212,6 +213,7 @@ impl EditorView {
212213 surface: &mut Surface,
213214 theme: &Theme,
214215 ) {
216+ let text_color = text_color();
215217 let mode = match view.doc.mode() {
216218 Mode::Insert => "INS",
217219 Mode::Normal => "NOR",
@@ -222,23 +224,21 @@ impl EditorView {
222224 Rect::new(0, viewport.y, viewport.width, 1),
223225 theme.get("ui.statusline"),
224226 );
225− surface.set_string(1, viewport.y, mode, text_color());
227+ surface.set_string(1, viewport.y, mode, text_color);
226228
227229 if let Some(path) = view.doc.path() {
228− surface.set_string(6, viewport.y, path.to_string_lossy(), text_color());
230+ surface.set_string(6, viewport.y, path.to_string_lossy(), text_color);
229231 }
230232
231233 surface.set_string(
232234 viewport.width - 10,
233235 viewport.y,
234236 format!("{}", view.doc.diagnostics.len()),
235− text_color(),
237+ text_color,
236238 );
237239 }
238240}
239241
240−use crate::compositor::Context;
241−
242242impl Component for EditorView {
243243 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
244244 match event {
helix-term/src/ui/mod.rsnew file+14
@@ -0,0 +1,14 @@
1+mod editor;
2+mod prompt;
3+
4+pub use editor::EditorView;
5+pub use prompt::Prompt;
6+
7+pub use tui::layout::Rect;
8+pub use tui::style::{Color, Modifier, Style};
9+
10+// TODO: temp
11+#[inline(always)]
12+pub fn text_color() -> Style {
13+ Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
14+}
helix-term/src/prompt.rs → helix-term/src/ui/prompt.rsrenamed+6−5
@@ -91,10 +91,11 @@ use tui::{
9191};
9292
9393const BASE_WIDTH: u16 = 30;
94−use crate::application::text_color;
94+use crate::ui::text_color;
9595
9696impl Prompt {
9797 pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
98+ let text_color = text_color();
9899 // completion
99100 if !self.completion.is_empty() {
100101 // TODO: find out better way of clearing individual lines of the screen
@@ -108,7 +109,7 @@ impl Prompt {
108109 0,
109110 area.height - i as u16,
110111 " ".repeat(area.width as usize),
111− text_color(),
112+ text_color,
112113 );
113114 }
114115 surface.set_style(
@@ -121,7 +122,7 @@ impl Prompt {
121122 {
122123 Style::default().bg(Color::Rgb(104, 060, 232))
123124 } else {
124− text_color()
125+ text_color
125126 };
126127 surface.set_stringn(
127128 1 + col * BASE_WIDTH,
@@ -141,8 +142,8 @@ impl Prompt {
141142 }
142143 }
143144 // render buffer text
144− surface.set_string(1, area.height - 1, &self.prompt, text_color());
145− surface.set_string(2, area.height - 1, &self.line, text_color());
145+ surface.set_string(1, area.height - 1, &self.prompt, text_color);
146+ surface.set_string(2, area.height - 1, &self.line, text_color);
146147 }
147148}
148149