dap: Improve variables UI

pull/574/head
Blaž Hrastnik 3 years ago
parent dac317e620
commit df3b88387b

@ -619,22 +619,41 @@ pub fn dap_variables(cx: &mut Context) {
// TODO: group by scope // TODO: group by scope
// TODO: ui::Text to use tui::text + styled builder // TODO: ui::Text to use tui::text + styled builder
// let contents = tui::text::Text::new();
let theme = &cx.editor.theme;
let scope_style = theme.get("ui.linenr.selected");
let type_style = theme.get("ui.text");
let text_style = theme.get("ui.text.focus");
for scope in scopes.iter() { for scope in scopes.iter() {
// use helix_view::graphics::Style;
use tui::text::{Span, Spans};
let response = block_on(debugger.variables(scope.variables_reference)); let response = block_on(debugger.variables(scope.variables_reference));
variables.push(Spans::from(Span::styled(
format!("▸ {}", scope.name),
scope_style,
)));
if let Ok(vars) = response { if let Ok(vars) = response {
variables.reserve(vars.len()); variables.reserve(vars.len());
for var in vars { for var in vars {
let prefix = match var.ty { let mut spans = Vec::with_capacity(5);
Some(data_type) => format!("{} ", data_type),
None => "".to_owned(), spans.push(Span::styled(var.name.to_owned(), text_style));
}; if let Some(ty) = var.ty {
variables.push(format!("{}{} = {}", prefix, var.name, var.value)); spans.push(Span::raw(": "));
spans.push(Span::styled(ty.to_owned(), type_style));
}
spans.push(Span::raw(" = "));
spans.push(Span::styled(var.value.to_owned(), text_style));
variables.push(Spans::from(spans));
} }
} }
} }
let contents = Text::new(variables.join("\n")); let contents = Text::from(tui::text::Text::from(variables));
let popup = Popup::new(contents); let popup = Popup::new(contents);
cx.push_layer(Box::new(popup)); cx.push_layer(Box::new(popup));
} }

@ -4,13 +4,23 @@ use tui::buffer::Buffer as Surface;
use helix_view::graphics::Rect; use helix_view::graphics::Rect;
pub struct Text { pub struct Text {
contents: String, contents: tui::text::Text<'static>,
size: (u16, u16), size: (u16, u16),
viewport: (u16, u16), viewport: (u16, u16),
} }
impl Text { impl Text {
pub fn new(contents: String) -> Self { pub fn new(contents: String) -> Self {
Self {
contents: tui::text::Text::from(contents),
size: (0, 0),
viewport: (0, 0),
}
}
}
impl From<tui::text::Text<'static>> for Text {
fn from(contents: tui::text::Text<'static>) -> Self {
Self { Self {
contents, contents,
size: (0, 0), size: (0, 0),
@ -18,12 +28,12 @@ impl Text {
} }
} }
} }
impl Component for Text { impl Component for Text {
fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) { fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) {
use tui::widgets::{Paragraph, Widget, Wrap}; use tui::widgets::{Paragraph, Widget, Wrap};
let contents = tui::text::Text::from(self.contents.clone());
let par = Paragraph::new(contents).wrap(Wrap { trim: false }); let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false });
// .scroll(x, y) offsets // .scroll(x, y) offsets
par.render(area, surface); par.render(area, surface);
@ -31,9 +41,8 @@ impl Component for Text {
fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> {
if viewport != self.viewport { if viewport != self.viewport {
let contents = tui::text::Text::from(self.contents.clone()); let width = std::cmp::min(self.contents.width() as u16, viewport.0);
let width = std::cmp::min(contents.width() as u16, viewport.0); let height = std::cmp::min(self.contents.height() as u16, viewport.1);
let height = std::cmp::min(contents.height() as u16, viewport.1);
self.size = (width, height); self.size = (width, height);
self.viewport = viewport; self.viewport = viewport;
} }

Loading…
Cancel
Save