-
-
Notifications
You must be signed in to change notification settings - Fork 16
Check for Nerd Font and switch #53
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a912c9
Use fc-list to check for Nerd Font
heathhenley d42efd5
Doc format fix
heathhenley 42a5d1a
Use existing shell util
heathhenley 8124e04
WIP: checking for fonts
heathhenley d45419f
Export just icons in pretty
heathhenley 1c98f79
Filename has no space (fc-list prints font name too)
heathhenley 5176f03
Fix: home dir on mac
heathhenley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ | |
| (libraries | ||
| ansifmt | ||
| shell | ||
| str | ||
| ;; Internal dependencies | ||
| extra)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,93 @@ | ||
| let closed_char = "\u{ebda}" | ||
| let open_char = "\u{ea64}" | ||
| let merged_char = "\u{e725}" | ||
| let arrow_left_char = "\u{f0a8}" | ||
| let pwd_char = "\u{e5fd}" | ||
| let dir_char = "\u{f4d4}" | ||
| let empty_dir_char = "\u{f413}" | ||
| let file_char = "\u{f4a5}" | ||
| let bin_char = "\u{eae8}" | ||
| let warning = "\u{26A0}" | ||
| let issue_char = "\u{f41b}" | ||
| type t = { | ||
| closed_char : string; | ||
| open_char : string; | ||
| merged_char : string; | ||
| arrow_left_char : string; | ||
| pwd_char : string; | ||
| dir_char : string; | ||
| empty_dir_char : string; | ||
| file_char : string; | ||
| bin_char : string; | ||
| warning : string; | ||
| issue_char : string; | ||
| } | ||
|
|
||
| let hack_nerd_font = "HackNerdFontMono" | ||
| let fc_list_cmd = Printf.sprintf "fc-list | grep '%s'" hack_nerd_font | ||
| let uname_cmd = {| uname |} | ||
|
|
||
| type os_name = | ||
| | Linux | ||
| | MacOS | ||
|
|
||
| let uname_result = | ||
| Shell.proc_stdout uname_cmd |> String.trim |> function | ||
| | "Linux" -> Some Linux | ||
| | "Darwin" -> Some MacOS | ||
| | _ -> None | ||
|
|
||
| (* Based on the list of possible folders here: https://github.com/adrg/xdg/blob/master/README.md#other-directories*) | ||
| let mac_font_dirs = | ||
| [ | ||
| Unix.getenv "HOME" ^ "/Library/Fonts"; | ||
| "/Library/Fonts"; | ||
| "/System/Library/Fonts"; | ||
| "/Network/Library/Fonts"; | ||
| ] | ||
|
|
||
| let string_contains str substr = | ||
| let re = Str.regexp_string substr in | ||
| try | ||
| ignore (Str.search_forward re str 0); | ||
| true | ||
| with Not_found -> false | ||
|
|
||
| let rec font_exists_in_dirs font_name = function | ||
| | [] -> false | ||
| | dir :: dirs -> | ||
| if Sys.file_exists dir then | ||
| let files = Sys.readdir dir in | ||
| if Array.exists (fun file -> string_contains file font_name) files then | ||
| true | ||
| else font_exists_in_dirs font_name dirs | ||
| else font_exists_in_dirs font_name dirs | ||
|
|
||
| (* We only support mac and linux right now - if the system is unix based and | ||
| it's linux, we can use the fc-list cmd, otherwise on mac we look in common | ||
| directories manually for our font *) | ||
| let nerd_font_installed = | ||
| match uname_result with | ||
| | Some Linux -> | ||
| Shell.proc_stdout fc_list_cmd |> String.trim |> String.length > 0 | ||
| | Some MacOS -> font_exists_in_dirs hack_nerd_font mac_font_dirs | ||
| | None -> false (* do we want this be false or true if we can't tell? *) | ||
|
|
||
| let icons = | ||
| if nerd_font_installed then | ||
| { | ||
| closed_char = "\u{ebda}"; | ||
| open_char = "\u{ea64}"; | ||
| merged_char = "\u{e725}"; | ||
| arrow_left_char = "\u{f0a8}"; | ||
| pwd_char = "\u{e5fd}"; | ||
| dir_char = "\u{f4d4}"; | ||
| empty_dir_char = "\u{f413}"; | ||
| file_char = "\u{f4a5}"; | ||
| bin_char = "\u{eae8}"; | ||
| warning = "\u{26A0}"; | ||
| issue_char = "\u{f41b}"; | ||
| } | ||
| else | ||
| { | ||
| closed_char = "x"; | ||
| open_char = "o"; | ||
| merged_char = "m"; | ||
| arrow_left_char = "<-"; | ||
| pwd_char = "*"; | ||
| dir_char = "/"; | ||
| empty_dir_char = "/"; | ||
| file_char = "f"; | ||
| bin_char = "b"; | ||
| warning = "!"; | ||
| issue_char = "i"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| (** A record representing the icon set **) | ||
| type t = { | ||
| closed_char : string; | ||
| open_char : string; | ||
| merged_char : string; | ||
| arrow_left_char : string; | ||
| pwd_char : string; | ||
| dir_char : string; | ||
| empty_dir_char : string; | ||
| file_char : string; | ||
| bin_char : string; | ||
| warning : string; | ||
| issue_char : string; | ||
| } | ||
|
Comment on lines
+2
to
+14
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea to use a record is really good! |
||
|
|
||
| (** Populated with the current icon set based on if Nerd Font is available or or | ||
| not**) | ||
| val icons : t | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| module Doc = Doc | ||
| module Layout = Layout | ||
| module Style = Style | ||
| module Icon = Icon | ||
|
|
||
| let icons = Icon.icons | ||
|
|
||
| let render ~width ~height doc = | ||
| doc |> Doc.render ~width ~height |> Layout.to_lines |> Extra.String.unlines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.