feat(cheddar): Use syntax highlighting assets from bat
This uses Nix to inject the path to the syntax highlighting assets that ship with the bat source code into the cheddar build at compile time, where the Rust compiler then inserts it into the binary via macros. bat has a lot of custom syntax highlighting definitions that they collected from all over the place (including for languages like Nix!) and this makes them accessible to cheddar. Also if you're reading this, can you just take a moment to appreciate how incredible it is that Nix just lets us do something like this?!
This commit is contained in:
parent
4681c07bde
commit
81d9b81b06
3 changed files with 21 additions and 2 deletions
1
third_party/default.nix
vendored
1
third_party/default.nix
vendored
|
@ -22,6 +22,7 @@ let
|
|||
# of the repo. They become available under `pkgs.third_party.<name>`
|
||||
inherit (nixpkgs)
|
||||
bashInteractive
|
||||
bat
|
||||
buildGoPackage
|
||||
cacert
|
||||
cachix
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
pkgs.third_party.naersk.buildPackage ./.
|
||||
with pkgs.third_party;
|
||||
|
||||
naersk.buildPackage {
|
||||
src = ./.;
|
||||
doDoc = false;
|
||||
doCheck = false;
|
||||
|
||||
override = x: {
|
||||
# bat contains syntax highlighting packages for a lot more
|
||||
# languages than what ships with syntect, and we can make use of
|
||||
# them!
|
||||
BAT_SYNTAXES = "${bat.src}/assets/syntaxes.bin";
|
||||
|
||||
# LLVM packages (why are they even required?) are not found
|
||||
# automatically if added to buildInputs, hence this ...
|
||||
LIBCLANG_PATH = "${llvmPackages.libclang}/lib/libclang.so.7";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::io::BufRead;
|
|||
use std::io;
|
||||
use std::path::Path;
|
||||
use syntect::easy::HighlightLines;
|
||||
use syntect::dumps::from_binary;
|
||||
use syntect::highlighting::ThemeSet;
|
||||
use syntect::parsing::{SyntaxSet, SyntaxReference};
|
||||
|
||||
|
@ -35,7 +36,7 @@ fn should_continue(res: &io::Result<usize>) -> bool {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let syntaxes = SyntaxSet::load_defaults_newlines();
|
||||
let syntaxes = from_binary(include_bytes!(env!("BAT_SYNTAXES")));
|
||||
|
||||
let stdin = io::stdin();
|
||||
let mut stdin = stdin.lock();
|
||||
|
|
Loading…
Reference in a new issue