package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6

doc/src/miaou_widgets_layout/file_icons.ml.html

Source file file_icons.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2026 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

module W = Miaou_widgets_display.Widgets

let nerd_font_enabled () =
  match Sys.getenv_opt "MIAOU_NERD_FONT" with
  | Some ("1" | "true" | "TRUE" | "yes" | "YES") -> true
  | _ -> false

(* Lower-case the trailing extension (no leading dot). Returns "" for
   files without a recognisable extension. *)
let extension_lower name =
  match Filename.extension name with
  | "" -> ""
  | ext ->
      let s = String.sub ext 1 (String.length ext - 1) in
      String.lowercase_ascii s

(* (icon-without-nerd, icon-nerd, fg-256-color-or-(-1)) per extension/special. *)
let table =
  [
    ("ml", ("๐Ÿซ", "", 214));
    ("mli", ("๐Ÿซ", "", 214));
    ("rs", ("๐Ÿฆ€", "", 208));
    ("py", ("๐Ÿ", "", 33));
    ("js", ("๐Ÿ“œ", "", 220));
    ("ts", ("๐Ÿ“œ", "", 75));
    ("json", ("๐Ÿ“ฆ", "", 178));
    ("yaml", ("๐Ÿ“ฆ", "", 178));
    ("yml", ("๐Ÿ“ฆ", "", 178));
    ("toml", ("๐Ÿ“ฆ", "", 178));
    ("md", ("๐Ÿ“", "", 252));
    ("markdown", ("๐Ÿ“", "", 252));
    ("txt", ("๐Ÿ“„", "", 250));
    ("log", ("๐Ÿ“‹", "", 244));
    ("sh", ("๐Ÿ”ง", "", 64));
    ("bash", ("๐Ÿ”ง", "", 64));
    ("zsh", ("๐Ÿ”ง", "", 64));
    ("fish", ("๐Ÿ”ง", "", 64));
    ("html", ("๐ŸŒ", "", 202));
    ("css", ("๐ŸŽจ", "", 39));
    ("png", ("๐Ÿ–ผ", "", 141));
    ("jpg", ("๐Ÿ–ผ", "", 141));
    ("jpeg", ("๐Ÿ–ผ", "", 141));
    ("gif", ("๐Ÿ–ผ", "", 141));
    ("svg", ("๐Ÿ–ผ", "", 141));
    ("pdf", ("๐Ÿ“•", "", 124));
    ("zip", ("๐Ÿ“ฆ", "", 130));
    ("tar", ("๐Ÿ“ฆ", "", 130));
    ("gz", ("๐Ÿ“ฆ", "", 130));
    ("xz", ("๐Ÿ“ฆ", "", 130));
    ("bz2", ("๐Ÿ“ฆ", "", 130));
    ("7z", ("๐Ÿ“ฆ", "", 130));
    ("rar", ("๐Ÿ“ฆ", "", 130));
    ("c", ("๐Ÿ“˜", "", 67));
    ("h", ("๐Ÿ“˜", "", 67));
    ("cpp", ("๐Ÿ“˜", "", 67));
    ("hpp", ("๐Ÿ“˜", "", 67));
    ("go", ("๐Ÿน", "", 75));
    ("hs", ("๐Ÿ“˜", "", 99));
    ("rb", ("๐Ÿ’Ž", "", 197));
    ("lock", ("๐Ÿ”’", "", 244));
  ]

let lookup ext =
  match List.assoc_opt ext table with Some v -> Some v | None -> None

let choose_icon ~nerd unicode nerd_icon =
  if nerd && nerd_icon <> "" then nerd_icon else unicode

let dir_unicode = "๐Ÿ“"

let dir_nerd = "๏ป" (* nf-fa-folder *)

let parent_unicode = "๐Ÿ“‚"

let parent_nerd = "๏ผ" (* nf-fa-folder_open *)

let plain_unicode = "๐Ÿ“„"

let plain_nerd = "๏€–" (* nf-fa-file_o *)

let icon_for ~name ~is_dir =
  let nerd = nerd_font_enabled () in
  let icon =
    if name = ".." then choose_icon ~nerd parent_unicode parent_nerd
    else if is_dir then choose_icon ~nerd dir_unicode dir_nerd
    else
      let ext = extension_lower name in
      match lookup ext with
      | Some (u, n, _) -> choose_icon ~nerd u n
      | None -> choose_icon ~nerd plain_unicode plain_nerd
  in
  icon ^ " "

let color_for ~name ~is_dir =
  if is_dir then Some 75 (* cyan-ish for directories *)
  else
    let ext = extension_lower name in
    match lookup ext with Some (_, _, c) -> Some c | None -> None

let decorate ~name ~is_dir label =
  let icon = icon_for ~name ~is_dir in
  let colored =
    match color_for ~name ~is_dir with Some c -> W.fg c label | None -> label
  in
  icon ^ colored

let () =
  Miaou_registry.register ~name:"file_icons" ~mli:[%blob "file_icons.mli"] ()