Debian Codegraph @

src/subcommands/list_syntax_themes.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
2
3 use itertoolsrust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#;
4
5 use craterust-analyzer cargo git-delta 0.19.2 crate/::{optionsrust-analyzer cargo git-delta 0.19.2 options/::themerust-analyzer cargo git-delta 0.19.2 options/theme/::is_light_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/is_light_syntax_theme()., utilsrust-analyzer cargo git-delta 0.19.2 utils/};
6
7 #[cfg(not(tarpaulin_include))]
8 pub fn list_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/list_syntax_themes().() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
9 let stdout = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().();
10 let mut stdout = stdout.lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout]lock().();
11 if stdout.is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[`StdoutLock<'_>`][IsTerminal]is_terminal().() {
12 _list_syntax_themes_for_humansrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_humans().(&mut stdout)
13 } else {
14 _list_syntax_themes_for_machinesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_machines().(&mut stdout)
15 }
16 }
17
18 pub fn _list_syntax_themes_for_humansrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_humans().(writer: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
19 let assets = utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/::load_highlighting_assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/load_highlighting_assets().();
20
21 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, "Light syntax themes:")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
22 for theme in assets.themesrust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]themes().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|t| is_light_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/is_light_syntax_theme().(t)) {
23 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, " {theme}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
24 }
25 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, "\nDark syntax themes:")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
26 for theme in assets.themesrust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]themes().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|t| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_light_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/is_light_syntax_theme().(t)) {
27 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, " {theme}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
28 }
29 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(
30 writer,
31 "\nUse delta --show-syntax-themes to demo the themes."
32 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
33 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
34 }
35
36 pub fn _list_syntax_themes_for_machinesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_machines().(writer: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> {
37 let assets = utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/::load_highlighting_assetsrust-analyzer cargo git-delta 0.19.2 utils/bat/assets/load_highlighting_assets().();
38 for theme in assets.themesrust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]themes().().sorted_by_keyrust-analyzer cargo itertools 0.14.0 Itertools#sorted_by_key().(|t| is_light_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/is_light_syntax_theme().(t)) {
39 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(
40 writer,
41 "{}\t{}",
42 if is_light_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/is_light_syntax_theme().(theme) {
43 "light"
44 } else {
45 "dark"
46 },
47 theme
48 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
49 }
50 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
51 }
52
53 #[cfg(test)]
54 mod testsrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/tests/ {
55 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#};
56
57 use superrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/::*;
58
59 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
60 fn test_list_syntax_themes_for_humansrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/tests/test_list_syntax_themes_for_humans().() {
61 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 512]);
62 _list_syntax_themes_for_humansrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_humans().(&mut writer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
63 let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
64 writer.rewindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#rewind().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
65 writer.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Read]read_to_string().(&mut s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
66 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Light syntax themes:\n"));
67 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(" GitHub\n"));
68 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("Dark syntax themes:\n"));
69 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(" Dracula\n"));
70 }
71
72 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
73 fn test_list_syntax_themes_for_machinesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/tests/test_list_syntax_themes_for_machines().() {
74 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; 512]);
75 _list_syntax_themes_for_machinesrust-analyzer cargo git-delta 0.19.2 subcommands/list_syntax_themes/_list_syntax_themes_for_machines().(&mut writer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
76 let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
77 writer.rewindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#rewind().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
78 writer.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Read]read_to_string().(&mut s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
79 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("light GitHub\n"));
80 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(s.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("dark Dracula\n"));
81 }
82 }