| 1 | use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/; |
| 2 | 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#, ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#::*}; |
| 3 | use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/; |
| 4 | use craterust-analyzer cargo git-delta 0.19.2 crate/::deltarust-analyzer cargo git-delta 0.19.2 delta/; |
| 5 | 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#; |
| 6 | 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/::color_mode_from_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/color_mode_from_syntax_theme().; |
| 7 | use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/; |
| 8 | 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#}; |
| 9 | use claprust-analyzer cargo clap 4.5.60 crate/::Parserrust-analyzer cargo clap_builder 4.5.60 derive/Parser#; |
| 10 | 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#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 11 | |
| 12 | #[cfg(not(tarpaulin_include))] |
| 13 | pub fn show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/show_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#<()> { |
| 14 | 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().(); |
| 15 | 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().(); |
| 16 | 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().( |
| 17 | &env, |
| 18 | PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::QuitIfOneScreenrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#QuitIfOneScreen#, |
| 19 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 20 | &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().(clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::parserust-analyzer cargo clap_builder 4.5.60 derive/Parser#parse().()).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 21 | ) |
| 22 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 23 | let mut 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().(); |
| 24 | |
| 25 | let stdin_data = 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().() { |
| 26 | 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().(); |
| 27 | 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().; |
| 28 | 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().() { |
| 29 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(buf) |
| 30 | } else { |
| 31 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 32 | } |
| 33 | } else { |
| 34 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 35 | }; |
| 36 | |
| 37 | let make_opt = || { |
| 38 | let mut opt = clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::parserust-analyzer cargo clap_builder 4.5.60 derive/Parser#parse().(); |
| 39 | opt.computedrust-analyzer cargo git-delta 0.19.2 cli/Opt#computed..syntax_setrust-analyzer cargo git-delta 0.19.2 cli/ComputedValues#syntax_set. = assets.get_syntax_setrust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]get_syntax_set().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().clonerust-analyzer cargo syntect 5.3.0 parsing/syntax_set/impl#[SyntaxSet][Clone]clone().(); |
| 40 | opt |
| 41 | }; |
| 42 | let opt = make_opt(); |
| 43 | |
| 44 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(opt.darkrust-analyzer cargo git-delta 0.19.2 cli/Opt#dark. || opt.lightrust-analyzer cargo git-delta 0.19.2 cli/Opt#light.) { |
| 45 | _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().(opt, Darkrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Dark#, &mut writer, stdin_data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().(make_opt(), Lightrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Light#, &mut writer, stdin_data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 47 | } else if opt.lightrust-analyzer cargo git-delta 0.19.2 cli/Opt#light. { |
| 48 | _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().(opt, Lightrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Light#, &mut writer, stdin_data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 49 | } else { |
| 50 | _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().(opt, Darkrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Dark#, &mut writer, stdin_data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 51 | }; |
| 52 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 53 | } |
| 54 | |
| 55 | fn _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().( |
| 56 | mut opt: clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#, |
| 57 | color_mode: ColorModerust-analyzer cargo git-delta 0.19.2 color/ColorMode#, |
| 58 | writer: &mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 59 | stdin: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 60 | ) -> 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#<()> { |
| 61 | use bytelinesrust-analyzer cargo bytelines 2.5.0 crate/::ByteLinesrust-analyzer cargo bytelines 2.5.0 std/ByteLines#; |
| 62 | 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#; |
| 63 | let input = match stdin { |
| 64 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stdin_data) => &stdin_data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 65 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 66 | b"\ |
| 67 | diff --git a/example.rs b/example.rs |
| 68 | index f38589a..0f1bb83 100644 |
| 69 | --- a/example.rs |
| 70 | +++ b/example.rs |
| 71 | @@ -1,5 +1,5 @@ |
| 72 | -// Output the square of a number. |
| 73 | -fn print_square(num: f64) { |
| 74 | - let result = f64::powf(num, 2.0); |
| 75 | - println!(\"The square of {:.2} is {:.2}.\", num, result); |
| 76 | +// Output the cube of a number. |
| 77 | +fn print_cube(num: f64) { |
| 78 | + let result = f64::powf(num, 3.0); |
| 79 | + println!(\"The cube of {:.2} is {:.2}.\", num, result); |
| 80 | " |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | opt.computedrust-analyzer cargo git-delta 0.19.2 cli/Opt#computed..color_moderust-analyzer cargo git-delta 0.19.2 cli/ComputedValues#color_mode. = color_mode; |
| 85 | let mut 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); |
| 86 | 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().(); |
| 87 | 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().(); |
| 88 | |
| 89 | for syntax_theme in assets |
| 90 | .themesrust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]themes().() |
| 91 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|t| color_mode_from_syntax_themerust-analyzer cargo git-delta 0.19.2 options/theme/color_mode_from_syntax_theme().(t) 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().color_mode) |
| 92 | { |
| 93 | writelnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/writeln!!( |
| 94 | writer, |
| 95 | "\n\nSyntax theme: {}\n", |
| 96 | title_style.paintrust-analyzer cargo nu-ansi-term 0.50.3 display/impl#[Style]paint().(syntax_theme) |
| 97 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 98 | config.syntax_themerust-analyzer cargo git-delta 0.19.2 config/Config#syntax_theme. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(assets.get_themerust-analyzer cargo bat 0.26.1 assets/impl#[HighlightingAssets]get_theme().(syntax_theme).clonerust-analyzer cargo syntect 5.3.0 highlighting/theme/impl#[Theme][Clone]clone().()); |
| 99 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = |
| 100 | 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 core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)), writer, &config) |
| 101 | { |
| 102 | match error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() { |
| 103 | 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), |
| 104 | _ => eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{error}"), |
| 105 | } |
| 106 | }; |
| 107 | } |
| 108 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 109 | } |
| 110 | |
| 111 | #[cfg(test)] |
| 112 | mod testsrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/tests/ { |
| 113 | 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#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#}; |
| 114 | |
| 115 | use superrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/::*; |
| 116 | use craterust-analyzer cargo git-delta 0.19.2 crate/::ansirust-analyzer cargo git-delta 0.19.2 ansi/; |
| 117 | use craterust-analyzer cargo git-delta 0.19.2 crate/::testsrust-analyzer cargo git-delta 0.19.2 tests/::integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/; |
| 118 | |
| 119 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 120 | #[ignore] // Not working (timing out) when run by tarpaulin, presumably due to stdin detection. |
| 121 | fn test_show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/tests/test_show_syntax_themes().() { |
| 122 | let opt = integration_test_utilsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::make_options_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args().(&[]); |
| 123 | |
| 124 | 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; 1024]); |
| 125 | _show_syntax_themesrust-analyzer cargo git-delta 0.19.2 subcommands/show_syntax_themes/_show_syntax_themes().(opt, Lightrust-analyzer cargo git-delta 0.19.2 color/ColorMode#Light#, &mut writer, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 126 | 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().(); |
| 127 | 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().(); |
| 128 | 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().(); |
| 129 | let s = ansirust-analyzer cargo git-delta 0.19.2 ansi/::strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(&s); |
| 130 | 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().("\nSyntax theme: gruvbox-light\n")); |
| 131 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{s}"); |
| 132 | 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().("\nfn print_cube(num: f64) {\n")); |
| 133 | } |
| 134 | } |