| 1 |
use helix_core::indent::IndentStyle; |
| 2 |
use helix_core::{coords_at_pos, encoding, unicode::width::UnicodeWidthStr, Position}; |
| 3 |
use helix_lsp::lsp::DiagnosticSeverity; |
| 4 |
use helix_view::document::DEFAULT_LANGUAGE_NAME; |
| 5 |
use helix_view::{ |
| 6 |
document::{Mode, SCRATCH_BUFFER_NAME}, |
| 7 |
graphics::Rect, |
| 8 |
theme::Style, |
| 9 |
Document, Editor, View, |
| 10 |
}; |
| 11 |
|
| 12 |
use crate::ui::ProgressSpinners; |
| 13 |
|
| 14 |
use helix_view::editor::StatusLineElement as StatusLineElementID; |
| 15 |
use tui::buffer::Buffer as Surface; |
| 16 |
use tui::text::{Span, Spans}; |
| 17 |
|
| 18 |
pub struct RenderContext<'a> { |
| 19 |
pub editor: &'a Editor, |
| 20 |
pub doc: &'a Document, |
| 21 |
pub view: &'a View, |
| 22 |
pub focused: bool, |
| 23 |
pub spinners: &'a ProgressSpinners, |
| 24 |
pub parts: RenderBuffer<'a>, |
| 25 |
} |
| 26 |
|
| 27 |
impl<'a> RenderContext<'a> { |
| 28 |
pub fn new( |
| 29 |
editor: &'a Editor, |
| 30 |
doc: &'a Document, |
| 31 |
view: &'a View, |
| 32 |
focused: bool, |
| 33 |
spinners: &'a ProgressSpinners, |
| 34 |
) -> Self { |
| 35 |
RenderContext { |
| 36 |
editor, |
| 37 |
doc, |
| 38 |
view, |
| 39 |
focused, |
| 40 |
spinners, |
| 41 |
parts: RenderBuffer::default(), |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
#[derive(Default)] |
| 47 |
pub struct RenderBuffer<'a> { |
| 48 |
pub left: Spans<'a>, |
| 49 |
pub center: Spans<'a>, |
| 50 |
pub right: Spans<'a>, |
| 51 |
} |
| 52 |
|
| 53 |
pub fn render(context: &mut RenderContext, viewport: Rect, surface: &mut Surface) { |
| 54 |
let base_style = if context.focused { |
| 55 |
context.editor.theme.get("ui.statusline") |
| 56 |
} else { |
| 57 |
context.editor.theme.get("ui.statusline.inactive") |
| 58 |
}; |
| 59 |
|
| 60 |
surface.set_style(viewport.with_height(1), base_style); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
let config = context.editor.config(); |
| 65 |
|
| 66 |
for element_id in &config.statusline.left { |
| 67 |
let render = get_render_function(*element_id); |
| 68 |
(render)(context, |context, span| { |
| 69 |
append(&mut context.parts.left, span, base_style) |
| 70 |
}); |
| 71 |
} |
| 72 |
|
| 73 |
surface.set_spans( |
| 74 |
viewport.x, |
| 75 |
viewport.y, |
| 76 |
&context.parts.left, |
| 77 |
context.parts.left.width() as u16, |
| 78 |
); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
for element_id in &config.statusline.right { |
| 83 |
let render = get_render_function(*element_id); |
| 84 |
(render)(context, |context, span| { |
| 85 |
append(&mut context.parts.right, span, base_style) |
| 86 |
}) |
| 87 |
} |
| 88 |
|
| 89 |
surface.set_spans( |
| 90 |
viewport.x |
| 91 |
+ viewport |
| 92 |
.width |
| 93 |
.saturating_sub(context.parts.right.width() as u16), |
| 94 |
viewport.y, |
| 95 |
&context.parts.right, |
| 96 |
context.parts.right.width() as u16, |
| 97 |
); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
for element_id in &config.statusline.center { |
| 102 |
let render = get_render_function(*element_id); |
| 103 |
(render)(context, |context, span| { |
| 104 |
append(&mut context.parts.center, span, base_style) |
| 105 |
}) |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
let spacing = 1u16; |
| 110 |
|
| 111 |
let edge_width = context.parts.left.width().max(context.parts.right.width()) as u16; |
| 112 |
let center_max_width = viewport.width.saturating_sub(2 * edge_width + 2 * spacing); |
| 113 |
let center_width = center_max_width.min(context.parts.center.width() as u16); |
| 114 |
|
| 115 |
surface.set_spans( |
| 116 |
viewport.x + viewport.width / 2 - center_width / 2, |
| 117 |
viewport.y, |
| 118 |
&context.parts.center, |
| 119 |
center_width, |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
fn append<'a>(buffer: &mut Spans<'a>, mut span: Span<'a>, base_style: Style) { |
| 124 |
span.style = base_style.patch(span.style); |
| 125 |
buffer.0.push(span); |
| 126 |
} |
| 127 |
|
| 128 |
fn get_render_function<'a, F>(element_id: StatusLineElementID) -> impl Fn(&mut RenderContext<'a>, F) |
| 129 |
where |
| 130 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 131 |
{ |
| 132 |
match element_id { |
| 133 |
helix_view::editor::StatusLineElement::Mode => render_mode, |
| 134 |
helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner, |
| 135 |
helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name, |
| 136 |
helix_view::editor::StatusLineElement::FileName => render_file_name, |
| 137 |
helix_view::editor::StatusLineElement::FileAbsolutePath => render_file_absolute_path, |
| 138 |
helix_view::editor::StatusLineElement::FileModificationIndicator => { |
| 139 |
render_file_modification_indicator |
| 140 |
} |
| 141 |
helix_view::editor::StatusLineElement::ReadOnlyIndicator => render_read_only_indicator, |
| 142 |
helix_view::editor::StatusLineElement::FileEncoding => render_file_encoding, |
| 143 |
helix_view::editor::StatusLineElement::FileLineEnding => render_file_line_ending, |
| 144 |
helix_view::editor::StatusLineElement::FileIndentStyle => render_file_indent_style, |
| 145 |
helix_view::editor::StatusLineElement::FileType => render_file_type, |
| 146 |
helix_view::editor::StatusLineElement::Diagnostics => render_diagnostics, |
| 147 |
helix_view::editor::StatusLineElement::WorkspaceDiagnostics => render_workspace_diagnostics, |
| 148 |
helix_view::editor::StatusLineElement::Selections => render_selections, |
| 149 |
helix_view::editor::StatusLineElement::PrimarySelectionLength => { |
| 150 |
render_primary_selection_length |
| 151 |
} |
| 152 |
helix_view::editor::StatusLineElement::Position => render_position, |
| 153 |
helix_view::editor::StatusLineElement::PositionPercentage => render_position_percentage, |
| 154 |
helix_view::editor::StatusLineElement::TotalLineNumbers => render_total_line_numbers, |
| 155 |
helix_view::editor::StatusLineElement::Separator => render_separator, |
| 156 |
helix_view::editor::StatusLineElement::Spacer => render_spacer, |
| 157 |
helix_view::editor::StatusLineElement::VersionControl => render_version_control, |
| 158 |
helix_view::editor::StatusLineElement::Register => render_register, |
| 159 |
helix_view::editor::StatusLineElement::CurrentWorkingDirectory => render_cwd, |
| 160 |
helix_view::editor::StatusLineElement::CodeActionHint => render_code_action_hint, |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
fn render_mode<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 165 |
where |
| 166 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 167 |
{ |
| 168 |
let visible = context.focused; |
| 169 |
let config = context.editor.config(); |
| 170 |
let modenames = &config.statusline.mode; |
| 171 |
let mode_str = match context.editor.mode() { |
| 172 |
Mode::Insert => &modenames.insert, |
| 173 |
Mode::Select => &modenames.select, |
| 174 |
Mode::Normal => &modenames.normal, |
| 175 |
}; |
| 176 |
let content = if visible { |
| 177 |
format!(" {mode_str} ") |
| 178 |
} else { |
| 179 |
|
| 180 |
" ".repeat(mode_str.width() + 2) |
| 181 |
}; |
| 182 |
let style = if visible && config.color_modes { |
| 183 |
match context.editor.mode() { |
| 184 |
Mode::Insert => context.editor.theme.get("ui.statusline.insert"), |
| 185 |
Mode::Select => context.editor.theme.get("ui.statusline.select"), |
| 186 |
Mode::Normal => context.editor.theme.get("ui.statusline.normal"), |
| 187 |
} |
| 188 |
} else { |
| 189 |
Style::default() |
| 190 |
}; |
| 191 |
write(context, Span::styled(content, style)); |
| 192 |
} |
| 193 |
|
| 194 |
fn render_lsp_spinner<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 195 |
where |
| 196 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 197 |
{ |
| 198 |
write( |
| 199 |
context, |
| 200 |
context |
| 201 |
.doc |
| 202 |
.language_servers() |
| 203 |
.find_map(|srv| { |
| 204 |
context |
| 205 |
.spinners |
| 206 |
.get(srv.id()) |
| 207 |
.and_then(|spinner| spinner.frame()) |
| 208 |
}) |
| 209 |
|
| 210 |
.unwrap_or(" ") |
| 211 |
.into(), |
| 212 |
); |
| 213 |
} |
| 214 |
|
| 215 |
fn render_diagnostics<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 216 |
where |
| 217 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 218 |
{ |
| 219 |
use helix_core::diagnostic::Severity; |
| 220 |
let (hints, info, warnings, errors) = |
| 221 |
context |
| 222 |
.doc |
| 223 |
.diagnostics() |
| 224 |
.iter() |
| 225 |
.fold((0, 0, 0, 0), |mut counts, diag| { |
| 226 |
match diag.severity { |
| 227 |
Some(Severity::Hint) | None => counts.0 += 1, |
| 228 |
Some(Severity::Info) => counts.1 += 1, |
| 229 |
Some(Severity::Warning) => counts.2 += 1, |
| 230 |
Some(Severity::Error) => counts.3 += 1, |
| 231 |
} |
| 232 |
counts |
| 233 |
}); |
| 234 |
|
| 235 |
for sev in &context.editor.config().statusline.diagnostics { |
| 236 |
match sev { |
| 237 |
Severity::Hint if hints > 0 => { |
| 238 |
write(context, Span::styled("●", context.editor.theme.get("hint"))); |
| 239 |
write(context, format!(" {} ", hints).into()); |
| 240 |
} |
| 241 |
Severity::Info if info > 0 => { |
| 242 |
write(context, Span::styled("●", context.editor.theme.get("info"))); |
| 243 |
write(context, format!(" {} ", info).into()); |
| 244 |
} |
| 245 |
Severity::Warning if warnings > 0 => { |
| 246 |
write( |
| 247 |
context, |
| 248 |
Span::styled("●", context.editor.theme.get("warning")), |
| 249 |
); |
| 250 |
write(context, format!(" {} ", warnings).into()); |
| 251 |
} |
| 252 |
Severity::Error if errors > 0 => { |
| 253 |
write( |
| 254 |
context, |
| 255 |
Span::styled("●", context.editor.theme.get("error")), |
| 256 |
); |
| 257 |
write(context, format!(" {} ", errors).into()); |
| 258 |
} |
| 259 |
_ => {} |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
fn render_workspace_diagnostics<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 265 |
where |
| 266 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 267 |
{ |
| 268 |
use helix_core::diagnostic::Severity; |
| 269 |
let (hints, info, warnings, errors) = context.editor.diagnostics.values().flatten().fold( |
| 270 |
(0u32, 0u32, 0u32, 0u32), |
| 271 |
|mut counts, (diag, _)| { |
| 272 |
match diag.severity { |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
Some(DiagnosticSeverity::WARNING) => counts.2 += 1, |
| 278 |
Some(DiagnosticSeverity::ERROR) => counts.3 += 1, |
| 279 |
Some(DiagnosticSeverity::HINT) => counts.0 += 1, |
| 280 |
Some(DiagnosticSeverity::INFORMATION) => counts.1 += 1, |
| 281 |
|
| 282 |
_ => counts.0 += 1, |
| 283 |
} |
| 284 |
counts |
| 285 |
}, |
| 286 |
); |
| 287 |
|
| 288 |
let sevs_to_show = &context.editor.config().statusline.workspace_diagnostics; |
| 289 |
|
| 290 |
|
| 291 |
if !sevs_to_show.iter().any(|sev| match sev { |
| 292 |
Severity::Hint => hints != 0, |
| 293 |
Severity::Info => info != 0, |
| 294 |
Severity::Warning => warnings != 0, |
| 295 |
Severity::Error => errors != 0, |
| 296 |
}) { |
| 297 |
return; |
| 298 |
} |
| 299 |
|
| 300 |
write(context, " W ".into()); |
| 301 |
|
| 302 |
for sev in sevs_to_show { |
| 303 |
match sev { |
| 304 |
Severity::Hint if hints > 0 => { |
| 305 |
write(context, Span::styled("●", context.editor.theme.get("hint"))); |
| 306 |
write(context, format!(" {} ", hints).into()); |
| 307 |
} |
| 308 |
Severity::Info if info > 0 => { |
| 309 |
write(context, Span::styled("●", context.editor.theme.get("info"))); |
| 310 |
write(context, format!(" {} ", info).into()); |
| 311 |
} |
| 312 |
Severity::Warning if warnings > 0 => { |
| 313 |
write( |
| 314 |
context, |
| 315 |
Span::styled("●", context.editor.theme.get("warning")), |
| 316 |
); |
| 317 |
write(context, format!(" {} ", warnings).into()); |
| 318 |
} |
| 319 |
Severity::Error if errors > 0 => { |
| 320 |
write( |
| 321 |
context, |
| 322 |
Span::styled("●", context.editor.theme.get("error")), |
| 323 |
); |
| 324 |
write(context, format!(" {} ", errors).into()); |
| 325 |
} |
| 326 |
_ => {} |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
fn render_selections<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 332 |
where |
| 333 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 334 |
{ |
| 335 |
let selection = context.doc.selection(context.view.id); |
| 336 |
let count = selection.len(); |
| 337 |
write( |
| 338 |
context, |
| 339 |
if count == 1 { |
| 340 |
" 1 sel ".into() |
| 341 |
} else { |
| 342 |
format!(" {}/{count} sels ", selection.primary_index() + 1).into() |
| 343 |
}, |
| 344 |
); |
| 345 |
} |
| 346 |
|
| 347 |
fn render_primary_selection_length<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 348 |
where |
| 349 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 350 |
{ |
| 351 |
let tot_sel = context.doc.selection(context.view.id).primary().len(); |
| 352 |
write( |
| 353 |
context, |
| 354 |
format!(" {} char{} ", tot_sel, if tot_sel == 1 { "" } else { "s" }).into(), |
| 355 |
); |
| 356 |
} |
| 357 |
|
| 358 |
fn get_position(context: &RenderContext) -> Position { |
| 359 |
coords_at_pos( |
| 360 |
context.doc.text().slice(..), |
| 361 |
context |
| 362 |
.doc |
| 363 |
.selection(context.view.id) |
| 364 |
.primary() |
| 365 |
.cursor(context.doc.text().slice(..)), |
| 366 |
) |
| 367 |
} |
| 368 |
|
| 369 |
fn render_position<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 370 |
where |
| 371 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 372 |
{ |
| 373 |
let position = get_position(context); |
| 374 |
write( |
| 375 |
context, |
| 376 |
format!(" {}:{} ", position.row + 1, position.col + 1).into(), |
| 377 |
); |
| 378 |
} |
| 379 |
|
| 380 |
fn render_total_line_numbers<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 381 |
where |
| 382 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 383 |
{ |
| 384 |
let total_line_numbers = context.doc.text().len_lines(); |
| 385 |
|
| 386 |
write(context, format!(" {} ", total_line_numbers).into()); |
| 387 |
} |
| 388 |
|
| 389 |
fn render_position_percentage<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 390 |
where |
| 391 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 392 |
{ |
| 393 |
let position = get_position(context); |
| 394 |
let maxrows = context.doc.text().len_lines(); |
| 395 |
write( |
| 396 |
context, |
| 397 |
format!("{}%", (position.row + 1) * 100 / maxrows).into(), |
| 398 |
); |
| 399 |
} |
| 400 |
|
| 401 |
fn render_file_encoding<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 402 |
where |
| 403 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 404 |
{ |
| 405 |
let enc = context.doc.encoding(); |
| 406 |
|
| 407 |
if enc != encoding::UTF_8 { |
| 408 |
write(context, format!(" {} ", enc.name()).into()); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
fn render_file_line_ending<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 413 |
where |
| 414 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 415 |
{ |
| 416 |
use helix_core::LineEnding::*; |
| 417 |
let line_ending = match context.doc.line_ending { |
| 418 |
Crlf => "CRLF", |
| 419 |
LF => "LF", |
| 420 |
#[cfg(feature = "unicode-lines")] |
| 421 |
VT => "VT", |
| 422 |
#[cfg(feature = "unicode-lines")] |
| 423 |
FF => "FF", |
| 424 |
#[cfg(feature = "unicode-lines")] |
| 425 |
CR => "CR", |
| 426 |
#[cfg(feature = "unicode-lines")] |
| 427 |
Nel => "NEL", |
| 428 |
#[cfg(feature = "unicode-lines")] |
| 429 |
LS => "LS", |
| 430 |
#[cfg(feature = "unicode-lines")] |
| 431 |
PS => "PS", |
| 432 |
}; |
| 433 |
|
| 434 |
write(context, format!(" {} ", line_ending).into()); |
| 435 |
} |
| 436 |
|
| 437 |
fn render_file_type<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 438 |
where |
| 439 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 440 |
{ |
| 441 |
let file_type = context.doc.language_name().unwrap_or(DEFAULT_LANGUAGE_NAME); |
| 442 |
|
| 443 |
write(context, format!(" {} ", file_type).into()); |
| 444 |
} |
| 445 |
|
| 446 |
fn render_file_name<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 447 |
where |
| 448 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 449 |
{ |
| 450 |
let title = { |
| 451 |
let rel_path = context.doc.relative_path(); |
| 452 |
let path = rel_path |
| 453 |
.as_ref() |
| 454 |
.map(|p| p.to_string_lossy()) |
| 455 |
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into()); |
| 456 |
format!(" {} ", path) |
| 457 |
}; |
| 458 |
|
| 459 |
write(context, title.into()); |
| 460 |
} |
| 461 |
|
| 462 |
fn render_file_absolute_path<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 463 |
where |
| 464 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 465 |
{ |
| 466 |
let title = { |
| 467 |
let path = context |
| 468 |
.doc |
| 469 |
.path() |
| 470 |
.as_ref() |
| 471 |
.map_or_else(|| SCRATCH_BUFFER_NAME.into(), |p| p.to_string_lossy()); |
| 472 |
format!(" {} ", path) |
| 473 |
}; |
| 474 |
|
| 475 |
write(context, title.into()); |
| 476 |
} |
| 477 |
|
| 478 |
fn render_file_modification_indicator<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 479 |
where |
| 480 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 481 |
{ |
| 482 |
let title = if context.doc.is_modified() { |
| 483 |
"[+]" |
| 484 |
} else { |
| 485 |
" " |
| 486 |
}; |
| 487 |
|
| 488 |
write(context, title.into()); |
| 489 |
} |
| 490 |
|
| 491 |
fn render_read_only_indicator<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 492 |
where |
| 493 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 494 |
{ |
| 495 |
let title = if context.doc.readonly { |
| 496 |
" [readonly] " |
| 497 |
} else { |
| 498 |
"" |
| 499 |
}; |
| 500 |
write(context, title.into()); |
| 501 |
} |
| 502 |
|
| 503 |
fn render_file_base_name<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 504 |
where |
| 505 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 506 |
{ |
| 507 |
let title = { |
| 508 |
let rel_path = context.doc.relative_path(); |
| 509 |
let path = rel_path |
| 510 |
.as_ref() |
| 511 |
.and_then(|p| p.file_name().map(|s| s.to_string_lossy())) |
| 512 |
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into()); |
| 513 |
format!(" {} ", path) |
| 514 |
}; |
| 515 |
|
| 516 |
write(context, title.into()); |
| 517 |
} |
| 518 |
|
| 519 |
fn render_separator<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 520 |
where |
| 521 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 522 |
{ |
| 523 |
let sep = &context.editor.config().statusline.separator; |
| 524 |
let style = context.editor.theme.get("ui.statusline.separator"); |
| 525 |
|
| 526 |
write(context, Span::styled(sep.to_string(), style)); |
| 527 |
} |
| 528 |
|
| 529 |
fn render_spacer<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 530 |
where |
| 531 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 532 |
{ |
| 533 |
write(context, " ".into()); |
| 534 |
} |
| 535 |
|
| 536 |
fn render_version_control<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 537 |
where |
| 538 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 539 |
{ |
| 540 |
let head = context |
| 541 |
.doc |
| 542 |
.version_control_head() |
| 543 |
.unwrap_or_default() |
| 544 |
.to_string(); |
| 545 |
|
| 546 |
write(context, head.into()); |
| 547 |
} |
| 548 |
|
| 549 |
fn render_register<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 550 |
where |
| 551 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 552 |
{ |
| 553 |
if let Some(reg) = context.editor.selected_register { |
| 554 |
write(context, format!(" reg={} ", reg).into()) |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
fn render_file_indent_style<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 559 |
where |
| 560 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 561 |
{ |
| 562 |
let style = context.doc.indent_style; |
| 563 |
|
| 564 |
write( |
| 565 |
context, |
| 566 |
match style { |
| 567 |
IndentStyle::Tabs => " tabs ".into(), |
| 568 |
IndentStyle::Spaces(indent) => { |
| 569 |
format!(" {} space{} ", indent, if indent == 1 { "" } else { "s" }).into() |
| 570 |
} |
| 571 |
}, |
| 572 |
); |
| 573 |
} |
| 574 |
|
| 575 |
fn render_cwd<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 576 |
where |
| 577 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 578 |
{ |
| 579 |
let cwd = helix_stdx::env::current_working_dir(); |
| 580 |
let cwd = cwd |
| 581 |
.file_name() |
| 582 |
.unwrap_or_default() |
| 583 |
.to_string_lossy() |
| 584 |
.to_string(); |
| 585 |
write(context, cwd.into()) |
| 586 |
} |
| 587 |
|
| 588 |
fn render_code_action_hint<'a, F>(context: &mut RenderContext<'a>, write: F) |
| 589 |
where |
| 590 |
F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy, |
| 591 |
{ |
| 592 |
if context.focused && context.doc.code_action_hints(context.view.id) { |
| 593 |
write(context, " ⋮ ".into()) |
| 594 |
} |
| 595 |
} |