Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
image: archlinux
sources:
- https://github.com/alacritty/vte
tasks:
- rustup: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal -c clippy
- stable: |
cd vte
$HOME/.cargo/bin/cargo +stable test
$HOME/.cargo/bin/cargo +stable test --features=ansi
$HOME/.cargo/bin/cargo +stable test --features=ansi --no-default-features
- clippy: |
cd vte
$HOME/.cargo/bin/cargo +stable clippy
$HOME/.cargo/bin/cargo +stable clippy --features=ansi
- rustfmt: |
$HOME/.cargo/bin/rustup toolchain install nightly -c rustfmt
cd vte
$HOME/.cargo/bin/cargo +nightly fmt -- --check
- msrv: |
cd vte
msrv=$(cat Cargo.toml | grep "rust-version" | sed 's/.*"\(.*\)".*/\1/')
$HOME/.cargo/bin/rustup toolchain install --profile minimal $msrv
rm Cargo.lock
$HOME/.cargo/bin/cargo +$msrv test
+1
View File
@@ -0,0 +1 @@
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".builds/linux.yml":"9e80f6db2b0ee1dfc1dbdd4589cfdd57077ed95bb760df61d4afc016b85ad3c9",".cargo_vcs_info.json":"fc40d5edc517c64729300bb06dbf6547b4bfe480dd16dc351ada78d71e58f2bb","CHANGELOG.md":"1ced5a221e2050a6d175aaa2cc5e03a1db0947ff7412b8464136c37445540336","Cargo.lock":"e103590b6ac4abeeb64dc18d85694de784b21f857b93615971ed5e857d35f67f","Cargo.toml":"202322b00bc0650696a6a33895d43434d6f507a7b3f8e464cf1549b76bd0e4fd","Cargo.toml.orig":"22dfaed40517d8f1bf7c6b783ffa8b3c869e202dad3fb1b5d5c571c032f2fbde","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"e4c9b06fa850cb9b540a5e400e9f6394cf15efcf4098144de477d1d3dae10150","README.md":"ff6200be737dfb4275b2cfbcd7742a7d7031f159908dd7799925733782341995","doc/modifyOtherKeys-example.txt":"b6eca4ccc196d3345f9a9b32d6f256fd7ac31d579e42609aae435d77de411903","examples/parselog.rs":"f7cf1a8ac1eb0579c6546603584fc73b8895038085006f351fa1a17a924e8fc4","rustfmt.toml":"8776da01d4b25480e1950b88500044bad40ae10b197cb89f4f17dd3f34480d3e","src/ansi.rs":"fd40e9ca80e07e5b125eb7dfc0453800935162c0655a8168d9c17e586a7a7c54","src/lib.rs":"4afa2136336352cd3c8d3ba746616c0f10123c73ab08f7c4343d2e05a2937020","src/params.rs":"a305b112e6779d14537fd420aad45722b9cde756aba75153ac8560b7aa7d4c4a","tests/demo.vte":"1ac4e7fe28999e2aa632cd80f85d4f5dae776499164ffe0fa792151614ef80fe"},"package":"231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077"}
+6
View File
@@ -0,0 +1,6 @@
{
"git": {
"sha1": "425fc59cb4b42932bc7e877cde32f72f4b0a3896"
},
"path_in_vcs": ""
}
+97
View File
@@ -0,0 +1,97 @@
CHANGELOG
=========
## 0.14.1
- Crash when partial advance buffer stopped inside some grapheme boundaries
## 0.14.0
- `Parser::advance` now takes byte slices, instead of individual bytes
- `Parser::advance_until_terminated` allows premature termination,
by checking for `Perform::terminated` after each dispatch
## 0.13.1
- Add SCP control support
- Improve SGR performance
## 0.13.0
- Reexport `cursor_icon` crate in `ansi`
- Split-out private modes from `Mode` into `PrivateMode`
- Add `unset_private_mode` and `set_private_mode`
- Add `report_mode` and `report_private_mode` to handle DECRPM/DECRQM
## 0.12.0
- Add support for OSC 22
- Add support for kitty keyboard protocol
- Add support for XTerm's modifyOtherKeys protocol
## 0.11.1
- Minimum rust version has been bumped to 1.62.1
- Support for ANSI terminal stream parsing under the `ansi` feature.
- Addition of the `serde` feature which derives `Serialize` and `Deserialize`
for the types provided in the `ansi` module.
## 0.11.0
- Minimum rust version has been bumped to 1.56.0
- Fixed infinite loop in `Params` iterator when 32nd parameter is a subparameter
## 0.10.1
- Fixed invalid intermediates when transitioning from DCS to ESC
## 0.10.0
- Changed the type of CSI parameters from i64 to u16
- All methods of the `Perform` trait are now optional
## 0.9.0
- Added CSI subparameter support; required changes can be seen in Alacritty:
https://github.com/alacritty/alacritty/commit/576252294d09c1f52ec73bde03652349bdf5a529#diff-49ac9e6f6e6a855312bfcd393201f18ca53e6148c4a22a3a4949f1f9d1d137a8
## 0.8.0
- Remove C1 ST support in OSCs, fixing OSCs with ST in the payload
## 0.7.1
- Out of bounds when parsing a DCS with more than 16 parameters
## 0.7.0
- Fix params reset between escapes
- Removed unused parameter from `esc_dispatch`
## 0.6.0
- Fix build failure on Rust 1.36.0
- Add `bool_terminated` parameter to osc dispatch
## 0.5.0
- Support for dynamically sized escape buffers without feature `no_std`
- Improved UTF8 parser performance
- Migrate to Rust 2018
## 0.4.0
- Fix handling of DCS escapes
## 0.3.3
- Fix off-by-one error in CSI parsing when params list was at max length
(previously caused a panic).
- Support no_std
## 0.2.0
- Removes `osc_start`, `osc_put`, and `osc_end`
- Adds `osc_dispatch` which simply receives a list of parameters
- Removes `byte: u8` parameter from `hook` and `unhook` because it's always
zero.
+100
View File
@@ -0,0 +1,100 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "arrayvec"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "bitflags"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
[[package]]
name = "cursor-icon"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "proc-macro2"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "2.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e02e55d62894af2a08aca894c6577281f76769ba47c94d5756bec8ac6e7373"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "vte"
version = "0.14.1"
dependencies = [
"arrayvec",
"bitflags",
"cursor-icon",
"log",
"memchr",
"serde",
]
+87
View File
@@ -0,0 +1,87 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.62.1"
name = "vte"
version = "0.14.1"
authors = [
"Joe Wilm <joe@jwilm.com>",
"Christian Duerr <contact@christianduerr.com>",
]
build = false
exclude = ["/.travis.yml"]
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Parser for implementing terminal emulators"
documentation = "https://docs.rs/vte/"
readme = "README.md"
keywords = [
"ansi",
"vte",
"parser",
"terminal",
]
categories = [
"parsing",
"no-std",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/alacritty/vte"
[features]
ansi = [
"log",
"cursor-icon",
"bitflags",
]
default = ["no_std"]
no_std = ["arrayvec"]
serde = ["dep:serde"]
[lib]
name = "vte"
path = "src/lib.rs"
[[example]]
name = "parselog"
path = "examples/parselog.rs"
[dependencies.arrayvec]
version = "0.7.2"
optional = true
default-features = false
[dependencies.bitflags]
version = "2.3.3"
optional = true
default-features = false
[dependencies.cursor-icon]
version = "1.0.0"
optional = true
default-features = false
[dependencies.log]
version = "0.4.17"
optional = true
[dependencies.memchr]
version = "2.7.4"
[dependencies.serde]
version = "1.0.160"
features = ["derive"]
optional = true
+28
View File
@@ -0,0 +1,28 @@
[package]
authors = ["Joe Wilm <joe@jwilm.com>", "Christian Duerr <contact@christianduerr.com>"]
description = "Parser for implementing terminal emulators"
repository = "https://github.com/alacritty/vte"
documentation = "https://docs.rs/vte/"
keywords = ["ansi", "vte", "parser", "terminal"]
categories = ["parsing", "no-std"]
exclude = ["/.travis.yml"]
readme = "README.md"
license = "Apache-2.0 OR MIT"
version = "0.14.1"
name = "vte"
edition = "2021"
rust-version = "1.62.1"
[features]
ansi = ["log", "cursor-icon", "bitflags"]
default = ["no_std"]
no_std = ["arrayvec"]
serde = ["dep:serde"]
[dependencies]
arrayvec = { version = "0.7.2", default-features = false, optional = true }
bitflags = { version = "2.3.3", default-features = false, optional = true }
cursor-icon = { version = "1.0.0", default-features = false, optional = true }
log = { version = "0.4.17", optional = true }
memchr = "2.7.4"
serde = { version = "1.0.160", features = ["derive"], optional = true }
+176
View File
@@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
+25
View File
@@ -0,0 +1,25 @@
Copyright (c) 2016 Joe Wilm
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+19
View File
@@ -0,0 +1,19 @@
vte
===
[![Build Status](https://travis-ci.org/alacritty/vte.svg?branch=master)](https://travis-ci.org/alacritty/vte)
[![Crates.io Version](https://img.shields.io/crates/v/vte.svg)](https://crates.io/crates/vte/)
Parser for implementing virtual terminal emulators in Rust.
The parser is implemented according to [Paul Williams' ANSI parser state
machine]. The state machine doesn't assign meaning to the parsed data and is
thus not itself sufficient for writing a terminal emulator. Instead, it is
expected that an implementation of the `Perform` trait which does something
useful with the parsed data. The `Parser` handles the book keeping, and the
`Perform` gets to simply handle actions.
See the [docs] for more info.
[Paul Williams' ANSI parser state machine]: https://vt100.net/emu/dec_ansi_parser
[docs]: https://docs.rs/crate/vte/
File diff suppressed because it is too large Load Diff
+71
View File
@@ -0,0 +1,71 @@
//! Parse input from stdin and log actions on stdout
use std::io::{self, Read};
use vte::{Params, Parser, Perform};
/// A type implementing Perform that just logs actions
struct Log;
impl Perform for Log {
fn print(&mut self, c: char) {
println!("[print] {:?}", c);
}
fn execute(&mut self, byte: u8) {
println!("[execute] {:02x}", byte);
}
fn hook(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
println!(
"[hook] params={:?}, intermediates={:?}, ignore={:?}, char={:?}",
params, intermediates, ignore, c
);
}
fn put(&mut self, byte: u8) {
println!("[put] {:02x}", byte);
}
fn unhook(&mut self) {
println!("[unhook]");
}
fn osc_dispatch(&mut self, params: &[&[u8]], bell_terminated: bool) {
println!("[osc_dispatch] params={:?} bell_terminated={}", params, bell_terminated);
}
fn csi_dispatch(&mut self, params: &Params, intermediates: &[u8], ignore: bool, c: char) {
println!(
"[csi_dispatch] params={:#?}, intermediates={:?}, ignore={:?}, char={:?}",
params, intermediates, ignore, c
);
}
fn esc_dispatch(&mut self, intermediates: &[u8], ignore: bool, byte: u8) {
println!(
"[esc_dispatch] intermediates={:?}, ignore={:?}, byte={:02x}",
intermediates, ignore, byte
);
}
}
fn main() {
let input = io::stdin();
let mut handle = input.lock();
let mut statemachine = Parser::new();
let mut performer = Log;
let mut buf = [0; 2048];
loop {
match handle.read(&mut buf) {
Ok(0) => break,
Ok(n) => statemachine.advance(&mut performer, &buf[..n]),
Err(err) => {
println!("err: {}", err);
break;
},
}
}
}
+17
View File
@@ -0,0 +1,17 @@
format_code_in_doc_comments = true
group_imports = "StdExternalCrate"
match_block_trailing_comma = true
condense_wildcard_suffixes = true
use_field_init_shorthand = true
normalize_doc_attributes = true
overflow_delimited_expr = true
imports_granularity = "Module"
format_macro_matchers = true
use_small_heuristics = "Max"
hex_literal_case = "Upper"
normalize_comments = true
reorder_impl_items = true
use_try_shorthand = true
newline_style = "Unix"
format_strings = true
wrap_comments = true
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+144
View File
@@ -0,0 +1,144 @@
//! Fixed size parameters list with optional subparameters.
use core::fmt::{self, Debug, Formatter};
pub(crate) const MAX_PARAMS: usize = 32;
#[derive(Default)]
pub struct Params {
/// Number of subparameters for each parameter.
///
/// For each entry in the `params` slice, this stores the length of the
/// param as number of subparams at the same index as the param in the
/// `params` slice.
///
/// At the subparam positions the length will always be `0`.
subparams: [u8; MAX_PARAMS],
/// All parameters and subparameters.
params: [u16; MAX_PARAMS],
/// Number of suparameters in the current parameter.
current_subparams: u8,
/// Total number of parameters and subparameters.
len: usize,
}
impl Params {
/// Returns the number of parameters.
#[inline]
pub fn len(&self) -> usize {
self.len
}
/// Returns `true` if there are no parameters present.
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
/// Returns an iterator over all parameters and subparameters.
#[inline]
pub fn iter(&self) -> ParamsIter<'_> {
ParamsIter::new(self)
}
/// Returns `true` if there is no more space for additional parameters.
#[inline]
pub(crate) fn is_full(&self) -> bool {
self.len == MAX_PARAMS
}
/// Clear all parameters.
#[inline]
pub(crate) fn clear(&mut self) {
self.current_subparams = 0;
self.len = 0;
}
/// Add an additional parameter.
#[inline]
pub(crate) fn push(&mut self, item: u16) {
self.subparams[self.len - self.current_subparams as usize] = self.current_subparams + 1;
self.params[self.len] = item;
self.current_subparams = 0;
self.len += 1;
}
/// Add an additional subparameter to the current parameter.
#[inline]
pub(crate) fn extend(&mut self, item: u16) {
self.subparams[self.len - self.current_subparams as usize] = self.current_subparams + 1;
self.params[self.len] = item;
self.current_subparams += 1;
self.len += 1;
}
}
impl<'a> IntoIterator for &'a Params {
type IntoIter = ParamsIter<'a>;
type Item = &'a [u16];
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
/// Immutable subparameter iterator.
pub struct ParamsIter<'a> {
params: &'a Params,
index: usize,
}
impl<'a> ParamsIter<'a> {
fn new(params: &'a Params) -> Self {
Self { params, index: 0 }
}
}
impl<'a> Iterator for ParamsIter<'a> {
type Item = &'a [u16];
fn next(&mut self) -> Option<Self::Item> {
if self.index >= self.params.len() {
return None;
}
// Get all subparameters for the current parameter.
let num_subparams = self.params.subparams[self.index];
let param = &self.params.params[self.index..self.index + num_subparams as usize];
// Jump to the next parameter.
self.index += num_subparams as usize;
Some(param)
}
fn size_hint(&self) -> (usize, Option<usize>) {
let remaining = self.params.len() - self.index;
(remaining, Some(remaining))
}
}
impl Debug for Params {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "[")?;
for (i, param) in self.iter().enumerate() {
if i != 0 {
write!(f, ";")?;
}
for (i, subparam) in param.iter().enumerate() {
if i != 0 {
write!(f, ":")?;
}
subparam.fmt(f)?;
}
}
write!(f, "]")
}
}
File diff suppressed because it is too large Load Diff