Debian Codegraph @

src/subcommands/show_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/, ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#};
2
3 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/;
4 use craterust-analyzer cargo git-delta 0.19.2 crate/::colorrust-analyzer cargo git-delta 0.19.2 color/::ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#;
5 use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/;
6 use craterust-analyzer cargo git-delta 0.19.2 crate/::deltarust-analyzer cargo git-delta 0.19.2 delta/;
7 use craterust-analyzer cargo git-delta 0.19.2 crate/::envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#;
8 use craterust-analyzer cargo git-delta 0.19.2 crate/::git_configrust-analyzer cargo git-delta 0.19.2 git_config/;
9 use craterust-analyzer cargo git-delta 0.19.2 crate/::optionsrust-analyzer cargo git-delta 0.19.2 options/::getrust-analyzer cargo git-delta 0.19.2 options/get/::get_themesrust-analyzer cargo git-delta 0.19.2 options/get/get_themes().;
10 use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/::batrust-analyzer cargo git-delta 0.19.2 utils/bat/::outputrust-analyzer cargo git-delta 0.19.2 utils/bat/output/::{OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#, PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#};
11
12 pub fn show_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_themes/show_themes().(dark: bool, light: bool, color_mode: ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#) -> 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#<()> {
13 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/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#;
14
15 use bytelinesrust-analyzer cargo bytelines 2.5.0 crate/::ByteLinesrust-analyzer cargo bytelines 2.5.0 std/ByteLines#;
16
17 use superrust-analyzer cargo git-delta 0.19.2 subcommands/::sample_diffrust-analyzer cargo git-delta 0.19.2 subcommands/sample_diff/::DIFFrust-analyzer cargo git-delta 0.19.2 subcommands/sample_diff/DIFF.;
18
19 let env = DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().();
20 let themes = get_themesrust-analyzer cargo git-delta 0.19.2 options/get/get_themes().(git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#::try_createrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]try_create().(&env));
21 if themes.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
22 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(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/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
23 ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::NotFoundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#NotFound#,
24 "No themes found. Please see https://dandavison.github.io/delta/custom-themes.html.",
25 ));
26 }
27
28 let mut input = DIFFrust-analyzer cargo git-delta 0.19.2 subcommands/sample_diff/DIFF..to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().();
29
30 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin][IsTerminal]is_terminal().() {
31 let mut buf = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
32 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdin().().lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdin]lock().().read_to_endrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[`StdinLock<'_>`][Read]read_to_end().(&mut buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
33 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().buf.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
34 input = buf;
35 }
36 };
37
38 let git_config = git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#::try_createrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]try_create().(&env);
39 let opt = clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::from_iter_and_git_configrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt]from_iter_and_git_config().(
40 &env,
41 &["delta", "--navigate", "--show-themes"],
42 git_config,
43 );
44 let mut output_type = OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::from_moderust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]from_mode().(
45 &env,
46 PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::Alwaysrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Always#,
47 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
48 &configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#::fromrust-analyzer cargo git-delta 0.19.2 config/impl#[Config][`From<cli::Opt>`]from().(opt).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
49 )
50 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 let title_style = ansi_termrust-analyzer cargo nu-ansi-term 0.50.3 crate/::Stylerust-analyzer cargo nu-ansi-term 0.50.3 style/Style#::newrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style]new().().boldrust-analyzer cargo nu-ansi-term 0.50.3 style/impl#[Style]bold().();
52 let writer = output_type.handlerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]handle().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
53
54 for theme in &themes {
55 let git_config = git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#::try_createrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]try_create().(&env);
56 let opt =
57 clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::from_iter_and_git_configrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt]from_iter_and_git_config().(&env, &["delta", "--features", theme], git_config);
58 let is_dark_theme = opt.darkrust-analyzer cargo git-delta 0.19.2 cli/Opt#dark.;
59 let is_light_theme = opt.lightrust-analyzer cargo git-delta 0.19.2 cli/Opt#light.;
60 let config = configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#::fromrust-analyzer cargo git-delta 0.19.2 config/impl#[Config][`From<cli::Opt>`]from().(opt);
61
62 if (color_mode rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq().==rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq(). rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq().ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#::Darkrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Dark# && is_dark_theme)
63 || (color_mode rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq().==rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq(). rust-analyzer cargo git-delta 0.19.2 color/impl#[ColorMode][`PartialEq<Self>`]eq().ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#::Lightrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Light# && is_light_theme)
64 || (dark && light)
65 {
66 writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!(writer, "\n\nTheme: {}\n", title_style.paintrust-analyzer cargo nu-ansi-term 0.50.3 display/impl#[Style]paint().(theme))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
67
68 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) =
69 deltarust-analyzer cargo git-delta 0.19.2 delta/::deltarust-analyzer cargo git-delta 0.19.2 delta/delta().(ByteLinesrust-analyzer cargo bytelines 2.5.0 std/ByteLines#::newrust-analyzer cargo bytelines 2.5.0 std/impl#[`ByteLines<B>`]new().(BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(&input[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)), writer, &config)
70 {
71 match error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() {
72 ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::BrokenPiperust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#BrokenPipe# => stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::exitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/exit().(0),
73 _ => eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{error}"),
74 }
75 }
76 }
77 }
78
79 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
80 }