deps: update deps and assets

close #203 #199 #200
This commit is contained in:
Aloxaf 2022-10-13 14:41:57 +08:00
parent e3311d72de
commit 83dac98d5e
14 changed files with 481 additions and 1345 deletions

696
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,8 +10,8 @@ license = "MIT"
edition = "2018"
[dependencies]
dirs = "3.0"
imageproc = "0.22.0"
dirs = "4.0"
imageproc = "0.23.0"
clipboard = "0.5.0"
tempfile = "3.1.0"
conv = "0.3.3"
@ -26,17 +26,17 @@ pasteboard = "0.1.3"
[target.'cfg(target_os = "windows")'.dependencies]
clipboard-win = "4.0.2"
image = { version = "0.23", default-features = false, features = ["jpeg", "bmp", "jpeg_rayon"] }
image = { version = "0.24", default-features = false, features = ["jpeg", "bmp", "jpeg_rayon"] }
[dependencies.image]
version = "0.23"
version = "0.24"
default-features = false
features = ["jpeg", "png", "jpeg_rayon"]
[dependencies.syntect]
version = "4.4"
version = "5.0"
default-features = false
features = ["parsing", "dump-load", "regex-onig"]
features = ["parsing", "dump-load", "regex-onig", "plist-load", "yaml-load"]
[dependencies.anyhow]
version = "1.0"
@ -49,13 +49,13 @@ features = ["color", "wrap_help"]
optional = true
[dependencies.env_logger]
version = "0.8.2"
version = "0.9.1"
default-features = false
features = ["termcolor", "atty", "humantime"]
optional = true
[dependencies.font-kit]
version= "0.10"
version= "0.11"
features= ["loader-freetype-default", "source-fontconfig-default"]
[dependencies.harfbuzz-sys]

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python
# Sync themes and syntaxes from [bat](https://github.com/sharkdp/bat/tree/master/assets)
import os
from glob import glob
from shutil import copy
if not os.path.exists('../../bat'):
os.system('git clone https://github.com/sharkdp/bat ../../bat')
else:
os.system('git -C ../../bat pull')
for syntax_file in glob('../../bat/assets/syntaxes/**/*.sublime-syntax'):
copy(syntax_file, './syntaxes/')
for theme_file in glob('../../bat/assets/themes/**/*.tmTheme'):
copy(theme_file, './themes/')
os.system('bat cache --build --source . --target .')
print('Finished.')

15
assets/sync_from_bat.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
if [[ -d ../../bat ]]; then
git -C ../../bat pull
else
git clone --recurse-submodules https://github.com/sharkdp/bat ../../bat
fi
rm -rf ./syntaxes/* ./themes/*
cp -r ../../bat/assets/syntaxes/* ./syntaxes/
cp -r ../../bat/assets/themes/* ./themes/
silicon --build-cache .
echo Finished.

Binary file not shown.

Binary file not shown.

View File

@ -1,940 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Dracula Theme v1.4.3
#
# https://github.com/dracula/sublime
#
# Copyright 2013-present, All rights reserved
#
# Code licensed under the MIT license
#
# @author Zeno Rocha <hi@zenorocha.com>
-->
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Dracula</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
<dict>
<key>background</key>
<string>#282a36</string>
<key>caret</key>
<string>#f8f8f0</string>
<key>block_caret</key>
<string>#999a9e</string>
<key>foreground</key>
<string>#f8f8f2</string>
<key>invisibles</key>
<string>#3B3A32</string>
<key>lineHighlight</key>
<string>#44475a</string>
<key>selection</key>
<string>#44475a</string>
<key>findHighlight</key>
<string>#effb7b</string>
<key>findHighlightForeground</key>
<string>#000000</string>
<key>selectionBorder</key>
<string>#222218</string>
<key>activeGuide</key>
<string>#9D550FB0</string>
<key>bracketsForeground</key>
<string>#F8F8F2A5</string>
<key>bracketsOptions</key>
<string>underline</string>
<key>bracketContentsForeground</key>
<string>#F8F8F2A5</string>
<key>bracketContentsOptions</key>
<string>underline</string>
<key>tagsOptions</key>
<string>stippled_underline</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272a4</string>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>String</string>
<key>scope</key>
<string>string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f1fa8c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Number</string>
<key>scope</key>
<string>constant.numeric</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Built-in constant</string>
<key>scope</key>
<string>constant.language</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>User-defined constant</string>
<key>scope</key>
<string>constant.character, constant.other</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable</string>
<key>scope</key>
<string>variable</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Ruby's @variable</string>
<key>scope</key>
<string>variable.other.readwrite.instance</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>String interpolation</string>
<key>scope</key>
<string>constant.character.escaped, constant.character.escape, string source, string source.ruby</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Ruby Regexp</string>
<key>scope</key>
<string>source.ruby string.regexp.classic.ruby,source.ruby string.regexp.mod-r.ruby</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff5555</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Keyword</string>
<key>scope</key>
<string>keyword</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage</string>
<key>scope</key>
<string>storage</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage type</string>
<key>scope</key>
<string>storage.type</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Namespace</string>
<key>scope</key>
<string>storage.type.namespace</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Class</string>
<key>scope</key>
<string>storage.type.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Class name</string>
<key>scope</key>
<string>entity.name.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Meta Path</string>
<key>scope</key>
<string>meta.path</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Inherited class</string>
<key>scope</key>
<string>entity.other.inherited-class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic underline</string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function name</string>
<key>scope</key>
<string>entity.name.function</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Function argument</string>
<key>scope</key>
<string>variable.parameter</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tag name</string>
<key>scope</key>
<string>entity.name.tag</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tag attribute</string>
<key>scope</key>
<string>entity.other.attribute-name</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library function</string>
<key>scope</key>
<string>support.function</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library constant</string>
<key>scope</key>
<string>support.constant</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#6be5fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library class&#x2f;type</string>
<key>scope</key>
<string>support.type, support.class</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Library variable</string>
<key>scope</key>
<string>support.other.variable</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support Other Namespace</string>
<key>scope</key>
<string>support.other.namespace</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#66d9ef</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Invalid</string>
<key>scope</key>
<string>invalid</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#ff79c6</string>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#F8F8F0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Invalid deprecated</string>
<key>scope</key>
<string>invalid.deprecated</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#bd93f9</string>
<key>foreground</key>
<string>#F8F8F0</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON String</string>
<key>scope</key>
<string>meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#CFCFC2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.header</string>
<key>scope</key>
<string>meta.diff, meta.diff.header</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272a4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.inserted</string>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>diff.changed</string>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#E6DB74</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>constant.numeric.line-number.find-in-files - match</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>entity.name.filename</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#E6DB74</string>
</dict>
</dict>
<dict>
<key>scope</key>
<string>message.error</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F83333</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON Punctuation</string>
<key>scope</key>
<string>punctuation.definition.string.begin.json - meta.structure.dictionary.value.json, punctuation.definition.string.end.json - meta.structure.dictionary.value.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#EEEEEE</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON Structure</string>
<key>scope</key>
<string>meta.structure.dictionary.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON String</string>
<key>scope</key>
<string>meta.structure.dictionary.value.json string.quoted.double.json</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#f1fa8c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 6 deep</string>
<key>scope</key>
<string>meta meta meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 5 deep</string>
<key>scope</key>
<string>meta meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 4 deep</string>
<key>scope</key>
<string>meta meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 3 deep</string>
<key>scope</key>
<string>meta meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 2 deep</string>
<key>scope</key>
<string>meta meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>JSON: 1 deep</string>
<key>scope</key>
<string>meta meta.structure.dictionary.value string</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffb86c</string>
</dict>
</dict>
<!-- Markdown Tweaks -->
<dict>
<key>name</key>
<string>Markup: strike</string>
<key>scope</key>
<string>markup.strike</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: bold</string>
<key>scope</key>
<string>markup.bold</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: italic</string>
<key>scope</key>
<string>markup.italic</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#FFB86C</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: heading</string>
<key>scope</key>
<string>markup.heading</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8BE9FD</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: List Items Punctuation</string>
<key>scope</key>
<string>punctuation.definition.list_item.markdown</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Blockquote</string>
<key>scope</key>
<string>markup.quote</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Blockquote Punctuation</string>
<key>scope</key>
<string>punctuation.definition.blockquote.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>background</key>
<string>#6272A4</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Separator</string>
<key>scope</key>
<string>meta.separator</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: raw inline</string>
<key>scope</key>
<string>text.html.markdown markup.raw.inline</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50FA7B</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: underline</string>
<key>scope</key>
<string>markup.underline</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>underline</string>
<key>foreground</key>
<string>#BD93F9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markup: Raw block</string>
<key>scope</key>
<string>markup.raw.block</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#CFCFC2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Raw Block fenced source</string>
<key>scope</key>
<string>markup.raw.block.fenced.markdown source</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#F8F8F2</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Fenced Bode Block</string>
<key>scope</key>
<string>punctuation.definition.fenced.markdown, variable.language.fenced.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Markdown: Fenced Language</string>
<key>scope</key>
<string>variable.language.fenced.markdown</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#6272A4</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Accessor</string>
<key>scope</key>
<string>punctuation.accessor</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Meta Function Return Type</string>
<key>scope</key>
<string>meta.function.return-type</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FF79C6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Block Begin</string>
<key>scope</key>
<string>punctuation.section.block.begin</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Block End</string>
<key>scope</key>
<string>punctuation.section.block.end</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Embedded Begin</string>
<key>scope</key>
<string>punctuation.section.embedded.begin</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Section Embedded End</string>
<key>scope</key>
<string>punctuation.section.embedded.end</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation Separator Namespace</string>
<key>scope</key>
<string>punctuation.separator.namespace</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Function</string>
<key>scope</key>
<string>variable.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#50fa7b</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Other</string>
<key>scope</key>
<string>variable.other</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variable Language</string>
<key>scope</key>
<string>variable.language</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Module Ruby</string>
<key>scope</key>
<string>entity.name.module.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Constant Ruby</string>
<key>scope</key>
<string>entity.name.constant.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#bd93f9</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support Function Builtin Ruby</string>
<key>scope</key>
<string>support.function.builtin.ruby</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffffff</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage Type Namespace CS</string>
<key>scope</key>
<string>storage.type.namespace.cs</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ff79c6</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Entity Name Namespace CS</string>
<key>scope</key>
<string>entity.name.namespace.cs</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#8be9fd</string>
</dict>
</dict>
</array>
<key>uuid</key>
<string>83091B89-765E-4F0D-9275-0EC6CB084126</string>
<key>colorSpaceName</key>
<string>sRGB</string>
<key>semanticClass</key>
<string>theme.dracula</string>
<key>author</key>
<string>Zeno Rocha</string>
</dict>
</plist>

50
src/assets.rs Normal file
View File

@ -0,0 +1,50 @@
use std::path::Path;
use crate::directories::PROJECT_DIRS;
use anyhow::Result;
use syntect::dumps;
use syntect::highlighting::ThemeSet;
use syntect::parsing::{SyntaxSet};
const DEFAULT_SYNTAXSET: &'static [u8] = include_bytes!("../assets/syntaxes.bin");
const DEFAULT_THEMESET: &'static [u8] = include_bytes!("../assets/themes.bin");
pub struct HighlightingAssets {
pub syntax_set: SyntaxSet,
pub theme_set: ThemeSet,
}
impl HighlightingAssets {
pub fn new() -> Self {
Self::from_dump_file().unwrap_or_else(|_| Self {
syntax_set: dumps::from_binary(DEFAULT_SYNTAXSET),
theme_set: dumps::from_binary(DEFAULT_THEMESET),
})
}
pub fn from_dump_file() -> Result<Self> {
let cache_dir = PROJECT_DIRS.cache_dir();
Ok(Self {
syntax_set: dumps::from_dump_file(cache_dir.join("syntaxes.bin"))?,
theme_set: dumps::from_dump_file(cache_dir.join("themes.bin"))?,
})
}
pub fn add_from_folder<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
let path = path.as_ref();
self.theme_set
.add_from_folder(path.join("themes"))?;
let mut builder = self.syntax_set
.clone()
.into_builder();
builder.add_from_folder(path.join("syntaxes"), true)?;
self.syntax_set = builder.build();
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")?;
Ok(())
}
}

View File

@ -19,7 +19,7 @@ pub fn config_file() -> PathBuf {
.ok()
.map(PathBuf::from)
.filter(|config_path| config_path.is_file())
.unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
.unwrap_or_else(|| PROJECT_DIRS.config_dir().to_owned())
}
pub fn get_args_from_config_file() -> Vec<OsString> {
@ -142,7 +142,7 @@ pub struct Config {
short,
long,
value_name = "PATH",
required_unless_one = &["config-file", "list-fonts", "list-themes", "to-clipboard"]
required_unless_one = &["config-file", "list-fonts", "list-themes", "to-clipboard", "build-cache"]
)]
pub output: Option<PathBuf>,
@ -195,12 +195,16 @@ pub struct Config {
#[structopt(long, value_name = "THEME", default_value = "Dracula")]
pub theme: String,
// Copy the output image to clipboard.
/// Copy the output image to clipboard.
#[structopt(short = "c", long)]
pub to_clipboard: bool,
// Draw a custom text on the bottom right corner
// #[structopt(long)]
// watermark: Option<String>,
/// build syntax definition and theme cache
#[structopt(long)]
pub build_cache: Option<PathBuf>,
}
impl Config {

View File

@ -19,7 +19,7 @@ use {image::ImageOutputFormat, std::process::Command};
mod config;
use crate::config::{config_file, get_args_from_config_file};
use config::Config;
use silicon::utils::init_syntect;
use silicon::assets::HighlightingAssets;
#[cfg(target_os = "linux")]
pub fn dump_image_to_clipboard(image: &DynamicImage) -> Result<(), Error> {
@ -81,9 +81,15 @@ fn run() -> Result<(), Error> {
args.extend(args_cli);
let config: Config = Config::from_iter(args);
let (ps, ts) = init_syntect();
let ha = HighlightingAssets::new();
let (ps, ts) = (ha.syntax_set, ha.theme_set);
if config.list_themes {
if let Some(path) = config.build_cache {
let mut ha = HighlightingAssets::new();
ha.add_from_folder(path)?;
ha.dump_to_file()?;
return Ok(())
} else if config.list_themes {
for i in ts.themes.keys() {
println!("{}", i);
}
@ -105,8 +111,8 @@ fn run() -> Result<(), Error> {
let mut h = HighlightLines::new(syntax, &theme);
let highlight = LinesWithEndings::from(&code)
.map(|line| h.highlight(line, &ps))
.collect::<Vec<_>>();
.map(|line| h.highlight_line(line, &ps))
.collect::<Result<Vec<_>, _>>()?;
let mut formatter = config.get_formatter()?;

View File

@ -9,7 +9,7 @@ use image::RgbaImage;
use rayon::prelude::*;
#[derive(Copy, Clone)]
struct SharedMutPtr<>(*mut [[u8; 4]]);
struct SharedMutPtr(*mut [[u8; 4]]);
unsafe impl Sync for SharedMutPtr {}

View File

@ -28,10 +28,9 @@ impl SiliconProjectDirs {
})
}
// silicon use bat's cache directory
fn get_cache_dir() -> Option<PathBuf> {
// on all OS prefer BAT_CACHE_PATH if set
let cache_dir_op = env::var_os("BAT_CACHE_PATH").map(PathBuf::from);
// on all OS prefer SILICON_CACHE_PATH if set
let cache_dir_op = env::var_os("SILICON_CACHE_PATH").map(PathBuf::from);
if cache_dir_op.is_some() {
return cache_dir_op;
}
@ -45,7 +44,7 @@ impl SiliconProjectDirs {
#[cfg(not(target_os = "macos"))]
let cache_dir_op = dirs::cache_dir();
cache_dir_op.map(|d| d.join("bat"))
cache_dir_op.map(|d| d.join("silicon"))
}
pub fn cache_dir(&self) -> &Path {

View File

@ -7,8 +7,10 @@
//! use syntect::util::LinesWithEndings;
//! use silicon::utils::{init_syntect, ShadowAdder};
//! use silicon::formatter::ImageFormatterBuilder;
//! use silicon::assets::HighlightingAssets;
//!
//! let (ps, ts) = init_syntect();
//! let ha = HighlightingAssets::new();
//! let (ps, ts) = (ha.syntax_set, ha.theme_set);
//! let code = r#"fn main() {
//! println!("Hello, world!");
//! }
@ -34,6 +36,7 @@
#[macro_use]
extern crate log;
pub mod assets;
pub mod blur;
pub mod directories;
pub mod error;

View File

@ -1,39 +1,9 @@
use crate::directories::PROJECT_DIRS;
use crate::error::ParseColorError;
use image::imageops::{crop, resize, FilterType};
use image::imageops::{crop_imm, resize, FilterType};
use image::Pixel;
use image::{DynamicImage, GenericImage, GenericImageView, Rgba, RgbaImage};
use imageproc::drawing::{draw_filled_rect_mut, draw_line_segment_mut};
use imageproc::rect::Rect;
use syntect::dumps;
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSet;
pub fn read_from_bat_cache() -> Option<(SyntaxSet, ThemeSet)> {
let cache_dir = PROJECT_DIRS.cache_dir();
let syntax_cache = cache_dir.join("syntaxes.bin");
let theme_cache = cache_dir.join("themes.bin");
if syntax_cache.exists() && theme_cache.exists() {
if let (Ok(a), Ok(b)) = (
dumps::from_dump_file(syntax_cache),
dumps::from_dump_file(theme_cache),
) {
return Some((a, b));
}
}
None
}
/// Load the default SyntaxSet and ThemeSet.
pub fn init_syntect() -> (SyntaxSet, ThemeSet) {
// try to use bat's cache
read_from_bat_cache().unwrap_or_else(|| {
(
dumps::from_binary(include_bytes!("../assets/syntaxes.bin")),
dumps::from_binary(include_bytes!("../assets/themes.bin")),
)
})
}
pub trait ToRgba {
type Target;
@ -295,18 +265,18 @@ pub(crate) fn round_corner(image: &mut DynamicImage, radius: u32) {
foreground,
);
let part = crop(&mut circle, 0, 0, radius, radius);
image.copy_from(&part, 0, 0).unwrap();
let part = crop_imm(&mut circle, 0, 0, radius, radius);
image.copy_from(&*part, 0, 0).unwrap();
let part = crop(&mut circle, radius + 1, 0, radius, radius);
image.copy_from(&part, width - radius, 0).unwrap();
let part = crop_imm(&mut circle, radius + 1, 0, radius, radius);
image.copy_from(&*part, width - radius, 0).unwrap();
let part = crop(&mut circle, 0, radius + 1, radius, radius);
image.copy_from(&part, 0, height - radius).unwrap();
let part = crop_imm(&mut circle, 0, radius + 1, radius, radius);
image.copy_from(&*part, 0, height - radius).unwrap();
let part = crop(&mut circle, radius + 1, radius + 1, radius, radius);
let part = crop_imm(&mut circle, radius + 1, radius + 1, radius, radius);
image
.copy_from(&part, width - radius, height - radius)
.copy_from(&*part, width - radius, height - radius)
.unwrap();
}