package miaou-driver-sdl

  1. Overview
  2. Docs
Miaou SDL driver

Install

dune-project
 Dependency

Authors

Maintainers

Sources

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

doc/src/miaou-driver-sdl.driver/sdl_font.ml.html

Source file sdl_font.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
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

type config = {
  font_path : string option;
  font_size : int;
  window_title : string;
  fg : Sdl_colors.color;
  bg : Sdl_colors.color;
  gradient : bool;
  scale : float;
  transition : [`None | `Slide | `Fade | `Explode | `Random];
}

let detect_display_scale () =
  match Sys.getenv_opt "MIAOU_SDL_SCALE" with
  | Some v -> (
      try float_of_string v
      with _ ->
        Printf.eprintf "Warning: invalid MIAOU_SDL_SCALE=%s, using 1.0\n%!" v ;
        1.0)
  | None -> 1.0

let default_config =
  let fg = {Sdl_colors.r = 200; g = 200; b = 200; a = 255} in
  let bg = {Sdl_colors.r = 20; g = 20; b = 30; a = 255} in
  let transition =
    match Sys.getenv_opt "MIAOU_SDL_TRANSITION" with
    | Some "slide" -> `Slide
    | Some "fade" -> `Fade
    | Some "explode" -> `Explode
    | Some "random" -> `Random
    | Some "none" | None -> `None
    | Some other ->
        Printf.eprintf
          "Warning: unknown MIAOU_SDL_TRANSITION=%s, using 'none'\n%!"
          other ;
        `None
  in
  {
    font_path = None;
    font_size = 14;
    window_title = "Miaou TUI (SDL)";
    fg;
    bg;
    gradient = true;
    scale = detect_display_scale ();
    transition;
  }

let font_candidates =
  [
    "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf";
    "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf";
    "/Library/Fonts/Menlo-Regular.ttf";
    "/System/Library/Fonts/Menlo.ttc";
    "/usr/share/fonts/TTF/DejaVuSansMono.ttf";
  ]

let pick_font_path (cfg : config) =
  match cfg.font_path with
  | Some p when Sys.file_exists p -> Ok p
  | Some p ->
      Error
        (Printf.sprintf
           "Configured MIAOU_SDL_FONT does not exist: %s (current working \
            directory: %s)"
           p
           (Sys.getcwd ()))
  | None -> (
      match Sys.getenv_opt "MIAOU_SDL_FONT" with
      | Some env when Sys.file_exists env -> Ok env
      | Some env ->
          Error
            (Printf.sprintf
               "Configured MIAOU_SDL_FONT does not exist: %s (cwd: %s)"
               env
               (Sys.getcwd ()))
      | None -> (
          let available = List.filter Sys.file_exists font_candidates in
          match available with
          | p :: _ -> Ok p
          | [] ->
              Error
                (Printf.sprintf
                   "Could not find any monospaced font. Provide \
                    MIAOU_SDL_FONT=<path> to a .ttf file. Probed: %s"
                   (String.concat ", " font_candidates))))