color: extract into new crate

This moves the code from `src/color.rs` into a new dedicated crate.

Closes #12311
This commit is contained in:
Daniel Rainer
2026-01-12 02:29:56 +01:00
committed by Johannes Altmanninger
parent b14692cb95
commit 2c06731a14
9 changed files with 33 additions and 13 deletions

9
Cargo.lock generated
View File

@@ -160,6 +160,7 @@ dependencies = [
"errno",
"fish-build-helper",
"fish-build-man-pages",
"fish-color",
"fish-common",
"fish-fallback",
"fish-gettext",
@@ -202,6 +203,14 @@ dependencies = [
"rsconf",
]
[[package]]
name = "fish-color"
version = "0.0.0"
dependencies = [
"fish-common",
"fish-widestring",
]
[[package]]
name = "fish-common"
version = "0.0.0"

View File

@@ -17,6 +17,7 @@ cfg-if = "1.0.3"
errno = "0.3.0"
fish-build-helper = { path = "crates/build-helper" }
fish-build-man-pages = { path = "crates/build-man-pages" }
fish-color = { path = "crates/color" }
fish-common = { path = "crates/common" }
fish-fallback = { path = "crates/fallback" }
fish-gettext = { path = "crates/gettext" }
@@ -93,6 +94,7 @@ cfg-if.workspace = true
errno.workspace = true
fish-build-helper.workspace = true
fish-build-man-pages = { workspace = true, optional = true }
fish-color.workspace = true
fish-common.workspace = true
fish-fallback.workspace = true
fish-gettext = { workspace = true, optional = true }

14
crates/color/Cargo.toml Normal file
View File

@@ -0,0 +1,14 @@
[package]
name = "fish-color"
edition.workspace = true
rust-version.workspace = true
version = "0.0.0"
repository.workspace = true
license.workspace = true
[dependencies]
fish-common.workspace = true
fish-widestring.workspace = true
[lints]
workspace = true

View File

@@ -322,8 +322,8 @@ fn term256_color_for_rgb(color: Color24) -> u8 {
#[cfg(test)]
mod tests {
use crate::color::{Color, Color24};
use crate::prelude::*;
use super::{Color, Color24};
use fish_widestring::L;
#[test]
fn parse() {

View File

@@ -1,13 +1,13 @@
// Implementation of the set_color builtin.
use super::prelude::*;
use crate::color::Color;
use crate::common::bytes2wcstring;
use crate::screen::{is_dumb, only_grayscale};
use crate::terminal::{Outputter, use_terminfo};
use crate::text_face::{
self, PrintColorsArgs, SpecifiedTextFace, TextFace, TextStyling, parse_text_face_and_options,
};
use fish_color::Color;
fn print_colors(
streams: &mut IoStreams,

View File

@@ -5,7 +5,6 @@
Keyword, Kind, Node, NodeVisitor, Redirection, Token, VariableAssignment,
};
use crate::builtins::shared::builtin_exists;
use crate::color::Color;
use crate::common::{valid_var_name, valid_var_name_char};
use crate::complete::complete_wrap_map;
use crate::env::{EnvVar, Environment};
@@ -30,6 +29,7 @@
use crate::threads::assert_is_background_thread;
use crate::tokenizer::{PipeOrRedir, variable_assignment_equals_pos};
use crate::wcstringutil::string_prefixes_string;
use fish_color::Color;
use fish_common::{ASCII_MAX, EXPAND_RESERVED_BASE, EXPAND_RESERVED_END};
use fish_widestring::{L, WExt, WString, wstr};
use std::collections::HashMap;

View File

@@ -13,7 +13,6 @@
pub mod ast;
pub mod autoload;
pub mod builtins;
pub mod color;
pub mod complete;
pub mod editable_line;
pub mod env;

View File

@@ -1,5 +1,4 @@
// Generic output functions.
use crate::color::{Color, Color24};
use crate::common::ToCString;
use crate::common::{self, EscapeStringStyle, escape_string, wcs2bytes, wcs2bytes_appending};
use crate::flogf;
@@ -9,6 +8,7 @@
use crate::text_face::{TextFace, TextStyling, UnderlineStyle};
use crate::threads::MainThread;
use bitflags::bitflags;
use fish_color::{Color, Color24};
use std::cell::{RefCell, RefMut};
use std::env;
use std::ffi::{CStr, CString};

View File

@@ -1,7 +1,7 @@
use crate::color::Color;
use crate::prelude::*;
use crate::terminal::{self, get_color_support};
use crate::wgetopt::{ArgType, WGetopter, WOption, wopt};
use fish_color::Color;
trait StyleSet {
fn union_prefer_right(self, other: Self) -> Self;
@@ -324,12 +324,8 @@ fn init_style(style: &mut Option<TextStyling>) -> &mut TextStyling {
#[cfg(test)]
mod tests {
use crate::{
color::{Color, Color24},
text_face::SpecifiedTextFace,
};
use super::parse_text_face;
use super::{SpecifiedTextFace, parse_text_face};
use fish_color::{Color, Color24};
#[test]
fn test_parse_text_face() {