Map keyboard to bépo

This commit is contained in:
2026-03-16 10:33:21 +01:00
parent baeea20aa7
commit 404a681254
9 changed files with 347 additions and 121 deletions

View File

@@ -8,8 +8,5 @@ proc-macro = true
[dependencies]
image = "0.25"
regex = "1"
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["full"] }
zyn = "0.5"

View File

@@ -1,13 +1,6 @@
use image::{ImageBuffer, Luma};
use proc_macro::{Span, TokenStream};
use quote::quote;
use regex::Regex;
use syn::parse::Parse;
fn remove_non_alphanumeric(input: &str) -> String {
let re = Regex::new(r"[^a-zA-Z0-9_]+").unwrap();
re.replace_all(input, "").to_string()
}
use proc_macro::TokenStream;
use zyn::{ToTokens, zyn};
fn to_format(img: ImageBuffer<Luma<u8>, Vec<u8>>, width: usize, height: usize) -> Vec<u8> {
let mut output = Vec::new();
@@ -48,25 +41,10 @@ fn path_to_image(path: &str) -> (Vec<u8>, usize, usize) {
(bytes, width, height)
}
struct ParsedArgs {
path: String,
}
impl Parse for ParsedArgs {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let path: syn::LitStr = input.parse()?;
let path = path.value();
Ok(ParsedArgs { path })
}
}
pub fn parse_image(
input: TokenStream,
) -> Result<(u8, u8, usize, Vec<proc_macro2::TokenStream>), syn::Error> {
pub fn parse_image(input: TokenStream) -> Result<(u8, u8, usize, Vec<u8>), syn::Error> {
// parse the input into a comma separated list of arguments
let parsed_args = syn::parse::<ParsedArgs>(input)?;
// let parsed_args = parse_macro_input!(input as ParsedArgs);
let (bytes, width, height) = path_to_image(&parsed_args.path);
let path = syn::parse::<syn::LitStr>(input)?.value();
let (bytes, width, height) = path_to_image(&path);
let width = width as u8;
let height = height as u8;
@@ -74,15 +52,19 @@ pub fn parse_image(
let byte_array = bytes.as_slice();
let byte_count = byte_array.len();
let byte_tokens = bytes.iter().map(|b| quote! { #b }).collect::<Vec<_>>();
Ok((width, height, byte_count, byte_tokens))
Ok((width, height, byte_count, bytes))
}
pub fn include_bitmap_image_impl(input: TokenStream) -> TokenStream {
let (_, _, _, byte_tokens) = parse_image(input).unwrap();
let output = quote! {
[#(#byte_tokens),*]
let output = zyn! {
[
@for (byte_token in byte_tokens) {
{{ byte_token }},
}
]
};
output.into()
output.to_token_stream().into()
}