on master help sign in
Move ui modules under a ui:: namespace.
7dc24a2Blaž Hrastnik
helix-term/src/application.rs+9−24
@@ -2,9 +2,8 @@ use clap::ArgMatches as Args;
2
2
3use helix_view::{document::Mode, Document, Editor, Theme, View};
3use helix_view::{document::Mode, Document, Editor, Theme, View};
4
4
5−use crate::compositor::{Component, Compositor, EventResult};
5+use crate::compositor::Compositor;
6−use crate::editor_view::EditorView;
6+use crate::ui;
7−use crate::prompt::Prompt;
8
7
9use log::{debug, info};
8use log::{debug, info};
10
9
@@ -19,18 +18,11 @@ use smol::prelude::*;
19use anyhow::Error;
18use anyhow::Error;
20
19
21use crossterm::{
20use crossterm::{
22− cursor,
23− event::{read, Event, EventStream, KeyCode, KeyEvent},
21+ event::{Event, EventStream},
24− execute, queue,
22+ execute, terminal,
25− terminal::{self, disable_raw_mode, enable_raw_mode},
26};
23};
27
24
28−use tui::{
29− backend::CrosstermBackend,
25+use tui::{backend::CrosstermBackend, layout::Rect};
30− buffer::Buffer as Surface,
31− layout::Rect,
32− style::{Color, Modifier, Style},
33−};
34
26
35type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
27type Terminal = crate::terminal::Terminal<CrosstermBackend<std::io::Stdout>>;
36
28
@@ -43,12 +35,6 @@ pub struct Application {
43 language_server: helix_lsp::Client,
35 language_server: helix_lsp::Client,
44}
36}
45
37
46−// TODO: temp
47−#[inline(always)]
48−pub fn text_color() -> Style {
49− Style::default().fg(Color::Rgb(219, 191, 239)) // lilac
50−}
51−
52impl Application {
38impl Application {
53 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
39 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
54 let backend = CrosstermBackend::new(stdout());
40 let backend = CrosstermBackend::new(stdout());
@@ -61,14 +47,13 @@ impl Application {
61 }
47 }
62
48
63 let mut compositor = Compositor::new();
49 let mut compositor = Compositor::new();
64− compositor.push(Box::new(EditorView::new()));
50+ compositor.push(Box::new(ui::EditorView::new()));
65
51
66 let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
52 let language_server = helix_lsp::Client::start(&executor, "rust-analyzer", &[]);
67
53
68 let mut app = Self {
54 let mut app = Self {
69 editor,
55 editor,
70 terminal,
56 terminal,
71− // TODO; move to state
72 compositor,
57 compositor,
73
58
74 executor,
59 executor,
@@ -213,7 +198,7 @@ impl Application {
213 }
198 }
214
199
215 pub async fn run(&mut self) -> Result<(), Error> {
200 pub async fn run(&mut self) -> Result<(), Error> {
216− enable_raw_mode()?;
201+ terminal::enable_raw_mode()?;
217
202
218 let mut stdout = stdout();
203 let mut stdout = stdout();
219
204
@@ -223,7 +208,7 @@ impl Application {
223 let hook = std::panic::take_hook();
208 let hook = std::panic::take_hook();
224 std::panic::set_hook(Box::new(move |info| {
209 std::panic::set_hook(Box::new(move |info| {
225 execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
210 execute!(std::io::stdout(), terminal::LeaveAlternateScreen);
226− disable_raw_mode();
211+ terminal::disable_raw_mode();
227 hook(info);
212 hook(info);
228 }));
213 }));
229
214
@@ -234,7 +219,7 @@ impl Application {
234
219
235 execute!(stdout, terminal::LeaveAlternateScreen)?;
220 execute!(stdout, terminal::LeaveAlternateScreen)?;
236
221
237− disable_raw_mode()?;
222+ terminal::disable_raw_mode()?;
238
223
239 Ok(())
224 Ok(())
240 }
225 }
helix-term/src/commands.rs+1−1
@@ -10,7 +10,7 @@ use helix_core::{
10use once_cell::sync::Lazy;
10use once_cell::sync::Lazy;
11
11
12use crate::compositor::Compositor;
12use crate::compositor::Compositor;
13−use crate::prompt::Prompt;
13+use crate::ui::Prompt;
14
14
15use helix_view::{
15use helix_view::{
16 document::Mode,
16 document::Mode,
helix-term/src/helix.lognew file

No changes to the content.

helix-term/src/main.rs+1−2
@@ -3,10 +3,9 @@
3mod application;
3mod application;
4mod commands;
4mod commands;
5mod compositor;
5mod compositor;
6−mod editor_view;
7mod keymap;
6mod keymap;
8−mod prompt;
9mod terminal;
7mod terminal;
8+mod ui;
10
9
11use application::Application;
10use application::Application;
12
11
helix-term/src/editor_view.rs → helix-term/src/ui/editor.rsrenamed+11−11
@@ -1,13 +1,16 @@
1−use crate::application::text_color;
2use crate::commands;
1use crate::commands;
3−use crate::compositor::{Component, Compositor, EventResult};
2+use crate::compositor::{Component, Compositor, Context, EventResult};
4use crate::keymap::{self, Keymaps};
3use 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+
5use crossterm::{
10use crossterm::{
6 cursor,
11 cursor,
7 event::{read, Event, EventStream, KeyCode, KeyEvent},
12 event::{read, Event, EventStream, KeyCode, KeyEvent},
8};
13};
9−use helix_view::{document::Mode, Document, Editor, Theme, View};
10−use std::borrow::Cow;
11use tui::{
14use tui::{
12 backend::CrosstermBackend,
15 backend::CrosstermBackend,
13 buffer::Buffer as Surface,
16 buffer::Buffer as Surface,
@@ -15,8 +18,6 @@ use tui::{
15 style::{Color, Modifier, Style},
18 style::{Color, Modifier, Style},
16};
19};
17
20
18−use helix_core::{indent::TAB_WIDTH, syntax::HighlightEvent, Position, Range, State};
19−
20pub struct EditorView {
21pub struct EditorView {
21 keymap: Keymaps,
22 keymap: Keymaps,
22}
23}
@@ -212,6 +213,7 @@ impl EditorView {
212 surface: &mut Surface,
213 surface: &mut Surface,
213 theme: &Theme,
214 theme: &Theme,
214 ) {
215 ) {
216+ let text_color = text_color();
215 let mode = match view.doc.mode() {
217 let mode = match view.doc.mode() {
216 Mode::Insert => "INS",
218 Mode::Insert => "INS",
217 Mode::Normal => "NOR",
219 Mode::Normal => "NOR",
@@ -222,23 +224,21 @@ impl EditorView {
222 Rect::new(0, viewport.y, viewport.width, 1),
224 Rect::new(0, viewport.y, viewport.width, 1),
223 theme.get("ui.statusline"),
225 theme.get("ui.statusline"),
224 );
226 );
225− surface.set_string(1, viewport.y, mode, text_color());
227+ surface.set_string(1, viewport.y, mode, text_color);
226
228
227 if let Some(path) = view.doc.path() {
229 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);
229 }
231 }
230
232
231 surface.set_string(
233 surface.set_string(
232 viewport.width - 10,
234 viewport.width - 10,
233 viewport.y,
235 viewport.y,
234 format!("{}", view.doc.diagnostics.len()),
236 format!("{}", view.doc.diagnostics.len()),
235− text_color(),
237+ text_color,
236 );
238 );
237 }
239 }
238}
240}
239
241
240−use crate::compositor::Context;
241−
242impl Component for EditorView {
242impl Component for EditorView {
243 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
243 fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
244 match event {
244 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::{
91};
91};
92
92
93const BASE_WIDTH: u16 = 30;
93const BASE_WIDTH: u16 = 30;
94−use crate::application::text_color;
94+use crate::ui::text_color;
95
95
96impl Prompt {
96impl Prompt {
97 pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
97 pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
98+ let text_color = text_color();
98 // completion
99 // completion
99 if !self.completion.is_empty() {
100 if !self.completion.is_empty() {
100 // TODO: find out better way of clearing individual lines of the screen
101 // TODO: find out better way of clearing individual lines of the screen
@@ -108,7 +109,7 @@ impl Prompt {
108 0,
109 0,
109 area.height - i as u16,
110 area.height - i as u16,
110 " ".repeat(area.width as usize),
111 " ".repeat(area.width as usize),
111− text_color(),
112+ text_color,
112 );
113 );
113 }
114 }
114 surface.set_style(
115 surface.set_style(
@@ -121,7 +122,7 @@ impl Prompt {
121 {
122 {
122 Style::default().bg(Color::Rgb(104, 060, 232))
123 Style::default().bg(Color::Rgb(104, 060, 232))
123 } else {
124 } else {
124− text_color()
125+ text_color
125 };
126 };
126 surface.set_stringn(
127 surface.set_stringn(
127 1 + col * BASE_WIDTH,
128 1 + col * BASE_WIDTH,
@@ -141,8 +142,8 @@ impl Prompt {
141 }
142 }
142 }
143 }
143 // render buffer text
144 // render buffer text
144− surface.set_string(1, area.height - 1, &self.prompt, text_color());
145+ surface.set_string(1, area.height - 1, &self.prompt, text_color);
145− surface.set_string(2, area.height - 1, &self.line, text_color());
146+ surface.set_string(2, area.height - 1, &self.line, text_color);
146 }
147 }
147}
148}
148
149