mirror of https://github.com/Aloxaf/silicon
fix: build cache output dir
This commit is contained in:
parent
6a3f037ae2
commit
e0fd52b442
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "silicon"
|
||||
version = "0.4.3"
|
||||
version = "0.5.0"
|
||||
description = "Create beautiful image of your code"
|
||||
authors = ["Aloxaf <aloxafx@gmail.com>"]
|
||||
categories = ["command-line-utilities"]
|
||||
|
|
|
@ -125,9 +125,10 @@ see `silicon --help` for detail
|
|||
|
||||
## Adding new syntaxes / themes
|
||||
|
||||
Silicon reads syntax-definition and theme cache from bat's cache directory.
|
||||
Silicon reads syntax-definition and theme cache from user's cache directory.
|
||||
|
||||
You can find the steps to add new syntaxes / themes for bat here: [sharkdp/bat#adding-new-syntaxes--language-definitions](https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions).
|
||||
The steps to add new syntaxes / themes is as same as bat: [sharkdp/bat#adding-new-syntaxes--language-definitions](https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions).
|
||||
Just replace `bat cache --build` to `silicon --build-cache`.
|
||||
|
||||
## Configuration file
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ impl HighlightingAssets {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dump_to_file(&self) -> Result<()> {
|
||||
dumps::dump_to_file(&self.syntax_set, "./syntaxes.bin")?;
|
||||
dumps::dump_to_file(&self.theme_set, "./themes.bin")?;
|
||||
pub fn dump_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||
dumps::dump_to_file(&self.syntax_set, path.as_ref().join("syntaxes.bin"))?;
|
||||
dumps::dump_to_file(&self.theme_set, path.as_ref().join("themes.bin"))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,8 +202,8 @@ pub struct Config {
|
|||
// #[structopt(long)]
|
||||
// watermark: Option<String>,
|
||||
/// build syntax definition and theme cache
|
||||
#[structopt(long)]
|
||||
pub build_cache: Option<PathBuf>,
|
||||
#[structopt(long, value_name = "OUTPUT_DIR")]
|
||||
pub build_cache: Option<Option<PathBuf>>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
|
|
@ -3,6 +3,7 @@ extern crate anyhow;
|
|||
|
||||
use anyhow::Error;
|
||||
use image::DynamicImage;
|
||||
use std::env;
|
||||
use structopt::StructOpt;
|
||||
use syntect::easy::HighlightLines;
|
||||
use syntect::util::LinesWithEndings;
|
||||
|
@ -17,9 +18,9 @@ use {image::ImageOutputFormat, pasteboard::Pasteboard};
|
|||
use {image::ImageOutputFormat, std::process::Command};
|
||||
|
||||
mod config;
|
||||
use crate::config::{config_file, get_args_from_config_file};
|
||||
use config::Config;
|
||||
use crate::config::{config_file, get_args_from_config_file, Config};
|
||||
use silicon::assets::HighlightingAssets;
|
||||
use silicon::directories::PROJECT_DIRS;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn dump_image_to_clipboard(image: &DynamicImage) -> Result<(), Error> {
|
||||
|
@ -86,8 +87,12 @@ fn run() -> Result<(), Error> {
|
|||
|
||||
if let Some(path) = config.build_cache {
|
||||
let mut ha = HighlightingAssets::new();
|
||||
ha.add_from_folder(path)?;
|
||||
ha.dump_to_file()?;
|
||||
ha.add_from_folder(env::current_dir()?)?;
|
||||
if let Some(path) = path {
|
||||
ha.dump_to_file(path)?;
|
||||
} else {
|
||||
ha.dump_to_file(PROJECT_DIRS.cache_dir())?;
|
||||
}
|
||||
return Ok(());
|
||||
} else if config.list_themes {
|
||||
for i in ts.themes.keys() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use lazy_static::lazy_static;
|
||||
use std::env;
|
||||
use std::fs::create_dir_all;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub struct SiliconProjectDirs {
|
||||
|
@ -22,6 +23,9 @@ impl SiliconProjectDirs {
|
|||
|
||||
let config_dir = config_dir_op.map(|d| d.join("silicon"))?;
|
||||
|
||||
create_dir_all(&config_dir).expect("cannot create config dir");
|
||||
create_dir_all(&cache_dir).expect("cannot create cache dir");
|
||||
|
||||
Some(Self {
|
||||
cache_dir,
|
||||
config_dir,
|
||||
|
|
Loading…
Reference in New Issue