mirror of
https://github.com/lotabout/skim.git
synced 2026-09-10 07:16:23 -04:00
wip: dynamic header function
This commit is contained in:
parent
a3e88a9f65
commit
f595db58d5
|
|
@ -12,10 +12,18 @@ use skim_tuikit::prelude::*;
|
|||
use std::cmp::max;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type HeaderCallback = Arc<dyn Fn(???)>;
|
||||
|
||||
pub struct Header {
|
||||
// The lines forming the header itself
|
||||
header: Vec<AnsiString<'static>>,
|
||||
// A function, used for dynamic header rendering
|
||||
header_fn: Option<HeaderCallback>,
|
||||
// The size of the tabstop
|
||||
tabstop: usize,
|
||||
// Whether or not the layout is reversed
|
||||
reverse: bool,
|
||||
// The color theme
|
||||
theme: Arc<ColorTheme>,
|
||||
|
||||
// for reserved header items
|
||||
|
|
@ -26,6 +34,7 @@ impl Header {
|
|||
pub fn empty() -> Self {
|
||||
Self {
|
||||
header: vec![],
|
||||
header_fn: None,
|
||||
tabstop: 8,
|
||||
reverse: false,
|
||||
theme: Arc::new(*DEFAULT_THEME),
|
||||
|
|
@ -50,14 +59,17 @@ impl Header {
|
|||
self.reverse = true;
|
||||
}
|
||||
|
||||
match &options.header {
|
||||
None => {}
|
||||
Some(header) => {
|
||||
match (&options.header, &options.header_fn) {
|
||||
(None, None) => {}
|
||||
(Some(header), None) => {
|
||||
let mut parser = ANSIParser::default();
|
||||
if !header.is_empty() {
|
||||
self.header = str_lines(header).into_iter().map(|l| parser.parse_ansi(l)).collect();
|
||||
}
|
||||
}
|
||||
(_, Some(header_fn)) => {
|
||||
self.header_fn = Some(header_fn.clone());
|
||||
},
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -871,6 +871,14 @@ pub struct SkimOptions {
|
|||
/// and return a Vec<String> with the lines to display in UTF-8
|
||||
#[clap(skip)]
|
||||
pub preview_fn: Option<PreviewCallback>,
|
||||
/// Header Callback
|
||||
///
|
||||
/// Used to define a function or closure for the preview window, instead of a shell command.
|
||||
///
|
||||
/// The function will take a `Vec<Arc<dyn SkimItem>>>` containing the currently selected items
|
||||
/// and return a Vec<String> with the lines to display in UTF-8
|
||||
#[clap(skip)]
|
||||
pub header_fn: Option<HeaderCallback>,
|
||||
}
|
||||
|
||||
impl Default for SkimOptions {
|
||||
|
|
|
|||
Loading…
Reference in a new issue