mirror of
https://github.com/mfontanini/presenterm.git
synced 2025-05-05 15:32:58 +00:00
Add proper acknowledgements to bat
via --acknowledgements
This commit is contained in:
parent
36239dab3e
commit
c8e8786a47
BIN
bat/acknowledgements.txt
Normal file
BIN
bat/acknowledgements.txt
Normal file
Binary file not shown.
1
bat/bat.git-hash
Normal file
1
bat/bat.git-hash
Normal file
@ -0,0 +1 @@
|
||||
3d87b25b190e0990e0e75a2ab8f994d6c277d263
|
@ -12,16 +12,18 @@ script_path=$(realpath "$0")
|
||||
script_dir=$(dirname "$script_path")
|
||||
git_hash=$1
|
||||
clone_path=$(mktemp -d)
|
||||
output_file="$script_dir/syntaxes.bin"
|
||||
output_tag="$script_dir/syntaxes.git-hash"
|
||||
|
||||
echo "Cloning repo @ ${git_hash} into '$clone_path'"
|
||||
git clone https://github.com/sharkdp/bat.git $clone_path
|
||||
cd $clone_path
|
||||
git reset --hard $git_hash
|
||||
|
||||
cp assets/syntaxes.bin $output_file
|
||||
echo $git_hash > $output_tag
|
||||
cp assets/syntaxes.bin "$script_dir"
|
||||
|
||||
echo "syntaxes file copied to '$output_file'"
|
||||
acknowledgements_file="$script_dir/acknowledgements.txt"
|
||||
cp LICENSE-MIT "$acknowledgements_file"
|
||||
zlib-flate -uncompress < assets/acknowledgements.bin >> "$acknowledgements_file"
|
||||
echo $git_hash > "$script_dir/bat.git-hash"
|
||||
|
||||
echo "syntaxes/themes updated"
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
".cargo"
|
||||
"src"
|
||||
"themes"
|
||||
"syntaxes"
|
||||
"bat"
|
||||
];
|
||||
|
||||
buildSrc = flakeboxLib.filterSubPaths {
|
||||
|
27
src/main.rs
27
src/main.rs
@ -11,7 +11,8 @@ use std::path::{Path, PathBuf};
|
||||
#[command(author, version, about = create_splash(), long_about = create_splash(), arg_required_else_help = true)]
|
||||
struct Cli {
|
||||
/// The path to the markdown file that contains the presentation.
|
||||
path: PathBuf,
|
||||
#[clap(group = "target")]
|
||||
path: Option<PathBuf>,
|
||||
|
||||
/// Export the presentation as a PDF rather than displaying it.
|
||||
#[clap(short, long)]
|
||||
@ -32,6 +33,10 @@ struct Cli {
|
||||
/// The theme to use.
|
||||
#[clap(short, long, default_value = "dark")]
|
||||
theme: String,
|
||||
|
||||
/// Display acknowledgements.
|
||||
#[clap(long, group = "target")]
|
||||
acknowledgements: bool,
|
||||
}
|
||||
|
||||
fn create_splash() -> String {
|
||||
@ -49,6 +54,11 @@ fn create_splash() -> String {
|
||||
)
|
||||
}
|
||||
|
||||
fn display_acknowledgements() {
|
||||
let acknowledgements = include_bytes!("../bat/acknowledgements.txt");
|
||||
println!("{}", String::from_utf8_lossy(acknowledgements));
|
||||
}
|
||||
|
||||
fn run(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let Some(default_theme) = PresentationTheme::from_name(&cli.theme) else {
|
||||
let mut cmd = Cli::command();
|
||||
@ -65,20 +75,25 @@ fn run(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let arena = Arena::new();
|
||||
let parser = MarkdownParser::new(&arena);
|
||||
let default_highlighter = CodeHighlighter::new("base16-ocean.dark")?;
|
||||
let resources_path = cli.path.parent().unwrap_or(Path::new("/"));
|
||||
if cli.acknowledgements {
|
||||
display_acknowledgements();
|
||||
return Ok(());
|
||||
}
|
||||
let path = cli.path.expect("no path");
|
||||
let resources_path = path.parent().unwrap_or(Path::new("/"));
|
||||
let resources = Resources::new(resources_path);
|
||||
if cli.export_pdf || cli.generate_pdf_metadata {
|
||||
let mut exporter = Exporter::new(parser, &default_theme, default_highlighter, resources);
|
||||
if cli.export_pdf {
|
||||
exporter.export_pdf(&cli.path)?;
|
||||
exporter.export_pdf(&path)?;
|
||||
} else {
|
||||
let meta = exporter.generate_metadata(&cli.path)?;
|
||||
let meta = exporter.generate_metadata(&path)?;
|
||||
println!("{}", serde_json::to_string_pretty(&meta)?);
|
||||
}
|
||||
} else {
|
||||
let commands = CommandSource::new(&cli.path);
|
||||
let commands = CommandSource::new(&path);
|
||||
let presenter = Presenter::new(&default_theme, default_highlighter, commands, parser, resources, mode);
|
||||
presenter.present(&cli.path)?;
|
||||
presenter.present(&path)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user