[m-rev.] for review: Add web browser-based term browsing in the debugger.

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Aug 17 07:02:22 AEST 2017


> +save_and_browse_browser_term_web(Term, OutStream, ErrStream, State, !IO) :-
> +    get_mdb_dir(MaybeMdbDir, !IO),
> +    (
> +        MaybeMdbDir = yes(MdbDir),
> +        MaybeBrowserCmd = State ^ web_browser_cmd,
> +        (
> +            MaybeBrowserCmd = yes(BrowserCmd),
> +            io.get_temp_directory(TmpDir, !IO),
> +            io.make_temp_file(TmpDir, "mdb", ".html", TmpResult, !IO),
> +            (
> +                TmpResult = ok(TmpFileName0),
> +                ( if string.suffix(TmpFileName0, ".html") then
> +                    TmpFileName = TmpFileName0
> +                else
> +                    % Work around io.make_temp_file ignoring suffix.
> +                    io.remove_file(TmpFileName, _, !IO),
> +                    TmpFileName = TmpFileName0 ++ ".html"
> +                ),
> 

The two paths in the last if-then-else differ in whether they leave
around a file named TmpFileName. Is that OK?

> +            MaybeBrowserCmd = no,
> +            io.write_string(ErrStream, "mdb: You need to issue a " ++
> +                "\"web_browser_cmd '<command>'\" command first.\n", !IO)

I would reword that as “mdb: You first need to specify the shell command that
launches your preferred browser, by issuing an mdb command such as web_browser_cmd
firefox” (with appropriate quoting).

> +browser_term_to_html_flat_string(BrowserTerm, Str, Elided, !IO) :-
> +    % Mimic portray_flat. We can afford larger sizes in a web browser due to
> +    % proportional fonts and horizontal scrolling.
> +    MaxTermSize = 120,
> +    browser_term_size_left_from_max(BrowserTerm, MaxTermSize, RemainingSize),
> +    ( if RemainingSize >= 0 then
> +        portray_flat_write_browser_term(string.builder.handle, BrowserTerm,
> +            string.builder.init, State),
> +        Str = to_string(State),
> +        Elided = no
> +    else
> +        io.get_stream_db(StreamDb, !IO),
> +        BrowserDb = browser_db(StreamDb),
> +        MaxSize = 10,
> +        MaxDepth = 5,
> +        browser_term_to_string(BrowserDb, BrowserTerm, MaxSize, MaxDepth, Str),
> +        Elided = yes
> +    ).
> 

These seem awfully small limits for a browseable term. Printing small terms
can be done perfectly well already; I, personally, would want to launch a browser
only on terms too big to look at with the existing tools.

> 
> +% Helpers for writing out JavaScript values within an HTML <script> element.
> +% We do not generate indented output because we may need to write large,
> +% deeply nested terms quickly, and have the web browser parse the file as
> +% quickly as possible.
> 

“and WE WANT the web browser TO parse …”

Zoltan.


More information about the reviews mailing list