keymaps 1.2.0

A rust crate which provides a standardized encoding for key codes
Documentation
// keymaps - A rust crate which provides a standardized encoding for key codes
//
// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// This file is part of the keymaps crate.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>.

use std::num::ParseIntError;

use thiserror::Error;

use crate::key_repr::parsing::parser::tokenizer::Token;

#[derive(Error, Debug)]
pub enum TrieReplace<K> {
    #[error("The Trie has no node with the key: {0}")]
    NoNodeWithKey(Vec<K>),
}

#[derive(Error, Debug)]
pub enum TrieInsert<K, V> {
    #[error("The key ({0:?}) is already used.")]
    KeyAlreadySet(Vec<K>),

    #[error(
        "The part of the key ({child_key:?}) is already used to refer to a child (with value: {child_value:#?})."
    )]
    KeyIncludesChild { child_key: Vec<K>, child_value: V },
}

#[derive(Error, Debug)]
pub enum KeyParse {
    #[error("The string ('{0}') was not Recognized.")]
    NotRecognized(String),

    #[error("The input stream ended, before parsing finished")]
    UnexpectedEnd,

    #[error("The number associate with the F key ('{0}') can't be parsed as u8.")]
    CantParseFNumber(#[from] ParseIntError),

    #[error("The String ('{0}') is not a correct special key name.")]
    UnexpectedSpecialKey(String),

    #[error("Expected to find token: {expected}, but found: {found}")]
    ExpectedButFound { expected: Token, found: Token },

    #[error("Expected to find a char token, but found: {0}")]
    ExpectedCharFound(Token),

    #[error("Found unknown long modifer: {0}")]
    UnknownLongMod(String),
    #[error("Found unknown short modifer: {0}")]
    UnknownShortMod(char),

    #[error("The modifer ('{0}') was set more than once.")]
    ModifierAlreadySet(String),

    #[error("The string ('{0}') should only contain one key, but contains more.")]
    TooManyKeys(String),
}

#[cfg(feature = "crossterm")]
#[derive(Error, Debug)]
pub enum KeyFromCrossterm {
    #[error("Can not parse non Key event to a Key code: ('{0:?}')")]
    OnlyKey(crossterm::event::Event),
}