Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nerd font glyphs in languages info #1395

Merged
merged 21 commits into from
Aug 31, 2024
Merged

Conversation

Localghost385
Copy link
Contributor

@Localghost385 Localghost385 commented Aug 16, 2024

Add support for nerd font glyphs in languages info

resolves #1308

far from finalized, but a decent chunk of it is done.
any language missing a special icon just uses the circle one.

I haven't added any test coverage, but all previous tests complete.

Not missing icons

  • Ada: "\uE6B5" 
  • Arduino: "\uF34B" 
  • Assembly: "\uE6AB" 
  • Bash: "\uEBCA" 
  • C: "\uE61E" 
  • Clojure: "\uE768" 
  • CoffeeScript: "\uE751" 
  • ColdFusion: "\uE645" 
  • Cpp: "\uE61D" 
  • Crystal: "\uE62F" 
  • CSharp: "\uE648" 
  • Css: "\uE749" 
  • D: "\uE7AF" 
  • Dart: "\uE64C" 
  • Dockerfile: "\uF308" 
  • Elisp: "\uE632" 
  • Elixir: "\uE62D" 
  • Elm: "\uE62C" 
  • Emojicode: "\uf1044" 󱁄
  • Erlang: "\uE7B1" 
  • Fish: "\uEE41" 
  • FortranLegacy: "\U000f121a" 󱈚
  • FortranModern: "\U000f121a" 󱈚
  • FSharp: "\uE7A7" 
  • GdScript: "\uE65F" 
  • Go: "\uE627" 
  • Graphql: "\ue662" 
  • Groovy: "\uE775" 
  • Haskell: "\uE777" 
  • Haxe: "\uE666" 
  • HolyC: "\uE61E" 
  • Html: "\uE736" 
  • Java: "\uE738" 
  • JavaScript: "\uF2EE" 
  • Json: "\ueb0f" 
  • Jsx: "\uF2EE" 
  • Julia: "\uE624" 
  • Kotlin: "\uE634" 
  • Lisp: "\uE6B0" 
  • Lua: "\uE620" 
  • Makefile: "\uE673" 
  • Markdown: "\uE73E" 
  • Nim: "\uE677" 
  • Nix: "\uf313" 󱄅
  • OCaml: "\uE67A" 
  • Org: "\uE633" 
  • Perl: "\uE67E" 
  • Php: "\U000f031f" 󰌟
  • PowerShell: "\U000f0a0a" 󰨊
  • Prolog: "\uE7A1" 
  • PureScript: "\uE630" 
  • Python: "\uE73C" 
  • R: "\uE68A" 
  • Ruby: "\uE739" 
  • Rust: "\uE7A8" 
  • Sass: "\uE74B" 
  • Scala: "\uE737" 
  • Scheme: "\uE6B1" 
  • Sh: "\U000f1183" 󱆃
  • Sql: "\uE737" 
  • Svelte: "\uE697" 
  • Svg: "\U000f0721" 󰜡
  • Swift: "\uE755" 
  • SystemVerilog: "\uF4BC" 
  • Tcl: "\ue7c4" 
  • Tex: "\uE69B" 
  • Toml: "\uE6B2" 
  • Tsx: "\uE69D" 
  • TypeScript: "\uE69D" 
  • Verilog: "\uF4BC" 
  • Vhdl: "\uF4BC" 
  • VimScript: "\uE7C5" 
  • Vue: "\uE6A0" 
  • WebAssembly: "\uE6A1" 
  • Xaml: "\U000f0673" 󰙳
  • Xml: "\U000f05c0" 󰗀
  • XSL: "\U000f05c0" 󰗀
  • Yaml: "\uE6A8" 
  • Zig: "\uE6A9" 
  • Zsh: "\U000f1183" 󱆃

Missing icons

  • Abap:
  • ABNF:
  • Agda:
  • AutoHotKey:
  • Ceylon:
  • CMake:
  • Coq:
  • Forth:
  • Glsl:
  • Hcl:
  • Hlsl:
  • Idris:
  • Jsonnet:
  • Jupyter:
  • LLVM:
  • ObjectiveC:
  • Odin:
  • Oz:
  • Pascal:
  • Perl6:
  • Processing:
  • Protobuf:
  • Qml:
  • Racket:
  • Renpy:
  • Solidity:
  • Vala:
  • VisualBasic:
  • Wolfram:

@Localghost385
Copy link
Contributor Author

the failed check is an extra space. I didn't think it was worth another commit.

src/info/langs/language.rs Outdated Show resolved Hide resolved
src/info/langs/language.rs Outdated Show resolved Hide resolved
src/info/langs/language.tera Outdated Show resolved Hide resolved
src/info/langs/language.tera Outdated Show resolved Hide resolved
@spenserblack
Copy link
Collaborator

spenserblack commented Aug 16, 2024

Looks pretty good so far! If you're planning on pushing up more commits, could you mark this as draft? And then mark it as ready when you're done.

@Localghost385 Localghost385 marked this pull request as draft August 16, 2024 19:58
@Localghost385
Copy link
Contributor Author

Do these changes warrant a new test?

@Localghost385 Localghost385 marked this pull request as ready for review August 17, 2024 18:19
@Localghost385
Copy link
Contributor Author

@spenserblack is there anything else i can do for this? Sorry to bother you if not.

Copy link
Collaborator

@spenserblack spenserblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! One stylistic nitpick, but you don't have to worry about it.

src/info/langs/language.rs Outdated Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
src/info/langs/language.rs Outdated Show resolved Hide resolved
circle_color: DynColors,
icon: &'static str,
}

fn prepare_languages(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a unit test on this method to cover the case when languages_info.nerd_fonts is true

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this a bit easier to test, I'd recommend writing a method that's implemented on either Language or LanguagesInfo. This method would resolve the icon or fall back to the circle when it's either disabled or not supported.

For example:

// on language
impl Language {
    fn get_chip(&self, use_nerd_fonts: bool) -> &'static str {
        if !use_nerd_fonts {
            return DEFAULT_ICON;
        }
        self.get_icon().unwrap_or(DEFAULT_ICON)
    }
}

And if you were to implement it on LanguagesInfo, it would take language as an argument and use self.nerd_fonts.

You don't need to use this exact implementation, but this is an example of how you could organize code to make it easier to test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a test for this case before I saw your suggestion.

It's identical to the one before it except for the value of nerd_fonts, and the expected result.

Is it worth changing it?

    fn test_prepare_languages_with_nerd_fonts() {
        let languages_info = LanguagesInfo {
            languages_with_percentage: vec![
                LanguageWithPercentage {
                    language: Language::Go,
                    percentage: 40_f64,
                },
                LanguageWithPercentage {
                    language: Language::Erlang,
                    percentage: 30_f64,
                },
                LanguageWithPercentage {
                    language: Language::Java,
                    percentage: 20_f64,
                },
                LanguageWithPercentage {
                    language: Language::Rust,
                    percentage: 10_f64,
                },
            ],
            true_color: false,
            number_of_languages_to_display: 2,
            info_color: DynColors::Ansi(AnsiColors::White),
            nerd_fonts: true,
        };

        let color_palette = [
            DynColors::Ansi(AnsiColors::Red),
            DynColors::Ansi(AnsiColors::Green),
        ];

        let result = prepare_languages(&languages_info, &color_palette);

        let expected_result = vec![
            LanguageDisplayData {
                language: Language::Go.to_string(),
                percentage: 40_f64,
                chip_color: DynColors::Ansi(AnsiColors::Red),
                icon: Language::Go.get_icon().unwrap(),
            },
            LanguageDisplayData {
                language: Language::Erlang.to_string(),
                percentage: 30_f64,
                chip_color: DynColors::Ansi(AnsiColors::Green),
                icon: Language::Erlang.get_icon().unwrap(),
            },
            LanguageDisplayData {
                language: "Other".to_string(),
                percentage: 30_f64,
                chip_color: DynColors::Ansi(AnsiColors::White),
                icon: DEFAULT_ICON,
            },
        ];

        assert_eq!(result, expected_result);
    }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied @spenserblack's suggestion in 43023ed

Should be good to go now

Copy link
Owner

@o2sh o2sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very cool new feature! 😍

Thanks a lot for implementing it, @Localghost385. 👍

I left a few suggestions—feel free to take them into consideration when you have time.

BTW, you should probably update the section of CONTRIBUTING.md that explains how to add support for a new language.

languages.yaml Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
languages.yaml Outdated Show resolved Hide resolved
@o2sh o2sh merged commit 6bf1807 into o2sh:main Aug 31, 2024
11 checks passed
@hasecilu
Copy link

Thanks for implementing this feature, it works really nice!
Few of the missing icons are on https://github.com/devicons/devicon/ project that will be merged into Nerd Fonts soon(TM), so when new NF version is released will be available to use.

@o2sh
Copy link
Owner

o2sh commented Sep 1, 2024

That's great news!
Please keep us posted @hasecilu

@Localghost385
Copy link
Contributor Author

@o2sh I can keep the icons up to date as they are added, it might also be a good idea to have a better place to track missing icons than this pr.

@o2sh
Copy link
Owner

o2sh commented Sep 1, 2024

Sure @Localghost385, you can create a tracking issue and pin it.

@o2sh o2sh added the feat label Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include a flag to replace the "circle" with a glyph from Nerd Fonts
4 participants