pub struct UnicodeConfig {
pub theme: UnicodeTheme,
pub use_fallback: bool,
pub overrides: HashMap<String, char>,
}Expand description
Unicode character configuration
Fields§
§theme: UnicodeThemeCurrent theme
use_fallback: boolWhether to use fallback ASCII characters
overrides: HashMap<String, char>Custom character overrides
Implementations§
Source§impl UnicodeConfig
impl UnicodeConfig
Sourcepub fn with_theme(theme: UnicodeTheme) -> Self
pub fn with_theme(theme: UnicodeTheme) -> Self
Create new config with theme
Examples found in repository?
examples/basic_usage.rs (line 72)
8fn main() {
9 println!("Unicode-rs Basic Usage Example");
10 println!("==============================\n");
11
12 // Demonstrate different themes for the same symbol
13 println!("Symbol themes:");
14 println!(
15 " Minimal: {}",
16 Symbol::Check.get_char(UnicodeTheme::Minimal)
17 );
18 println!(" Basic: {}", Symbol::Check.get_char(UnicodeTheme::Basic));
19 println!(" Rich: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
20 println!(" Fancy: {}", Symbol::Check.get_char(UnicodeTheme::Fancy));
21 println!();
22
23 // Show various symbol categories
24 println!("Symbol categories:");
25
26 // Symbols
27 println!(" Symbols:");
28 println!(" Check: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
29 println!(" X: {}", Symbol::X.get_char(UnicodeTheme::Rich));
30 println!(
31 " !: {}",
32 Symbol::Exclamation.get_char(UnicodeTheme::Rich)
33 );
34 println!(
35 " ?: {}",
36 Symbol::Question.get_char(UnicodeTheme::Rich)
37 );
38 println!();
39
40 // Arrows
41 println!(" Arrows:");
42 println!(" Up: {}", Arrow::Up.get_char(UnicodeTheme::Rich));
43 println!(" Down: {}", Arrow::Down.get_char(UnicodeTheme::Rich));
44 println!(" Left: {}", Arrow::Left.get_char(UnicodeTheme::Rich));
45 println!(" Right: {}", Arrow::Right.get_char(UnicodeTheme::Rich));
46 println!();
47
48 // Git symbols
49 println!(" Git Status:");
50 println!(
51 " Modified: {}",
52 GitStatus::Modified.get_char(UnicodeTheme::Rich)
53 );
54 println!(
55 " Added: {}",
56 GitStatus::Added.get_char(UnicodeTheme::Rich)
57 );
58 println!(
59 " Deleted: {}",
60 GitStatus::Deleted.get_char(UnicodeTheme::Rich)
61 );
62 println!(
63 " Untracked: {}",
64 GitStatus::Untracked.get_char(UnicodeTheme::Rich)
65 );
66 println!();
67
68 // Demonstrate global configuration
69 println!("Global configuration example:");
70
71 // Set global theme to minimal
72 set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
73 println!(" With Minimal theme:");
74 println!(" Check: {}", get_char(&Symbol::Check, None));
75 println!(" Arrow: {}", get_char(&Arrow::Right, None));
76
77 // Set global theme to rich with fallback
78 set_global_config(
79 UnicodeConfig::with_theme(UnicodeTheme::Rich)
80 .with_fallback()
81 .with_override("custom_check", '√'),
82 );
83 println!(" With Rich theme + fallback:");
84 println!(" Check: {}", get_char(&Symbol::Check, None));
85 println!(
86 " Custom: {}",
87 get_char(&Symbol::Check, Some("custom_check"))
88 );
89
90 println!("\nExample complete!");
91}More examples
examples/git_status.rs (line 84)
14fn main() {
15 println!("Git Status Display Example");
16 println!("==========================\n");
17
18 // Sample file statuses
19 let files = vec![
20 FileStatus {
21 path: "src/main.rs".to_string(),
22 status: GitStatus::Modified,
23 },
24 FileStatus {
25 path: "README.md".to_string(),
26 status: GitStatus::Added,
27 },
28 FileStatus {
29 path: "old_file.txt".to_string(),
30 status: GitStatus::Deleted,
31 },
32 FileStatus {
33 path: "new_feature.rs".to_string(),
34 status: GitStatus::Untracked,
35 },
36 FileStatus {
37 path: "Cargo.toml".to_string(),
38 status: GitStatus::Modified,
39 },
40 ];
41
42 // Display with different themes
43 let themes = vec![
44 ("Minimal (ASCII)", UnicodeTheme::Minimal),
45 ("Basic Unicode", UnicodeTheme::Basic),
46 ("Rich Unicode", UnicodeTheme::Rich),
47 ("Fancy Unicode", UnicodeTheme::Fancy),
48 ];
49
50 for (theme_name, theme) in themes {
51 println!("{} theme:", theme_name);
52 println!("{}:", "─".repeat(theme_name.len() + 7));
53
54 for file in &files {
55 let status_char = file.status.get_char(theme);
56 let status_name = format!("{:?}", file.status);
57 println!(" {} {} ({})", status_char, file.path, status_name);
58 }
59 println!();
60 }
61
62 // Demonstrate branch and diff symbols
63 println!("Branch and Diff Symbols:");
64 println!("========================");
65
66 let theme = UnicodeTheme::Rich;
67
68 println!("Branch symbols:");
69 println!(" Current: {}", GitBranch::Current.get_char(theme));
70 println!(" Remote: {}", GitBranch::Remote.get_char(theme));
71 println!(" Local: {}", GitBranch::Local.get_char(theme));
72 println!();
73
74 println!("Diff symbols:");
75 println!(" Added: {}", GitDiff::Added.get_char(theme));
76 println!(" Removed: {}", GitDiff::Removed.get_char(theme));
77 println!(" Modified: {}", GitDiff::Modified.get_char(theme));
78 println!();
79
80 // Create a more realistic git status display
81 println!("Realistic Git Status Display:");
82 println!("============================");
83
84 set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Rich));
85
86 println!("On branch {} main", get_char(&GitBranch::Current, None));
87 println!("Your branch is up to date with 'origin/main'.\n");
88
89 println!("Changes to be committed:");
90 println!(" (use \"git reset HEAD <file>...\" to unstage)\n");
91 for file in files
92 .iter()
93 .filter(|f| matches!(f.status, GitStatus::Added))
94 {
95 println!(
96 " {} {}",
97 get_char(&GitStatus::Added, None),
98 file.path
99 );
100 }
101
102 println!("\nChanges not staged for commit:");
103 println!(" (use \"git add <file>...\" to update what will be committed)");
104 println!(" (use \"git checkout -- <file>...\" to discard changes in working directory)\n");
105 for file in files
106 .iter()
107 .filter(|f| matches!(f.status, GitStatus::Modified | GitStatus::Deleted))
108 {
109 println!(" {} {}", get_char(&file.status, None), file.path);
110 }
111
112 println!("\nUntracked files:");
113 println!(" (use \"git add <file>...\" to include in what will be committed)\n");
114 for file in files
115 .iter()
116 .filter(|f| matches!(f.status, GitStatus::Untracked))
117 {
118 println!(" {} {}", get_char(&file.status, None), file.path);
119 }
120}examples/file_browser.rs (line 125)
34fn main() {
35 println!("File Browser Example");
36 println!("===================\n");
37
38 // Sample file entries
39 let files = vec![
40 FileEntry::new("src", true),
41 FileEntry::new("target", true),
42 FileEntry::new("examples", true),
43 FileEntry::new("main.rs", false),
44 FileEntry::new("lib.rs", false),
45 FileEntry::new("Cargo.toml", false),
46 FileEntry::new("README.md", false),
47 FileEntry::new("package.json", false),
48 FileEntry::new("index.html", false),
49 FileEntry::new("style.css", false),
50 FileEntry::new("script.js", false),
51 FileEntry::new("image.png", false),
52 FileEntry::new("document.pdf", false),
53 FileEntry::new("archive.zip", false),
54 FileEntry::new("config.yaml", false),
55 FileEntry::new("data.json", false),
56 FileEntry::new("test.py", false),
57 FileEntry::new("app.go", false),
58 FileEntry::new("component.tsx", false),
59 FileEntry::new("unknown_file", false),
60 ];
61
62 // Display with different themes
63 let themes = vec![
64 ("Minimal (ASCII)", UnicodeTheme::Minimal),
65 ("Rich Unicode", UnicodeTheme::Rich),
66 ];
67
68 for (theme_name, theme) in themes {
69 println!("{} theme:", theme_name);
70 println!("{}:", "─".repeat(theme_name.len() + 7));
71
72 for file in &files {
73 let icon = if file.is_directory {
74 FileType::Directory.get_char(theme)
75 } else if let Some(ext) = &file.extension {
76 let ft = get_file_type_from_extension(ext);
77 ft.get_char(theme)
78 } else {
79 let ft = get_file_type_from_filename(&file.name);
80 ft.get_char(theme)
81 };
82
83 let file_type_name = if file.is_directory {
84 "Directory".to_string()
85 } else if let Some(ext) = &file.extension {
86 let ft = get_file_type_from_extension(ext);
87 format!("{:?}", ft)
88 } else {
89 let ft = get_file_type_from_filename(&file.name);
90 format!("{:?}", ft)
91 };
92
93 println!(" {} {} ({})", icon, file.name, file_type_name);
94 }
95 println!();
96 }
97
98 // Demonstrate language-specific file types
99 println!("Language-specific file types:");
100 println!("============================");
101
102 let theme = UnicodeTheme::Rich;
103 let languages = vec![
104 ("Rust", LanguageType::Rust),
105 ("JavaScript/TypeScript", LanguageType::JavaScript),
106 ("Python", LanguageType::Python),
107 ("Go", LanguageType::Go),
108 ("HTML", LanguageType::Html),
109 ("CSS", LanguageType::Css),
110 ("JSON", LanguageType::Json),
111 ("YAML", LanguageType::Yaml),
112 ("Markdown", LanguageType::Markdown),
113 ("Shell", LanguageType::Shell),
114 ];
115
116 for (name, lang_type) in languages {
117 println!(" {} {}", lang_type.get_char(theme), name);
118 }
119 println!();
120
121 // Create a more realistic file browser display
122 println!("Realistic File Browser Display:");
123 println!("==============================");
124
125 set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Rich));
126
127 println!("📁 /home/user/project");
128 println!("├── {} src/", get_char(&FileType::Directory, None));
129 println!("│ ├── {} main.rs", get_char(&LanguageType::Rust, None));
130 println!("│ ├── {} lib.rs", get_char(&LanguageType::Rust, None));
131 println!("│ └── {} mod.rs", get_char(&LanguageType::Rust, None));
132 println!("├── {} examples/", get_char(&FileType::Directory, None));
133 println!("│ └── {} basic.rs", get_char(&LanguageType::Rust, None));
134 println!("├── {} target/", get_char(&FileType::Directory, None));
135 println!("├── {} Cargo.toml", get_char(&FileType::Config, None));
136 println!("├── {} README.md", get_char(&LanguageType::Markdown, None));
137 println!("├── {} package.json", get_char(&LanguageType::Json, None));
138 println!("└── {} .gitignore", get_char(&FileType::Config, None));
139
140 println!(
141 "\nFile count: {} directories, {} files",
142 files.iter().filter(|f| f.is_directory).count(),
143 files.iter().filter(|f| !f.is_directory).count()
144 );
145}Sourcepub fn with_fallback(self) -> Self
pub fn with_fallback(self) -> Self
Enable fallback mode
Examples found in repository?
examples/basic_usage.rs (line 80)
8fn main() {
9 println!("Unicode-rs Basic Usage Example");
10 println!("==============================\n");
11
12 // Demonstrate different themes for the same symbol
13 println!("Symbol themes:");
14 println!(
15 " Minimal: {}",
16 Symbol::Check.get_char(UnicodeTheme::Minimal)
17 );
18 println!(" Basic: {}", Symbol::Check.get_char(UnicodeTheme::Basic));
19 println!(" Rich: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
20 println!(" Fancy: {}", Symbol::Check.get_char(UnicodeTheme::Fancy));
21 println!();
22
23 // Show various symbol categories
24 println!("Symbol categories:");
25
26 // Symbols
27 println!(" Symbols:");
28 println!(" Check: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
29 println!(" X: {}", Symbol::X.get_char(UnicodeTheme::Rich));
30 println!(
31 " !: {}",
32 Symbol::Exclamation.get_char(UnicodeTheme::Rich)
33 );
34 println!(
35 " ?: {}",
36 Symbol::Question.get_char(UnicodeTheme::Rich)
37 );
38 println!();
39
40 // Arrows
41 println!(" Arrows:");
42 println!(" Up: {}", Arrow::Up.get_char(UnicodeTheme::Rich));
43 println!(" Down: {}", Arrow::Down.get_char(UnicodeTheme::Rich));
44 println!(" Left: {}", Arrow::Left.get_char(UnicodeTheme::Rich));
45 println!(" Right: {}", Arrow::Right.get_char(UnicodeTheme::Rich));
46 println!();
47
48 // Git symbols
49 println!(" Git Status:");
50 println!(
51 " Modified: {}",
52 GitStatus::Modified.get_char(UnicodeTheme::Rich)
53 );
54 println!(
55 " Added: {}",
56 GitStatus::Added.get_char(UnicodeTheme::Rich)
57 );
58 println!(
59 " Deleted: {}",
60 GitStatus::Deleted.get_char(UnicodeTheme::Rich)
61 );
62 println!(
63 " Untracked: {}",
64 GitStatus::Untracked.get_char(UnicodeTheme::Rich)
65 );
66 println!();
67
68 // Demonstrate global configuration
69 println!("Global configuration example:");
70
71 // Set global theme to minimal
72 set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
73 println!(" With Minimal theme:");
74 println!(" Check: {}", get_char(&Symbol::Check, None));
75 println!(" Arrow: {}", get_char(&Arrow::Right, None));
76
77 // Set global theme to rich with fallback
78 set_global_config(
79 UnicodeConfig::with_theme(UnicodeTheme::Rich)
80 .with_fallback()
81 .with_override("custom_check", '√'),
82 );
83 println!(" With Rich theme + fallback:");
84 println!(" Check: {}", get_char(&Symbol::Check, None));
85 println!(
86 " Custom: {}",
87 get_char(&Symbol::Check, Some("custom_check"))
88 );
89
90 println!("\nExample complete!");
91}Sourcepub fn with_override(self, key: &str, character: char) -> Self
pub fn with_override(self, key: &str, character: char) -> Self
Add character override
Examples found in repository?
examples/basic_usage.rs (line 81)
8fn main() {
9 println!("Unicode-rs Basic Usage Example");
10 println!("==============================\n");
11
12 // Demonstrate different themes for the same symbol
13 println!("Symbol themes:");
14 println!(
15 " Minimal: {}",
16 Symbol::Check.get_char(UnicodeTheme::Minimal)
17 );
18 println!(" Basic: {}", Symbol::Check.get_char(UnicodeTheme::Basic));
19 println!(" Rich: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
20 println!(" Fancy: {}", Symbol::Check.get_char(UnicodeTheme::Fancy));
21 println!();
22
23 // Show various symbol categories
24 println!("Symbol categories:");
25
26 // Symbols
27 println!(" Symbols:");
28 println!(" Check: {}", Symbol::Check.get_char(UnicodeTheme::Rich));
29 println!(" X: {}", Symbol::X.get_char(UnicodeTheme::Rich));
30 println!(
31 " !: {}",
32 Symbol::Exclamation.get_char(UnicodeTheme::Rich)
33 );
34 println!(
35 " ?: {}",
36 Symbol::Question.get_char(UnicodeTheme::Rich)
37 );
38 println!();
39
40 // Arrows
41 println!(" Arrows:");
42 println!(" Up: {}", Arrow::Up.get_char(UnicodeTheme::Rich));
43 println!(" Down: {}", Arrow::Down.get_char(UnicodeTheme::Rich));
44 println!(" Left: {}", Arrow::Left.get_char(UnicodeTheme::Rich));
45 println!(" Right: {}", Arrow::Right.get_char(UnicodeTheme::Rich));
46 println!();
47
48 // Git symbols
49 println!(" Git Status:");
50 println!(
51 " Modified: {}",
52 GitStatus::Modified.get_char(UnicodeTheme::Rich)
53 );
54 println!(
55 " Added: {}",
56 GitStatus::Added.get_char(UnicodeTheme::Rich)
57 );
58 println!(
59 " Deleted: {}",
60 GitStatus::Deleted.get_char(UnicodeTheme::Rich)
61 );
62 println!(
63 " Untracked: {}",
64 GitStatus::Untracked.get_char(UnicodeTheme::Rich)
65 );
66 println!();
67
68 // Demonstrate global configuration
69 println!("Global configuration example:");
70
71 // Set global theme to minimal
72 set_global_config(UnicodeConfig::with_theme(UnicodeTheme::Minimal));
73 println!(" With Minimal theme:");
74 println!(" Check: {}", get_char(&Symbol::Check, None));
75 println!(" Arrow: {}", get_char(&Arrow::Right, None));
76
77 // Set global theme to rich with fallback
78 set_global_config(
79 UnicodeConfig::with_theme(UnicodeTheme::Rich)
80 .with_fallback()
81 .with_override("custom_check", '√'),
82 );
83 println!(" With Rich theme + fallback:");
84 println!(" Check: {}", get_char(&Symbol::Check, None));
85 println!(
86 " Custom: {}",
87 get_char(&Symbol::Check, Some("custom_check"))
88 );
89
90 println!("\nExample complete!");
91}Trait Implementations§
Source§impl Clone for UnicodeConfig
impl Clone for UnicodeConfig
Source§fn clone(&self) -> UnicodeConfig
fn clone(&self) -> UnicodeConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnicodeConfig
impl Debug for UnicodeConfig
Auto Trait Implementations§
impl Freeze for UnicodeConfig
impl RefUnwindSafe for UnicodeConfig
impl Send for UnicodeConfig
impl Sync for UnicodeConfig
impl Unpin for UnicodeConfig
impl UnwindSafe for UnicodeConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more