KristofferC/OhMyREPL.jl

Support in custom REPL modes

ronisbr opened this issue · 2 comments

Hi @KristofferC !

I have a package (TerminalPager.jl) that defines a custom REPL mode to show large outputs inside a pager. When I enable OhMyREPL.jl, the highlight only works when I type certain characters. For example, if I type function in normal REPL, it gets highlighted immediately:

Captura de Tela 2023-09-23 às 13 51 38

However, if I enter my custom mode, this does not happen:

Captura de Tela 2023-09-23 às 13 52 47

The only way to make the line highlighted is if I type backspace, enter, or move the cursor using the left/right keys (at least it was what I found):

Captura de Tela 2023-09-23 às 13 53 19

It seems that I need to call some function to refresh the line at each character. Maybe I can add OhMyREPL as extension for TerminalPager.jl, but I just do not know what should I do. Can you help me?

Bump!

I think I solved this problem by adding this keymap:

    # For every typed character, we insert it and update the line. This approach is
    # necessary to make OhMyREPL.jl works in TerminalPager.jl.
    line_update_keymap = Dict{Any, Any}(
        "*" => function(s, data, c)
            LineEdit.edit_insert(s, c)
            LineEdit.refresh_line(s)
        end
    )

    tp_mode_keymaps = Dict{Any, Any}[
        line_update_keymap,
        mk,
        prefix_keymap,
        skeymap,
        help_mode_transition_keymap,
        LineEdit.history_keymap,
        LineEdit.default_keymap,
        LineEdit.escape_defaults,
    ]

    tp_mode.keymap_dict = LineEdit.keymap(tp_mode_keymaps)

But I am not sure if this is the correct approach.