summaryrefslogtreecommitdiff
path: root/helix-term/src/prompt.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-12-13 03:23:50 +0000
committerBlaž Hrastnik2020-12-13 03:23:50 +0000
commit8695415fbfe927250f68e93793660e3c4e4a70b4 (patch)
tree829bb12d6fe17d322b1586871c3aeacc095d9f58 /helix-term/src/prompt.rs
parent29cb33300b1486c778e9318e87e60c26695c2520 (diff)
wip: Move to new rendering structure.
Diffstat (limited to 'helix-term/src/prompt.rs')
-rw-r--r--helix-term/src/prompt.rs72
1 files changed, 66 insertions, 6 deletions
diff --git a/helix-term/src/prompt.rs b/helix-term/src/prompt.rs
index 689eac66..4747c9f5 100644
--- a/helix-term/src/prompt.rs
+++ b/helix-term/src/prompt.rs
@@ -1,9 +1,7 @@
-use crate::{
- application::Renderer,
- compositor::{Component, Context, EventResult},
-};
+use crate::compositor::{Component, Context, EventResult};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use helix_view::Editor;
+use helix_view::Theme;
use std::string::String;
pub struct Prompt {
@@ -85,6 +83,68 @@ impl Prompt {
}
}
+use tui::{
+ buffer::Buffer as Surface,
+ layout::Rect,
+ style::{Color, Modifier, Style},
+};
+
+const BASE_WIDTH: u16 = 30;
+use crate::application::text_color;
+
+impl Prompt {
+ pub fn render_prompt(&self, area: Rect, surface: &mut Surface, theme: &Theme) {
+ // completion
+ if !self.completion.is_empty() {
+ // TODO: find out better way of clearing individual lines of the screen
+ let mut row = 0;
+ let mut col = 0;
+ let max_col = area.width / BASE_WIDTH;
+ let col_height = ((self.completion.len() as u16 + max_col - 1) / max_col);
+
+ for i in (3..col_height + 3) {
+ surface.set_string(
+ 0,
+ area.height - i as u16,
+ " ".repeat(area.width as usize),
+ text_color(),
+ );
+ }
+ surface.set_style(
+ Rect::new(0, area.height - col_height - 2, area.width, col_height),
+ theme.get("ui.statusline"),
+ );
+ for (i, command) in self.completion.iter().enumerate() {
+ let color = if self.completion_selection_index.is_some()
+ && i == self.completion_selection_index.unwrap()
+ {
+ Style::default().bg(Color::Rgb(104, 060, 232))
+ } else {
+ text_color()
+ };
+ surface.set_stringn(
+ 1 + col * BASE_WIDTH,
+ area.height - col_height - 2 + row,
+ &command,
+ BASE_WIDTH as usize - 1,
+ color,
+ );
+ row += 1;
+ if row > col_height - 1 {
+ row = 0;
+ col += 1;
+ }
+ if col > max_col {
+ break;
+ }
+ }
+ }
+ // 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());
+ }
+}
+
impl Component for Prompt {
fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult {
let event = match event {
@@ -137,7 +197,7 @@ impl Component for Prompt {
EventResult::Consumed(None)
}
- fn render(&mut self, renderer: &mut Renderer, cx: &mut Context) {
- renderer.render_prompt(self, &cx.editor.theme)
+ fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
+ self.render_prompt(area, surface, &cx.editor.theme)
}
}