gobubbletea

F-Keys in Windows don't result in update in bubbletea


While used to C# /.Net, I am quite new to go and bubbletea and I am trying to do a little cli helper for my private amusement.

Now, what I am trying to do is bind F2 Key to an update action in bubbletea.

So I am using bubbletea and bubbles/keys and in my model I have a status string that gets displayed when it is not nil. This works on keys like "a", "b", ... and also up/down/pgdown etc.

But this:

package main

import (
    tea "github.com/charmbracelet/bubbletea"
)

type model struct {
    status string
}

func (m model) Init() tea.Cmd { return nil }

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
    switch msg := msg.(type) {
    case tea.KeyMsg:
        m.status = "'" + msg.String() + "'"
        switch msg.String() {
        case "q":
            m.status = "Bye!"
            return m, tea.Quit
        }
    }
    return m, nil
}

func (m model) View() string {
    return m.status
}

func main() {
    if _, err := tea.NewProgram(model{}).Run(); err != nil {
        panic(err)
    }
}

will output just '' when run on a Windows 10 cmd.exe when I hit any of the F-Keys (F1, F2, ...).

What am I missing?

Edits:

As suggested in comment, opened Issue : https://github.com/charmbracelet/bubbletea/issues/1404


Solution

  • As suggested by @kostix, it was indeed a bug.

    As stated in the fix merge request, they ignored Function Keys on Windows starting from when they switched APIs.

    It is filed as issue #1404 and currently being fixed. Expecting to see expected output in bubbletea versions higher than 1.3.4

    Will update, as soon as I can confirm.

    [EDIT]

    I was able to test it today and in bubbletea v1.3.5 this issue is fixed.