Skip to content

Commit

Permalink
feat: pertty
Browse files Browse the repository at this point in the history
  • Loading branch information
ofzo committed Aug 25, 2024
1 parent a8b499b commit dae9cab
Show file tree
Hide file tree
Showing 21 changed files with 463 additions and 294 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- ofzo
merge_group:
schedule:
- cron: "00 01 * * *"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- '[0-9]+.[0-9]+.[0-9]+'
branches:
- 'patch/ci-release-*'
- 'ofzo'
pull_request:
paths:
- '.github/workflows/release.yml'
Expand Down
5 changes: 4 additions & 1 deletion helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,9 +1076,12 @@ pub fn hover(cx: &mut Context) {
};

// skip if contents empty
if contents.is_empty() {
return
}

let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents).auto_close(true);
let popup = Popup::new("hover", contents).auto_close(true).position(editor.cursor().0);
compositor.replace_or_push("hover", popup);
}
},
Expand Down
2 changes: 2 additions & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,7 @@ FLAGS:

let exit_code = app.run(&mut EventStream::new()).await?;

print!("\x1b[6 q");
Ok(exit_code)

}
68 changes: 36 additions & 32 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,42 @@ impl menu::Item for CompletionItem {
});

menu::Row::new(vec![
menu::Cell::from(Span::styled(
" ".to_string()
+ match self.item.kind {
Some(lsp::CompletionItemKind::TEXT) => "󰉿",
Some(lsp::CompletionItemKind::METHOD) => "󰆧",
Some(lsp::CompletionItemKind::FUNCTION) => "󰊕",
Some(lsp::CompletionItemKind::CONSTRUCTOR) => "",
Some(lsp::CompletionItemKind::FIELD) => "󰜢",
Some(lsp::CompletionItemKind::VARIABLE) => "󰀫",
Some(lsp::CompletionItemKind::CLASS) => "󰠱",
Some(lsp::CompletionItemKind::INTERFACE) => "",
Some(lsp::CompletionItemKind::MODULE) => "",
Some(lsp::CompletionItemKind::PROPERTY) => "󰜢",
Some(lsp::CompletionItemKind::UNIT) => "󰑭",
Some(lsp::CompletionItemKind::VALUE) => "󰎠",
Some(lsp::CompletionItemKind::ENUM) => "",
Some(lsp::CompletionItemKind::KEYWORD) => "󰌋",
Some(lsp::CompletionItemKind::SNIPPET) => "",
Some(lsp::CompletionItemKind::COLOR) => "󰏘",
Some(lsp::CompletionItemKind::FILE) => "󰈙",
Some(lsp::CompletionItemKind::REFERENCE) => "󰈇",
Some(lsp::CompletionItemKind::FOLDER) => "󰉋",
Some(lsp::CompletionItemKind::ENUM_MEMBER) => "",
Some(lsp::CompletionItemKind::CONSTANT) => "󰏿",
Some(lsp::CompletionItemKind::STRUCT) => "󰙅",
Some(lsp::CompletionItemKind::EVENT) => "",
Some(lsp::CompletionItemKind::OPERATOR) => "󰆕",
Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "",
Some(kind) => {
log::error!("Received unknown completion item kind: {:?}", kind);
""
}
None => "",
},
Style::default().fg(helix_view::theme::Color::Gray),
)),
menu::Cell::from(Span::styled(
self.item.label.as_str(),
if deprecated {
Expand All @@ -51,38 +87,6 @@ impl menu::Item for CompletionItem {
Style::default()
},
)),
menu::Cell::from(match self.item.kind {
Some(lsp::CompletionItemKind::TEXT) => "text",
Some(lsp::CompletionItemKind::METHOD) => "method",
Some(lsp::CompletionItemKind::FUNCTION) => "function",
Some(lsp::CompletionItemKind::CONSTRUCTOR) => "constructor",
Some(lsp::CompletionItemKind::FIELD) => "field",
Some(lsp::CompletionItemKind::VARIABLE) => "variable",
Some(lsp::CompletionItemKind::CLASS) => "class",
Some(lsp::CompletionItemKind::INTERFACE) => "interface",
Some(lsp::CompletionItemKind::MODULE) => "module",
Some(lsp::CompletionItemKind::PROPERTY) => "property",
Some(lsp::CompletionItemKind::UNIT) => "unit",
Some(lsp::CompletionItemKind::VALUE) => "value",
Some(lsp::CompletionItemKind::ENUM) => "enum",
Some(lsp::CompletionItemKind::KEYWORD) => "keyword",
Some(lsp::CompletionItemKind::SNIPPET) => "snippet",
Some(lsp::CompletionItemKind::COLOR) => "color",
Some(lsp::CompletionItemKind::FILE) => "file",
Some(lsp::CompletionItemKind::REFERENCE) => "reference",
Some(lsp::CompletionItemKind::FOLDER) => "folder",
Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member",
Some(lsp::CompletionItemKind::CONSTANT) => "constant",
Some(lsp::CompletionItemKind::STRUCT) => "struct",
Some(lsp::CompletionItemKind::EVENT) => "event",
Some(lsp::CompletionItemKind::OPERATOR) => "operator",
Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param",
Some(kind) => {
log::error!("Received unknown completion item kind: {:?}", kind);
""
}
None => "",
}),
])
}
}
Expand Down
71 changes: 53 additions & 18 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl EditorView {
let mut decorations = DecorationManager::default();

if is_focused && config.cursorline {
decorations.add_decoration(Self::cursorline(doc, view, theme));
decorations.add_decoration(Self::cursorline(doc, view, theme, &editor.mode));
}

if is_focused && config.cursorcolumn {
Expand Down Expand Up @@ -232,15 +232,17 @@ impl EditorView {
Self::render_diagnostics(doc, view, inner, surface, theme);
}

let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(config.commandline as u16); // -1 from bottom to remove commandline
if editor.status_msg.is_none() {
let statusline_area = view
.area
.clip_top(view.area.height.saturating_sub(1))
.clip_bottom(config.commandline as u16); // -1 from bottom to remove commandline

let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);
let mut context =
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);

statusline::render(&mut context, statusline_area, surface);
statusline::render(&mut context, statusline_area, surface);
}
}

pub fn render_rulers(
Expand Down Expand Up @@ -476,12 +478,35 @@ impl EditorView {
let cursorkind = cursor_shape_config.from_mode(mode);
let cursor_is_block = cursorkind == CursorKind::Block;

let selection_scope = theme
.find_scope_index_exact("ui.selection")
.expect("could not find `ui.selection` scope in the theme!");
let primary_selection_scope = theme
.find_scope_index_exact("ui.selection.primary")
.unwrap_or(selection_scope);
// let selection_scope = theme
// .find_scope_index_exact("ui.selection")
// .expect("could not find `ui.selection` scope in the theme!");

let selection_scope = match mode {
Mode::Normal => theme.find_scope_index_exact("ui.selection.normal"),
Mode::Select => theme.find_scope_index_exact("ui.selection.select"),
Mode::Insert => theme.find_scope_index_exact("ui.selection.insert"),
}
.unwrap_or(
theme
.find_scope_index_exact("ui.selection")
.expect("could not find `ui.selection` scope in the theme!"),
);

// let primary_selection_scope = theme
// .find_scope_index_exact("ui.selection.primary")
// .unwrap_or(selection_scope);

let primary_selection_scope = match mode {
Mode::Normal => theme.find_scope_index_exact("ui.selection.primary.normal"),
Mode::Select => theme.find_scope_index_exact("ui.selection.primary.select"),
Mode::Insert => theme.find_scope_index_exact("ui.selection.primary.insert"),
}
.unwrap_or(
theme
.find_scope_index_exact("ui.selection.primary")
.expect("could not find `ui.selection.primary` scope in the theme!"),
);

let base_cursor_scope = theme
.find_scope_index_exact("ui.cursor")
Expand Down Expand Up @@ -773,7 +798,7 @@ impl EditorView {
}

/// Apply the highlighting on the lines where a cursor is active
pub fn cursorline(doc: &Document, view: &View, theme: &Theme) -> impl Decoration {
pub fn cursorline(doc: &Document, view: &View, theme: &Theme, mode: &Mode) -> impl Decoration {
let text = doc.text().slice(..);
// TODO only highlight the visual line that contains the cursor instead of the full visual line
let primary_line = doc.selection(view.id).primary().cursor_line(text);
Expand All @@ -790,7 +815,13 @@ impl EditorView {
.map(|range| range.cursor_line(text))
.collect();

let primary_style = theme.get("ui.cursorline.primary");
let primary_style = match mode {
Mode::Normal => theme.try_get("ui.cursorline.primary.normal"),
Mode::Select => theme.try_get("ui.cursorline.primary.select"),
Mode::Insert => theme.try_get("ui.cursorline.primary.insert"),
}
.unwrap_or(theme.get("ui.cursorline.primary"));

let secondary_style = theme.get("ui.cursorline.secondary");
let viewport = view.area;

Expand Down Expand Up @@ -1517,7 +1548,7 @@ impl Component for EditorView {
let mut status_msg_width = 0;

// commandline
let commandline_msg_pos = if config.commandline { 1 } else { 2 };
let commandline_msg_pos = 1; //if config.commandline { 1 } else { 1 };

// render status msg
if let Some((status_msg, severity)) = &cx.editor.status_msg {
Expand Down Expand Up @@ -1556,7 +1587,11 @@ impl Component for EditorView {
};
surface.set_string(
area.x + area.width.saturating_sub(key_width + macro_width),
area.y + area.height.saturating_sub(commandline_msg_pos),
area.y
+ area
.height
.saturating_sub(commandline_msg_pos)
.saturating_sub(1),
disp.get(disp.len().saturating_sub(key_width as usize)..)
.unwrap_or(&disp),
style,
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Component for SignatureHelp {
}

let sep_style = Style::default();
let borders = BorderType::line_symbols(BorderType::Plain);
let borders = BorderType::line_symbols(BorderType::Rounded);
for x in sig_text_area.left()..sig_text_area.right() {
if let Some(cell) = surface.get_mut(x, sig_text_area.bottom()) {
cell.set_symbol(borders.horizontal).set_style(sep_style);
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ impl Markdown {
}
}
Event::Rule => {
lines.push(Spans::from(Span::styled("---", code_style)));
lines.push(Spans::default());
lines.push(Spans::from(Span::styled("────────────", code_style)));
// lines.push(Spans::default());
}
// TaskListMarker(bool) true if checked
_ => {
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ impl<T: Item + 'static> Component for Menu<T> {

let mut cell;
for i in 0..win_height {
cell = &mut surface[(area.right() - 1, area.top() + i as u16)];
cell = &mut surface[(area.right(), area.top() + i as u16)];

let half_block = if render_borders { "▌" } else { "▐" };
let half_block = "▋";

if scroll_line <= i && i < scroll_line + scroll_height {
// Draw scroll thumb
Expand Down
40 changes: 27 additions & 13 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,22 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
(size, _) if size > MAX_FILE_SIZE_FOR_PREVIEW => {
CachedPreview::LargeFile
}
_ => Document::open(&path, None, None, editor.config.clone())
.map(|doc| {
// Asynchronously highlight the new document
helix_event::send_blocking(
&self.preview_highlight_handler,
path.clone(),
);
CachedPreview::Document(Box::new(doc))
})
.unwrap_or(CachedPreview::NotFound),
_ => Document::open(
&path,
None,
None,
editor.config.clone(),
&editor.diff_providers,
)
.map(|doc| {
// Asynchronously highlight the new document
helix_event::send_blocking(
&self.preview_highlight_handler,
path.clone(),
);
CachedPreview::Document(Box::new(doc))
})
.unwrap_or(CachedPreview::NotFound),
},
)
.unwrap_or(CachedPreview::NotFound);
Expand Down Expand Up @@ -688,12 +694,20 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {

// -- Separator
let sep_style = cx.editor.theme.get("ui.background.separator");
let borders = BorderType::line_symbols(BorderType::Plain);
let header_style = cx.editor.theme.get("ui.picker.header");
let borders = BorderType::line_symbols(BorderType::Rounded);
for x in inner.left()..inner.right() {
if let Some(cell) = surface.get_mut(x, inner.y + 1) {
cell.set_symbol(borders.horizontal).set_style(sep_style);
}
}
if self.columns.len() > 1 {
for x in inner.left()..inner.right() {
if let Some(cell) = surface.get_mut(x, inner.y + 2) {
cell.set_symbol(" ").set_style(header_style);
}
}
}

// -- Render the contents:
// subtract area of prompt from top
Expand Down Expand Up @@ -791,7 +805,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
let mut table = Table::new(options)
.style(text_style)
.highlight_style(selected)
.highlight_symbol(" > ")
.highlight_symbol(" ")
.column_spacing(1)
.widths(&self.widths);

Expand Down Expand Up @@ -960,7 +974,7 @@ impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I,
self.show_preview && self.file_fn.is_some() && area.width > MIN_AREA_WIDTH_FOR_PREVIEW;

let picker_width = if render_preview {
area.width / 2
area.width / 3
} else {
area.width
};
Expand Down
25 changes: 14 additions & 11 deletions helix-term/src/ui/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ impl<T: Component> Popup<T> {
}

fn render_info(&mut self, viewport: Rect, editor: &Editor) -> RenderInfo {
let mut position = editor.cursor().0.unwrap_or_default();
if let Some(old_position) = self
let position = self
.position
.filter(|old_position| old_position.row == position.row)
{
position = old_position;
} else {
self.position = Some(position);
}
.or_else(|| editor.cursor().0)
.unwrap_or_default();
// if let Some(old_position) = self
// .position
// .filter(|old_position| old_position.row == position.row)
// {
// position = old_position;
// } else {
// self.position = Some(position);
// }

let is_menu = self
.contents
Expand Down Expand Up @@ -353,12 +356,12 @@ impl<T: Component> Component for Popup<T> {
let scroll_line = (win_height - scroll_height) * scroll
/ std::cmp::max(1, len.saturating_sub(win_height));

let mut cell;
// let mut cell;
for i in 0..win_height {
cell =
let cell =
&mut surface[(inner.right() - 1 + border as u16, inner.top() + i as u16)];

let half_block = if render_borders { "▌" } else { "▐" };
let half_block = "▋";

if scroll_line <= i && i < scroll_line + scroll_height {
// Draw scroll thumb
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/ui/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Spinner {
}

pub fn dots(interval: u64) -> Self {
Self::new(vec!["", "", "", "", "", "", "", ""], interval)
Self::new(vec!["󰪞", "󰪟", "󰪠", "󰪡", "󰪢", "󰪣", "󰪤", "󰪥"], interval)
}

pub fn start(&mut self) {
Expand Down
Loading

0 comments on commit dae9cab

Please sign in to comment.