build(ariadne): vendor clap
This commit was merged in pull request #30.
This commit is contained in:
1 parent
e6af135702
commit
8855b6d379
681 files changed
+400416
No files matched your search
@@ -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":{".cargo_vcs_info.json":"9d39f51788117eb8ff1e40f7e664b63450737ec11d5670e1d5b3fc13d45e5032","Cargo.lock":"fabba837ae654e97f42dd56a61fc8606e7c37bf54dee47e93dfc4e093db3c6a6","Cargo.toml":"be7526c599f7d291150912990e4a70cef1e691c96c300c06c784d310dc00efb3","Cargo.toml.orig":"6be136b355f517efe523de76cdc120b0a7d943418b9bf25bbbc75da5a314dc73","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"b979881246703593aad26da21f5d467c03c35142d6f5965f7e7253cb89695c9f","examples/dump-wincon.rs":"f585b378e151f0489465cd769ab49e59665dcc3cb17c9dd12a9893ba186edd48","examples/set-wincon.rs":"b8862ad2c5c8e834932c6f3baf64c5c65058021805e6fecc989ec50288a87c51","src/ansi.rs":"765d868d6efd1324c21a1c778a3a3be4c6fa9fc3191b415858e0a4d2b8f01a3f","src/lib.rs":"faa64326e95cdbff9b999adafcfdbc8e576859537272200cebdb630e8cfd7d22","src/stream.rs":"8b0a852b1c43d9b483154a7820edd30f658409349f9db339eb18e873aafd6b32","src/windows.rs":"ef7a56c7bc4436a46c93ce85220e5c03c0ca82fbe945521360ea9ecffce4291d"},"package":"291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "368a8719474357f9d54be800b4163c9074561e37"
|
||||
},
|
||||
"path_in_vcs": "crates/anstyle-wincon"
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
###############################################################################
|
||||
# @generated
|
||||
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
|
||||
# regenerate this file, run the following:
|
||||
#
|
||||
# bazel run @@//third_party:vendor_crates
|
||||
###############################################################################
|
||||
|
||||
load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
cargo_toml_env_vars(
|
||||
name = "cargo_toml_env_vars",
|
||||
src = "Cargo.toml",
|
||||
)
|
||||
|
||||
rust_library(
|
||||
name = "anstyle_wincon",
|
||||
srcs = glob(
|
||||
include = ["**/*.rs"],
|
||||
allow_empty = False,
|
||||
),
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
".tmp_git_root/**/*",
|
||||
"BUILD",
|
||||
"BUILD.bazel",
|
||||
"WORKSPACE",
|
||||
"WORKSPACE.bazel",
|
||||
],
|
||||
),
|
||||
crate_root = "src/lib.rs",
|
||||
edition = "2021",
|
||||
rustc_env_files = [
|
||||
":cargo_toml_env_vars",
|
||||
],
|
||||
rustc_flags = [
|
||||
"--cap-lints=allow",
|
||||
],
|
||||
tags = [
|
||||
"cargo-bazel",
|
||||
"crate-name=anstyle-wincon",
|
||||
"manual",
|
||||
"noclippy",
|
||||
"norustfmt",
|
||||
],
|
||||
target_compatible_with = select({
|
||||
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios-macabi": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios-sim": [],
|
||||
"@rules_rust//rust/platform:aarch64-linux-android": [],
|
||||
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-fuchsia": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-none": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-uefi": [],
|
||||
"@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [],
|
||||
"@rules_rust//rust/platform:arm-unknown-linux-musleabi": [],
|
||||
"@rules_rust//rust/platform:armv7-linux-androideabi": [],
|
||||
"@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [],
|
||||
"@rules_rust//rust/platform:i686-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:i686-linux-android": [],
|
||||
"@rules_rust//rust/platform:i686-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:i686-unknown-freebsd": [],
|
||||
"@rules_rust//rust/platform:i686-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:mips-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:s390x-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-netbsd": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-openbsd": [],
|
||||
"@rules_rust//rust/platform:thumbv6m-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv7em-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv7em-none-eabihf": [],
|
||||
"@rules_rust//rust/platform:thumbv7m-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv8m.main-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [],
|
||||
"@rules_rust//rust/platform:wasm32-unknown-emscripten": [],
|
||||
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip1": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip1-threads": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip2": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-ios": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-ios-macabi": [],
|
||||
"@rules_rust//rust/platform:x86_64-linux-android": [],
|
||||
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-freebsd": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-fuchsia": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-none": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-uefi": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
version = "3.0.11",
|
||||
deps = [
|
||||
"//third_party/crates/anstyle-1.0.14:anstyle",
|
||||
] + select({
|
||||
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [
|
||||
"//third_party/crates/once_cell_polyfill-1.70.2:once_cell_polyfill", # cfg(windows)
|
||||
"//third_party/crates/windows-sys-0.61.2:windows_sys", # cfg(windows)
|
||||
],
|
||||
"@rules_rust//rust/platform:i686-pc-windows-msvc": [
|
||||
"//third_party/crates/once_cell_polyfill-1.70.2:once_cell_polyfill", # cfg(windows)
|
||||
"//third_party/crates/windows-sys-0.61.2:windows_sys", # cfg(windows)
|
||||
],
|
||||
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [
|
||||
"//third_party/crates/once_cell_polyfill-1.70.2:once_cell_polyfill", # cfg(windows)
|
||||
"//third_party/crates/windows-sys-0.61.2:windows_sys", # cfg(windows)
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"lexopt",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lexopt"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fa0e2a1fcbe2f6be6c42e342259976206b383122fc152e872795338b5a3f3a7"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.56.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8aab899efe6ce4fe821f6dda30c02d7041c79f147598ab4b60197f181e12d001"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.53.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
# 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.66.0"
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
build = false
|
||||
include = [
|
||||
"build.rs",
|
||||
"src/**/*",
|
||||
"Cargo.toml",
|
||||
"Cargo.lock",
|
||||
"LICENSE*",
|
||||
"README.md",
|
||||
"examples/**/*",
|
||||
]
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = "Styling legacy Windows terminals"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"ansi",
|
||||
"terminal",
|
||||
"color",
|
||||
"windows",
|
||||
]
|
||||
categories = ["command-line-interface"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-cli/anstyle.git"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"docsrs",
|
||||
"--generate-link-to-definition",
|
||||
]
|
||||
targets = ["x86_64-pc-windows-msvc"]
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "Unreleased"
|
||||
replace = "{{version}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = '\.\.\.HEAD'
|
||||
replace = "...{{tag_name}}"
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "ReleaseDate"
|
||||
replace = "{{date}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-header -->"
|
||||
replace = """
|
||||
<!-- next-header -->
|
||||
## [Unreleased] - ReleaseDate
|
||||
"""
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-url -->"
|
||||
replace = """
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD"""
|
||||
exactly = 1
|
||||
|
||||
[lib]
|
||||
name = "anstyle_wincon"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[example]]
|
||||
name = "dump-wincon"
|
||||
path = "examples/dump-wincon.rs"
|
||||
|
||||
[[example]]
|
||||
name = "set-wincon"
|
||||
path = "examples/set-wincon.rs"
|
||||
|
||||
[dependencies.anstyle]
|
||||
version = "1.0.0"
|
||||
|
||||
[dev-dependencies.lexopt]
|
||||
version = "0.3.1"
|
||||
|
||||
[target."cfg(windows)".dependencies.once_cell_polyfill]
|
||||
version = "1.56.1"
|
||||
|
||||
[target."cfg(windows)".dependencies.windows-sys]
|
||||
version = ">=0.60.2, <0.62"
|
||||
features = [
|
||||
"Win32_System_Console",
|
||||
"Win32_Foundation",
|
||||
]
|
||||
|
||||
[lints.clippy]
|
||||
bool_assert_comparison = "allow"
|
||||
branches_sharing_code = "allow"
|
||||
checked_conversions = "warn"
|
||||
collapsible_else_if = "allow"
|
||||
create_dir = "warn"
|
||||
dbg_macro = "warn"
|
||||
debug_assert_with_mut_call = "warn"
|
||||
doc_markdown = "warn"
|
||||
empty_enum = "warn"
|
||||
enum_glob_use = "warn"
|
||||
expl_impl_clone_on_copy = "warn"
|
||||
explicit_deref_methods = "warn"
|
||||
explicit_into_iter_loop = "warn"
|
||||
fallible_impl_from = "warn"
|
||||
filter_map_next = "warn"
|
||||
flat_map_option = "warn"
|
||||
float_cmp_const = "warn"
|
||||
fn_params_excessive_bools = "warn"
|
||||
from_iter_instead_of_collect = "warn"
|
||||
if_same_then_else = "allow"
|
||||
implicit_clone = "warn"
|
||||
imprecise_flops = "warn"
|
||||
inconsistent_struct_constructor = "warn"
|
||||
inefficient_to_string = "warn"
|
||||
infinite_loop = "warn"
|
||||
invalid_upcast_comparisons = "warn"
|
||||
large_digit_groups = "warn"
|
||||
large_stack_arrays = "warn"
|
||||
large_types_passed_by_value = "warn"
|
||||
let_and_return = "allow"
|
||||
linkedlist = "warn"
|
||||
lossy_float_literal = "warn"
|
||||
macro_use_imports = "warn"
|
||||
mem_forget = "warn"
|
||||
mutex_integer = "warn"
|
||||
needless_continue = "allow"
|
||||
needless_for_each = "warn"
|
||||
negative_feature_names = "warn"
|
||||
path_buf_push_overwrite = "warn"
|
||||
ptr_as_ptr = "warn"
|
||||
rc_mutex = "warn"
|
||||
redundant_feature_names = "warn"
|
||||
ref_option_ref = "warn"
|
||||
rest_pat_in_fully_bound_structs = "warn"
|
||||
result_large_err = "allow"
|
||||
same_functions_in_if_condition = "warn"
|
||||
self_named_module_files = "warn"
|
||||
semicolon_if_nothing_returned = "warn"
|
||||
str_to_string = "warn"
|
||||
string_add = "warn"
|
||||
string_add_assign = "warn"
|
||||
string_lit_as_bytes = "warn"
|
||||
todo = "warn"
|
||||
trait_duplication_in_bounds = "warn"
|
||||
uninlined_format_args = "warn"
|
||||
verbose_file_reads = "warn"
|
||||
wildcard_imports = "warn"
|
||||
zero_sized_map_values = "warn"
|
||||
|
||||
[lints.rust]
|
||||
unnameable_types = "warn"
|
||||
unreachable_pub = "warn"
|
||||
unsafe_op_in_unsafe_fn = "warn"
|
||||
unused_lifetimes = "warn"
|
||||
unused_macro_rules = "warn"
|
||||
unused_qualifications = "warn"
|
||||
|
||||
[lints.rust.rust_2018_idioms]
|
||||
level = "warn"
|
||||
priority = -1
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
description = "Styling legacy Windows terminals"
|
||||
categories = ["command-line-interface"]
|
||||
keywords = ["ansi", "terminal", "color", "windows"]
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
include.workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
|
||||
targets = ["x86_64-pc-windows-msvc"]
|
||||
|
||||
[package.metadata.release]
|
||||
pre-release-replacements = [
|
||||
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
|
||||
{file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1},
|
||||
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1},
|
||||
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n## [Unreleased] - ReleaseDate\n", exactly=1},
|
||||
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD", exactly=1},
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
anstyle = { version = "1.0.0", path = "../anstyle" }
|
||||
|
||||
[dev-dependencies]
|
||||
lexopt = "0.3.1"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { version = ">=0.60.2, <0.62", features = ["Win32_System_Console", "Win32_Foundation"] }
|
||||
once_cell_polyfill = "1.56.1"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,202 @@
|
||||
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
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) Individual contributors
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,30 @@
|
||||
# anstyle-wincon
|
||||
|
||||
> Styling legacy Windows terminals
|
||||
|
||||
[][Documentation]
|
||||

|
||||
[](https://crates.io/crates/anstyle-wincon)
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/license/mit>)
|
||||
|
||||
at your option.
|
||||
|
||||
## [Contribute](../../CONTRIBUTING.md)
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally
|
||||
submitted for inclusion in the work by you, as defined in the Apache-2.0
|
||||
license, shall be dual-licensed as above, without any additional terms or
|
||||
conditions.
|
||||
|
||||
### Special Thanks
|
||||
|
||||
[burntsushi](https://github.com/burntsushi) for [termcolor](https://github.com/burntsushi/termcolor) as I don't know Windows either :)
|
||||
|
||||
[Crates.io]: https://crates.io/crates/anstyle-wincon
|
||||
[Documentation]: https://docs.rs/anstyle-wincon
|
||||
@@ -0,0 +1,142 @@
|
||||
//! Write colored text using wincon API calls
|
||||
|
||||
use anstyle_wincon::WinconStream as _;
|
||||
|
||||
fn main() -> Result<(), lexopt::Error> {
|
||||
let args = Args::parse()?;
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
|
||||
for fixed in 0..16 {
|
||||
let style = style(fixed, args.layer, args.effects);
|
||||
let _ = print_number(&mut stdout, fixed, style);
|
||||
if fixed == 7 || fixed == 15 {
|
||||
let _ = stdout.write_colored(None, None, &b"\n"[..]);
|
||||
}
|
||||
}
|
||||
|
||||
for fixed in 16..232 {
|
||||
let col = (fixed - 16) % 36;
|
||||
if col == 0 {
|
||||
let _ = stdout.write_colored(None, None, &b"\n"[..]);
|
||||
}
|
||||
let style = style(fixed, args.layer, args.effects);
|
||||
let _ = print_number(&mut stdout, fixed, style);
|
||||
}
|
||||
|
||||
let _ = stdout.write_colored(None, None, &b"\n"[..]);
|
||||
let _ = stdout.write_colored(None, None, &b"\n"[..]);
|
||||
for fixed in 232..=255 {
|
||||
let style = style(fixed, args.layer, args.effects);
|
||||
let _ = print_number(&mut stdout, fixed, style);
|
||||
}
|
||||
|
||||
let _ = stdout.write_colored(None, None, &b"\n"[..]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn style(
|
||||
color: impl Into<anstyle::Color>,
|
||||
layer: Layer,
|
||||
effects: anstyle::Effects,
|
||||
) -> anstyle::Style {
|
||||
let color = color.into();
|
||||
(match layer {
|
||||
Layer::Fg => anstyle::Style::new().fg_color(Some(color)),
|
||||
Layer::Bg => anstyle::Style::new().bg_color(Some(color)),
|
||||
Layer::Underline => anstyle::Style::new().underline_color(Some(color)),
|
||||
}) | effects
|
||||
}
|
||||
|
||||
fn print_number(
|
||||
stdout: &mut std::io::StdoutLock<'static>,
|
||||
fixed: u8,
|
||||
style: anstyle::Style,
|
||||
) -> std::io::Result<()> {
|
||||
let fg = style.get_fg_color().and_then(|c| match c {
|
||||
anstyle::Color::Ansi(c) => Some(c),
|
||||
anstyle::Color::Ansi256(c) => c.into_ansi(),
|
||||
anstyle::Color::Rgb(_) => None,
|
||||
});
|
||||
let bg = style.get_bg_color().and_then(|c| match c {
|
||||
anstyle::Color::Ansi(c) => Some(c),
|
||||
anstyle::Color::Ansi256(c) => c.into_ansi(),
|
||||
anstyle::Color::Rgb(_) => None,
|
||||
});
|
||||
|
||||
stdout
|
||||
.write_colored(fg, bg, format!("{fixed:>3X}").as_bytes())
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Args {
|
||||
effects: anstyle::Effects,
|
||||
layer: Layer,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default)]
|
||||
enum Layer {
|
||||
#[default]
|
||||
Fg,
|
||||
Bg,
|
||||
Underline,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self, lexopt::Error> {
|
||||
use lexopt::prelude::*;
|
||||
|
||||
let mut res = Args::default();
|
||||
|
||||
let mut args = lexopt::Parser::from_env();
|
||||
while let Some(arg) = args.next()? {
|
||||
match arg {
|
||||
Long("layer") => {
|
||||
res.layer = args.value()?.parse_with(|s| match s {
|
||||
"fg" => Ok(Layer::Fg),
|
||||
"bg" => Ok(Layer::Bg),
|
||||
"underline" => Ok(Layer::Underline),
|
||||
_ => Err("expected values fg, bg, underline"),
|
||||
})?;
|
||||
}
|
||||
Long("effect") => {
|
||||
const EFFECTS: [(&str, anstyle::Effects); 12] = [
|
||||
("bold", anstyle::Effects::BOLD),
|
||||
("dimmed", anstyle::Effects::DIMMED),
|
||||
("italic", anstyle::Effects::ITALIC),
|
||||
("underline", anstyle::Effects::UNDERLINE),
|
||||
("double_underline", anstyle::Effects::UNDERLINE),
|
||||
("curly_underline", anstyle::Effects::CURLY_UNDERLINE),
|
||||
("dotted_underline", anstyle::Effects::DOTTED_UNDERLINE),
|
||||
("dashed_underline", anstyle::Effects::DASHED_UNDERLINE),
|
||||
("blink", anstyle::Effects::BLINK),
|
||||
("invert", anstyle::Effects::INVERT),
|
||||
("hidden", anstyle::Effects::HIDDEN),
|
||||
("strikethrough", anstyle::Effects::STRIKETHROUGH),
|
||||
];
|
||||
let effect = args.value()?.parse_with(|s| {
|
||||
EFFECTS
|
||||
.into_iter()
|
||||
.find(|(name, _)| *name == s)
|
||||
.map(|(_, effect)| effect)
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
"expected one of {}",
|
||||
EFFECTS
|
||||
.into_iter()
|
||||
.map(|(n, _)| n)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
})
|
||||
})?;
|
||||
res.effects = res.effects.insert(effect);
|
||||
}
|
||||
_ => return Err(arg.unexpected()),
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
//! Interactively manipulate wincon colors
|
||||
|
||||
#![cfg_attr(not(windows), allow(dead_code))]
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn main() {
|
||||
panic!("unsupported");
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn main() -> Result<(), lexopt::Error> {
|
||||
use anstyle_wincon::WinconStream as _;
|
||||
|
||||
let args = Args::parse()?;
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout.lock();
|
||||
|
||||
let fg = args.fg.and_then(|c| c.into_ansi());
|
||||
let bg = args.bg.and_then(|c| c.into_ansi());
|
||||
|
||||
let _ = stdout.write_colored(fg, bg, b"");
|
||||
|
||||
#[allow(clippy::mem_forget)]
|
||||
std::mem::forget(stdout);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Args {
|
||||
fg: Option<anstyle::Ansi256Color>,
|
||||
bg: Option<anstyle::Ansi256Color>,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
fn parse() -> Result<Self, lexopt::Error> {
|
||||
use lexopt::prelude::*;
|
||||
|
||||
let mut res = Args::default();
|
||||
|
||||
let mut args = lexopt::Parser::from_env();
|
||||
while let Some(arg) = args.next()? {
|
||||
match arg {
|
||||
Long("fg") => {
|
||||
res.fg = Some(
|
||||
args.value()?
|
||||
.parse_with(|s| s.parse::<u8>().map(anstyle::Ansi256Color))?,
|
||||
);
|
||||
}
|
||||
Long("bg") => {
|
||||
res.fg = Some(
|
||||
args.value()?
|
||||
.parse_with(|s| s.parse::<u8>().map(anstyle::Ansi256Color))?,
|
||||
);
|
||||
}
|
||||
_ => return Err(arg.unexpected()),
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//! Low-level ANSI-styling
|
||||
|
||||
/// Write ANSI colored text to the stream
|
||||
pub fn write_colored<S: std::io::Write + ?Sized>(
|
||||
stream: &mut S,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
let non_default = fg.is_some() || bg.is_some();
|
||||
|
||||
if non_default {
|
||||
if let Some(fg) = fg {
|
||||
write!(stream, "{}", fg.render_fg())?;
|
||||
}
|
||||
if let Some(bg) = bg {
|
||||
write!(stream, "{}", bg.render_bg())?;
|
||||
}
|
||||
}
|
||||
let written = stream.write(data)?;
|
||||
if non_default {
|
||||
write!(stream, "{}", anstyle::Reset.render())?;
|
||||
}
|
||||
Ok(written)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//! Styling legacy Windows terminals
|
||||
//!
|
||||
//! See [`WinconStream`]
|
||||
//!
|
||||
//! This fills a similar role as [`winapi-util`](https://crates.io/crates/winapi-util) does for
|
||||
//! [`termcolor`](https://crates.io/crates/termcolor) with the differences
|
||||
//! - Uses `windows-sys` rather than `winapi`
|
||||
//! - Uses [`anstyle`](https://crates.io/crates/termcolor) rather than defining its own types
|
||||
//! - More focused, smaller
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(clippy::print_stderr)]
|
||||
#![warn(clippy::print_stdout)]
|
||||
|
||||
pub mod ansi;
|
||||
mod stream;
|
||||
#[cfg(windows)]
|
||||
pub mod windows;
|
||||
|
||||
pub use stream::WinconStream;
|
||||
|
||||
#[doc = include_str!("../README.md")]
|
||||
#[cfg(doctest)]
|
||||
pub struct ReadmeDoctests;
|
||||
@@ -0,0 +1,163 @@
|
||||
/// Extend `std::io::Write` with wincon styling
|
||||
pub trait WinconStream {
|
||||
/// Write colored text to the stream
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize>;
|
||||
}
|
||||
|
||||
impl<T: WinconStream + ?Sized> WinconStream for &mut T {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
(**self).write_colored(fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: WinconStream + ?Sized> WinconStream for Box<T> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
(**self).write_colored(fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for dyn std::io::Write {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for dyn std::io::Write + Send {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for dyn std::io::Write + Send + Sync {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for std::fs::File {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for Vec<u8> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for std::io::Stdout {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
// Ensure exclusive access
|
||||
self.lock().write_colored(fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl WinconStream for std::io::Stderr {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
// Ensure exclusive access
|
||||
self.lock().write_colored(fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
mod platform {
|
||||
impl super::WinconStream for std::io::StdoutLock<'_> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
|
||||
impl super::WinconStream for std::io::StderrLock<'_> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
crate::ansi::write_colored(self, fg, bg, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
mod platform {
|
||||
impl super::WinconStream for std::io::StdoutLock<'_> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
let initial = crate::windows::stdout_initial_colors();
|
||||
crate::windows::write_colored(self, fg, bg, data, initial)
|
||||
}
|
||||
}
|
||||
|
||||
impl super::WinconStream for std::io::StderrLock<'_> {
|
||||
fn write_colored(
|
||||
&mut self,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
) -> std::io::Result<usize> {
|
||||
let initial = crate::windows::stderr_initial_colors();
|
||||
crate::windows::write_colored(self, fg, bg, data, initial)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
//! Low-level wincon-styling
|
||||
|
||||
use std::os::windows::io::AsHandle;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
|
||||
type StdioColorResult = std::io::Result<(anstyle::AnsiColor, anstyle::AnsiColor)>;
|
||||
type StdioColorInnerResult = Result<(anstyle::AnsiColor, anstyle::AnsiColor), inner::IoError>;
|
||||
|
||||
/// Cached [`get_colors`] call for [`std::io::stdout`]
|
||||
pub fn stdout_initial_colors() -> StdioColorResult {
|
||||
static INITIAL: once_cell_polyfill::sync::OnceLock<StdioColorInnerResult> =
|
||||
once_cell_polyfill::sync::OnceLock::new();
|
||||
(*INITIAL.get_or_init(|| get_colors_(&std::io::stdout()))).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Cached [`get_colors`] call for [`std::io::stderr`]
|
||||
pub fn stderr_initial_colors() -> StdioColorResult {
|
||||
static INITIAL: once_cell_polyfill::sync::OnceLock<StdioColorInnerResult> =
|
||||
once_cell_polyfill::sync::OnceLock::new();
|
||||
(*INITIAL.get_or_init(|| get_colors_(&std::io::stderr()))).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Apply colors to future writes
|
||||
///
|
||||
/// **Note:** Make sure any buffers are first flushed or else these colors will apply
|
||||
pub fn set_colors<S: AsHandle>(
|
||||
stream: &mut S,
|
||||
fg: anstyle::AnsiColor,
|
||||
bg: anstyle::AnsiColor,
|
||||
) -> std::io::Result<()> {
|
||||
set_colors_(stream, fg, bg).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn set_colors_<S: AsHandle>(
|
||||
stream: &mut S,
|
||||
fg: anstyle::AnsiColor,
|
||||
bg: anstyle::AnsiColor,
|
||||
) -> Result<(), inner::IoError> {
|
||||
let handle = stream.as_handle();
|
||||
let handle = handle.as_raw_handle();
|
||||
let attributes = inner::set_colors(fg, bg);
|
||||
inner::set_console_text_attributes(handle, attributes)
|
||||
}
|
||||
|
||||
/// Get the colors currently active on the console
|
||||
pub fn get_colors<S: AsHandle>(stream: &S) -> StdioColorResult {
|
||||
get_colors_(stream).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn get_colors_<S: AsHandle>(stream: &S) -> StdioColorInnerResult {
|
||||
let handle = stream.as_handle();
|
||||
let handle = handle.as_raw_handle();
|
||||
let info = inner::get_screen_buffer_info(handle)?;
|
||||
let (fg, bg) = inner::get_colors(&info);
|
||||
Ok((fg, bg))
|
||||
}
|
||||
|
||||
pub(crate) fn write_colored<S: AsHandle + std::io::Write>(
|
||||
stream: &mut S,
|
||||
fg: Option<anstyle::AnsiColor>,
|
||||
bg: Option<anstyle::AnsiColor>,
|
||||
data: &[u8],
|
||||
initial: StdioColorResult,
|
||||
) -> std::io::Result<usize> {
|
||||
let (initial_fg, initial_bg) = initial?;
|
||||
let non_default = fg.is_some() || bg.is_some();
|
||||
|
||||
if non_default {
|
||||
let fg = fg.unwrap_or(initial_fg);
|
||||
let bg = bg.unwrap_or(initial_bg);
|
||||
// Ensure everything is written with the last set of colors before applying the next set
|
||||
stream.flush()?;
|
||||
set_colors(stream, fg, bg)?;
|
||||
}
|
||||
let written = stream.write(data)?;
|
||||
if non_default {
|
||||
// Ensure everything is written with the last set of colors before applying the next set
|
||||
stream.flush()?;
|
||||
set_colors(stream, initial_fg, initial_bg)?;
|
||||
}
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
mod inner {
|
||||
use std::os::windows::io::RawHandle;
|
||||
|
||||
use windows_sys::Win32::Foundation::HANDLE;
|
||||
use windows_sys::Win32::System::Console::CONSOLE_CHARACTER_ATTRIBUTES;
|
||||
use windows_sys::Win32::System::Console::CONSOLE_SCREEN_BUFFER_INFO;
|
||||
use windows_sys::Win32::System::Console::FOREGROUND_BLUE;
|
||||
use windows_sys::Win32::System::Console::FOREGROUND_GREEN;
|
||||
use windows_sys::Win32::System::Console::FOREGROUND_INTENSITY;
|
||||
use windows_sys::Win32::System::Console::FOREGROUND_RED;
|
||||
|
||||
const FOREGROUND_CYAN: CONSOLE_CHARACTER_ATTRIBUTES = FOREGROUND_BLUE | FOREGROUND_GREEN;
|
||||
const FOREGROUND_MAGENTA: CONSOLE_CHARACTER_ATTRIBUTES = FOREGROUND_BLUE | FOREGROUND_RED;
|
||||
const FOREGROUND_YELLOW: CONSOLE_CHARACTER_ATTRIBUTES = FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
const FOREGROUND_WHITE: CONSOLE_CHARACTER_ATTRIBUTES =
|
||||
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) enum IoError {
|
||||
BrokenPipe,
|
||||
RawOs(i32),
|
||||
}
|
||||
|
||||
impl From<IoError> for std::io::Error {
|
||||
fn from(io: IoError) -> Self {
|
||||
match io {
|
||||
IoError::BrokenPipe => {
|
||||
std::io::Error::new(std::io::ErrorKind::BrokenPipe, "console is detached")
|
||||
}
|
||||
IoError::RawOs(code) => std::io::Error::from_raw_os_error(code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IoError {
|
||||
fn last_os_error() -> Self {
|
||||
Self::RawOs(std::io::Error::last_os_error().raw_os_error().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_screen_buffer_info(
|
||||
handle: RawHandle,
|
||||
) -> Result<CONSOLE_SCREEN_BUFFER_INFO, IoError> {
|
||||
unsafe {
|
||||
let handle: HANDLE = handle as HANDLE;
|
||||
if handle.is_null() {
|
||||
return Err(IoError::BrokenPipe);
|
||||
}
|
||||
|
||||
let mut info: CONSOLE_SCREEN_BUFFER_INFO = std::mem::zeroed();
|
||||
if windows_sys::Win32::System::Console::GetConsoleScreenBufferInfo(handle, &mut info)
|
||||
!= 0
|
||||
{
|
||||
Ok(info)
|
||||
} else {
|
||||
Err(IoError::last_os_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_console_text_attributes(
|
||||
handle: RawHandle,
|
||||
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
|
||||
) -> Result<(), IoError> {
|
||||
unsafe {
|
||||
let handle: HANDLE = handle as HANDLE;
|
||||
if handle.is_null() {
|
||||
return Err(IoError::BrokenPipe);
|
||||
}
|
||||
|
||||
if windows_sys::Win32::System::Console::SetConsoleTextAttribute(handle, attributes) != 0
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(IoError::last_os_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_colors(
|
||||
info: &CONSOLE_SCREEN_BUFFER_INFO,
|
||||
) -> (anstyle::AnsiColor, anstyle::AnsiColor) {
|
||||
let attributes = info.wAttributes;
|
||||
let bg = from_nibble(attributes >> 4);
|
||||
let fg = from_nibble(attributes);
|
||||
(fg, bg)
|
||||
}
|
||||
|
||||
pub(crate) fn set_colors(
|
||||
fg: anstyle::AnsiColor,
|
||||
bg: anstyle::AnsiColor,
|
||||
) -> CONSOLE_CHARACTER_ATTRIBUTES {
|
||||
to_nibble(bg) << 4 | to_nibble(fg)
|
||||
}
|
||||
|
||||
fn from_nibble(color: CONSOLE_CHARACTER_ATTRIBUTES) -> anstyle::AnsiColor {
|
||||
if color & FOREGROUND_WHITE == FOREGROUND_WHITE {
|
||||
// 3 bits high
|
||||
anstyle::AnsiColor::White
|
||||
} else if color & FOREGROUND_CYAN == FOREGROUND_CYAN {
|
||||
// 2 bits high
|
||||
anstyle::AnsiColor::Cyan
|
||||
} else if color & FOREGROUND_YELLOW == FOREGROUND_YELLOW {
|
||||
// 2 bits high
|
||||
anstyle::AnsiColor::Yellow
|
||||
} else if color & FOREGROUND_MAGENTA == FOREGROUND_MAGENTA {
|
||||
// 2 bits high
|
||||
anstyle::AnsiColor::Magenta
|
||||
} else if color & FOREGROUND_RED == FOREGROUND_RED {
|
||||
// 1 bit high
|
||||
anstyle::AnsiColor::Red
|
||||
} else if color & FOREGROUND_GREEN == FOREGROUND_GREEN {
|
||||
// 1 bit high
|
||||
anstyle::AnsiColor::Green
|
||||
} else if color & FOREGROUND_BLUE == FOREGROUND_BLUE {
|
||||
// 1 bit high
|
||||
anstyle::AnsiColor::Blue
|
||||
} else {
|
||||
// 0 bits high
|
||||
anstyle::AnsiColor::Black
|
||||
}
|
||||
.bright(color & FOREGROUND_INTENSITY == FOREGROUND_INTENSITY)
|
||||
}
|
||||
|
||||
fn to_nibble(color: anstyle::AnsiColor) -> CONSOLE_CHARACTER_ATTRIBUTES {
|
||||
let mut attributes = 0;
|
||||
attributes |= match color.bright(false) {
|
||||
anstyle::AnsiColor::Black => 0,
|
||||
anstyle::AnsiColor::Red => FOREGROUND_RED,
|
||||
anstyle::AnsiColor::Green => FOREGROUND_GREEN,
|
||||
anstyle::AnsiColor::Yellow => FOREGROUND_YELLOW,
|
||||
anstyle::AnsiColor::Blue => FOREGROUND_BLUE,
|
||||
anstyle::AnsiColor::Magenta => FOREGROUND_MAGENTA,
|
||||
anstyle::AnsiColor::Cyan => FOREGROUND_CYAN,
|
||||
anstyle::AnsiColor::White => FOREGROUND_WHITE,
|
||||
anstyle::AnsiColor::BrightBlack
|
||||
| anstyle::AnsiColor::BrightRed
|
||||
| anstyle::AnsiColor::BrightGreen
|
||||
| anstyle::AnsiColor::BrightYellow
|
||||
| anstyle::AnsiColor::BrightBlue
|
||||
| anstyle::AnsiColor::BrightMagenta
|
||||
| anstyle::AnsiColor::BrightCyan
|
||||
| anstyle::AnsiColor::BrightWhite => unreachable!("brights were toggled off"),
|
||||
};
|
||||
if color.is_bright() {
|
||||
attributes |= FOREGROUND_INTENSITY;
|
||||
}
|
||||
attributes
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_from_nibble() {
|
||||
const COLORS: [anstyle::AnsiColor; 16] = [
|
||||
anstyle::AnsiColor::Black,
|
||||
anstyle::AnsiColor::Red,
|
||||
anstyle::AnsiColor::Green,
|
||||
anstyle::AnsiColor::Yellow,
|
||||
anstyle::AnsiColor::Blue,
|
||||
anstyle::AnsiColor::Magenta,
|
||||
anstyle::AnsiColor::Cyan,
|
||||
anstyle::AnsiColor::White,
|
||||
anstyle::AnsiColor::BrightBlack,
|
||||
anstyle::AnsiColor::BrightRed,
|
||||
anstyle::AnsiColor::BrightGreen,
|
||||
anstyle::AnsiColor::BrightYellow,
|
||||
anstyle::AnsiColor::BrightBlue,
|
||||
anstyle::AnsiColor::BrightMagenta,
|
||||
anstyle::AnsiColor::BrightCyan,
|
||||
anstyle::AnsiColor::BrightWhite,
|
||||
];
|
||||
for expected in COLORS {
|
||||
let nibble = to_nibble(expected);
|
||||
let actual = from_nibble(nibble);
|
||||
assert_eq!(expected, actual, "Intermediate: {nibble}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user