Skip to content

Exception raised by List.init if the terminal is not wide enough #31

@heathhenley

Description

@heathhenley

If the terminal window is too narrow, the List.init will raise, here's the traceback:

gh-tui: internal error, uncaught exception:
       Invalid_argument("List.init")
       Raised at Stdlib.invalid_arg in file "stdlib.ml", line 30, characters 20-45
       Called from Extra__String_extra.repeat_txt in file "lib/extra/string_extra.ml", line 9, characters 21-49
       Called from Pretty__Doc.horizontal_to_layout.(fun) in file "lib/pretty/doc.ml", line 54, characters 11-55
       Called from Stdlib__List.map in file "list.ml", line 87, characters 15-19
       Called from Pretty__Doc.horizontal_to_layout in file "lib/pretty/doc.ml", lines 49-54, characters 2-70
       Called from Stdlib__List.map in file "list.ml", line 87, characters 15-19
       Called from Stdlib__List.map in file "list.ml", line 88, characters 14-21
       Called from Pretty__Doc.render in file "lib/pretty/doc.ml", line 25, characters 21-53
       Called from Pretty.render in file "lib/pretty/pretty.ml", line 6, characters 2-26
       Called from Tea.run.loop in file "lib/tui/tea/tea.ml", line 63, characters 20-34
       Called from Stdlib__Fun.protect in file "fun.ml", line 34, characters 8-15
       Re-raised at Stdlib__Fun.protect in file "fun.ml", line 39, characters 6-52
       Called from Cmdliner_term.app.(fun) in file "cmdliner_term.ml", line 24, characters 19-24
       Called from Cmdliner_eval.run_parser in file "cmdliner_eval.ml", line 35, characters 37-44

I logged the n to a file to debug it is sometimes negative depending on the selected file when the terminal is too skinny. When there isn't enough horizontal space for the files it breaks the layout anyway - maybe that should be detected instead and we could show a more informative error?

For example using this repo it will crash on the .gitignore or LICENSE when the size is 99w x 55h on wsl2 - but ~135w x 55h is ok.

Guarding the List.init with a max 0 n stops the raise but of course the layout is wonky.

I wonder if we need to calculate the space available between the nav and the about box width to make it display ok in those situations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: UIIssues related to changing UIpriority: lowIssues with low priority. Most like will never be done.type: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions