on master help sign in
dap: Improve variables UI
df3b883Blaž Hrastnik
helix-term/src/commands/dap.rs+25−6
@@ -619,22 +619,41 @@ pub fn dap_variables(cx: &mut Context) {
619 // TODO: group by scope
619 // TODO: group by scope
620 // TODO: ui::Text to use tui::text + styled builder
620 // TODO: ui::Text to use tui::text + styled builder
621
621
622+ // let contents = tui::text::Text::new();
623+
624+ let theme = &cx.editor.theme;
625+ let scope_style = theme.get("ui.linenr.selected");
626+ let type_style = theme.get("ui.text");
627+ let text_style = theme.get("ui.text.focus");
628+
622 for scope in scopes.iter() {
629 for scope in scopes.iter() {
630+ // use helix_view::graphics::Style;
631+ use tui::text::{Span, Spans};
623 let response = block_on(debugger.variables(scope.variables_reference));
632 let response = block_on(debugger.variables(scope.variables_reference));
624
633
634+ variables.push(Spans::from(Span::styled(
635+ format!("▸ {}", scope.name),
636+ scope_style,
637+ )));
638+
625 if let Ok(vars) = response {
639 if let Ok(vars) = response {
626 variables.reserve(vars.len());
640 variables.reserve(vars.len());
627 for var in vars {
641 for var in vars {
628− let prefix = match var.ty {
642+ let mut spans = Vec::with_capacity(5);
629− Some(data_type) => format!("{} ", data_type),
643+
630− None => "".to_owned(),
644+ spans.push(Span::styled(var.name.to_owned(), text_style));
631− };
645+ if let Some(ty) = var.ty {
632− variables.push(format!("{}{} = {}", prefix, var.name, var.value));
646+ spans.push(Span::raw(": "));
647+ spans.push(Span::styled(ty.to_owned(), type_style));
648+ }
649+ spans.push(Span::raw(" = "));
650+ spans.push(Span::styled(var.value.to_owned(), text_style));
651+ variables.push(Spans::from(spans));
633 }
652 }
634 }
653 }
635 }
654 }
636
655
637− let contents = Text::new(variables.join("\n"));
656+ let contents = Text::from(tui::text::Text::from(variables));
638 let popup = Popup::new(contents);
657 let popup = Popup::new(contents);
639 cx.push_layer(Box::new(popup));
658 cx.push_layer(Box::new(popup));
640}
659}
helix-term/src/ui/text.rs+15−6
@@ -4,13 +4,23 @@ use tui::buffer::Buffer as Surface;
4use helix_view::graphics::Rect;
4use helix_view::graphics::Rect;
5
5
6pub struct Text {
6pub struct Text {
7− contents: String,
7+ contents: tui::text::Text<'static>,
8 size: (u16, u16),
8 size: (u16, u16),
9 viewport: (u16, u16),
9 viewport: (u16, u16),
10}
10}
11
11
12impl Text {
12impl Text {
13 pub fn new(contents: String) -> Self {
13 pub fn new(contents: String) -> Self {
14+ Self {
15+ contents: tui::text::Text::from(contents),
16+ size: (0, 0),
17+ viewport: (0, 0),
18+ }
19+ }
20+}
21+
22+impl From<tui::text::Text<'static>> for Text {
23+ fn from(contents: tui::text::Text<'static>) -> Self {
14 Self {
24 Self {
15 contents,
25 contents,
16 size: (0, 0),
26 size: (0, 0),
@@ -18,12 +28,12 @@ impl Text {
18 }
28 }
19 }
29 }
20}
30}
31+
21impl Component for Text {
32impl Component for Text {
22 fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
33 fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
23 use tui::widgets::{Paragraph, Widget, Wrap};
34 use tui::widgets::{Paragraph, Widget, Wrap};
24− let contents = tui::text::Text::from(self.contents.clone());
25
35
26− let par = Paragraph::new(contents).wrap(Wrap { trim: false });
36+ let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false });
27 // .scroll(x, y) offsets
37 // .scroll(x, y) offsets
28
38
29 par.render(area, surface);
39 par.render(area, surface);
@@ -31,9 +41,8 @@ impl Component for Text {
31
41
32 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
42 fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
33 if viewport != self.viewport {
43 if viewport != self.viewport {
34− let contents = tui::text::Text::from(self.contents.clone());
35− let width = std::cmp::min(contents.width() as u16, viewport.0);
44+ let width = std::cmp::min(self.contents.width() as u16, viewport.0);
36− let height = std::cmp::min(contents.height() as u16, viewport.1);
45+ let height = std::cmp::min(self.contents.height() as u16, viewport.1);
37 self.size = (width, height);
46 self.size = (width, height);
38 self.viewport = viewport;
47 self.viewport = viewport;
39 }
48 }