feat: upgrade bubbletea to v2
SonarQube Scan / SonarQube Trigger (push) Failing after 2m16s

This commit is contained in:
2026-03-20 18:06:08 +07:00
parent 9dc3711875
commit 93d4fb48e7
9 changed files with 90 additions and 86 deletions
+4 -4
View File
@@ -3,14 +3,14 @@ package interaction
import (
"strings"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/lipgloss"
)
func (m *model) comingSoonUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
func (m *model) comingSoonUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
_ = msg
m.showingComingSoon = false
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
}
func (m *model) comingSoonView() string {
+7 -10
View File
@@ -4,9 +4,8 @@ import (
"strings"
"time"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
@@ -17,24 +16,22 @@ func (m *model) handleCommandSelection(item commandItem) (tea.Model, tea.Cmd) {
m.editingSlug = true
m.slugInput.SetValue(m.interaction.slug.String())
m.slugInput.Focus()
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
case "tunnel-type":
m.showingCommands = false
m.showingComingSoon = true
return m, tea.Batch(tickCmd(5*time.Second), tea.ClearScreen, textinput.Blink)
return m, tickCmd(5 * time.Second)
default:
m.showingCommands = false
return m, nil
}
}
func (m *model) commandsUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
func (m *model) commandsUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, m.keymap.quit), msg.String() == "esc":
m.showingCommands = false
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
case msg.String() == "enter":
selectedItem := m.commandList.SelectedItem()
if selectedItem != nil {
@@ -42,8 +39,8 @@ func (m *model) commandsUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
return m.handleCommandSelection(item)
}
}
m.commandList, cmd = m.commandList.Update(msg)
return m, cmd
m.commandList, _ = m.commandList.Update(msg)
return m, nil
}
func (m *model) commandsView() string {
+4 -5
View File
@@ -4,20 +4,19 @@ import (
"fmt"
"strings"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
func (m *model) dashboardUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
func (m *model) dashboardUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, m.keymap.quit):
m.quitting = true
return m, tea.Batch(tea.ClearScreen, textinput.Blink, tea.Quit)
return m, tea.Quit
case key.Matches(msg, m.keymap.command):
m.showingCommands = true
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
}
return m, nil
}
+20 -22
View File
@@ -9,11 +9,11 @@ import (
"tunnel_pls/session/slug"
"tunnel_pls/types"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh"
@@ -120,7 +120,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tickMsg:
m.showingComingSoon = false
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
case tea.WindowSizeMsg:
m.width = msg.Width
@@ -137,9 +137,9 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.QuitMsg:
m.quitting = true
return m, tea.Batch(tea.ClearScreen, textinput.Blink, tea.Quit)
return m, tea.Quit
case tea.KeyMsg:
case tea.KeyPressMsg:
if m.showingComingSoon {
return m.comingSoonUpdate(msg)
}
@@ -160,28 +160,28 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (i *interaction) Redraw() {
if i.program != nil {
i.program.Send(tea.ClearScreen())
i.program.Send(tea.WindowSizeMsg{})
}
}
func (m *model) View() string {
func (m *model) View() tea.View {
var content string
if m.quitting {
return ""
content = ""
} else if m.showingComingSoon {
content = m.comingSoonView()
} else if m.editingSlug {
content = m.slugView()
} else if m.showingCommands {
content = m.commandsView()
} else {
content = m.dashboardView()
}
if m.showingComingSoon {
return m.comingSoonView()
}
if m.editingSlug {
return m.slugView()
}
if m.showingCommands {
return m.commandsView()
}
return m.dashboardView()
v := tea.NewView(content)
v.AltScreen = true
v.MouseMode = tea.MouseModeCellMotion
return v
}
func (i *interaction) Start() {
@@ -249,8 +249,6 @@ func (i *interaction) Start() {
m,
tea.WithInput(i.channel),
tea.WithOutput(i.channel),
tea.WithAltScreen(),
tea.WithMouseCellMotion(),
tea.WithoutSignals(),
tea.WithoutSignalHandler(),
tea.WithFPS(30),
+30 -30
View File
@@ -9,10 +9,10 @@ import (
"time"
"tunnel_pls/types"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"golang.org/x/crypto/ssh"
@@ -694,7 +694,7 @@ func TestInteraction_Integration(t *testing.T) {
func TestModel_Update_KeyMessages(t *testing.T) {
tests := []struct {
name string
key tea.KeyMsg
key tea.KeyPressMsg
showingComingSoon bool
editingSlug bool
showingCommands bool
@@ -702,25 +702,25 @@ func TestModel_Update_KeyMessages(t *testing.T) {
}{
{
name: "key press while showing coming soon",
key: tea.KeyMsg{Type: tea.KeyEnter},
key: tea.KeyPressMsg{Code: tea.KeyEnter},
showingComingSoon: true,
description: "should call comingSoonUpdate",
},
{
name: "key press while editing slug",
key: tea.KeyMsg{Type: tea.KeyEnter},
key: tea.KeyPressMsg{Code: tea.KeyEnter},
editingSlug: true,
description: "should call slugUpdate",
},
{
name: "key press while showing commands",
key: tea.KeyMsg{Type: tea.KeyEnter},
key: tea.KeyPressMsg{Code: tea.KeyEnter},
showingCommands: true,
description: "should call commandsUpdate",
},
{
name: "key press in dashboard view",
key: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}},
key: tea.KeyPressMsg{Code: 'c', Text: "c"},
description: "should call dashboardUpdate",
},
}
@@ -777,7 +777,7 @@ func TestModel_SlugUpdate(t *testing.T) {
tests := []struct {
name string
tunnelType types.TunnelType
keyMsg tea.KeyMsg
keyMsg tea.KeyPressMsg
inputValue string
setupMocks func(*MockSessionRegistry, *MockSlug, *MockRandom)
expectedEdit bool
@@ -787,21 +787,21 @@ func TestModel_SlugUpdate(t *testing.T) {
{
name: "escape key cancels editing",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
expectedEdit: false,
},
{
name: "ctrl+c cancels editing",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlC},
keyMsg: tea.KeyPressMsg{Code: 'c', Mod: tea.ModCtrl},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
expectedEdit: false,
},
{
name: "enter key saves valid slug",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
inputValue: "my-custom-slug",
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
ms.On("String").Return("old-slug")
@@ -816,7 +816,7 @@ func TestModel_SlugUpdate(t *testing.T) {
{
name: "enter key with error shows error message",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
inputValue: "invalid",
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
ms.On("String").Return("old-slug")
@@ -831,7 +831,7 @@ func TestModel_SlugUpdate(t *testing.T) {
{
name: "ctrl+r generates random slug",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlR},
keyMsg: tea.KeyPressMsg{Code: 'r', Mod: tea.ModCtrl},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
mr.On("String", 20).Return("random-generated-slug", nil)
},
@@ -841,7 +841,7 @@ func TestModel_SlugUpdate(t *testing.T) {
{
name: "ctrl+r with error does nothing",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlR},
keyMsg: tea.KeyPressMsg{Code: 'r', Mod: tea.ModCtrl},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {
mr.On("String", 20).Return("", assert.AnError)
},
@@ -850,14 +850,14 @@ func TestModel_SlugUpdate(t *testing.T) {
{
name: "regular key updates input",
tunnelType: types.TunnelTypeHTTP,
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'a'}},
keyMsg: tea.KeyPressMsg{Code: 'a', Text: "a"},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
expectedEdit: true,
},
{
name: "tcp tunnel exits editing immediately",
tunnelType: types.TunnelTypeTCP,
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'a'}},
keyMsg: tea.KeyPressMsg{Code: 'a', Text: "a"},
setupMocks: func(msr *MockSessionRegistry, ms *MockSlug, mr *MockRandom) {},
expectedEdit: false,
},
@@ -1006,19 +1006,19 @@ func TestModel_SlugView(t *testing.T) {
func TestModel_ComingSoonUpdate(t *testing.T) {
tests := []struct {
name string
keyMsg tea.KeyMsg
keyMsg tea.KeyPressMsg
}{
{
name: "any key dismisses coming soon",
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
},
{
name: "escape key dismisses",
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
},
{
name: "space key dismisses",
keyMsg: tea.KeyMsg{Type: tea.KeySpace},
keyMsg: tea.KeyPressMsg{Code: ' ', Text: " "},
},
}
@@ -1097,7 +1097,7 @@ func TestModel_ComingSoonView(t *testing.T) {
func TestModel_CommandsUpdate(t *testing.T) {
tests := []struct {
name string
keyMsg tea.KeyMsg
keyMsg tea.KeyPressMsg
selectedItem list.Item
expectCommands bool
expectEditSlug bool
@@ -1105,31 +1105,31 @@ func TestModel_CommandsUpdate(t *testing.T) {
}{
{
name: "escape key closes commands",
keyMsg: tea.KeyMsg{Type: tea.KeyEsc},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEsc},
expectCommands: false,
},
{
name: "q key closes commands",
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}},
keyMsg: tea.KeyPressMsg{Code: 'q', Text: "q"},
expectCommands: false,
},
{
name: "enter on slug command starts editing",
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
selectedItem: commandItem{name: "slug", desc: "Set custom subdomain"},
expectCommands: false,
expectEditSlug: true,
},
{
name: "enter on tunnel-type shows coming soon",
keyMsg: tea.KeyMsg{Type: tea.KeyEnter},
keyMsg: tea.KeyPressMsg{Code: tea.KeyEnter},
selectedItem: commandItem{name: "tunnel-type", desc: "Change tunnel type"},
expectCommands: false,
expectComingSoon: true,
},
{
name: "arrow key navigates list",
keyMsg: tea.KeyMsg{Type: tea.KeyDown},
keyMsg: tea.KeyPressMsg{Code: tea.KeyDown},
expectCommands: true,
},
}
@@ -1261,28 +1261,28 @@ func TestModel_CommandsView(t *testing.T) {
func TestModel_DashboardUpdate(t *testing.T) {
tests := []struct {
name string
keyMsg tea.KeyMsg
keyMsg tea.KeyPressMsg
expectQuit bool
expectCommands bool
}{
{
name: "q key quits",
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'q'}},
keyMsg: tea.KeyPressMsg{Code: 'q', Text: "q"},
expectQuit: true,
},
{
name: "ctrl+c quits",
keyMsg: tea.KeyMsg{Type: tea.KeyCtrlC},
keyMsg: tea.KeyPressMsg{Code: 'c', Mod: tea.ModCtrl},
expectQuit: true,
},
{
name: "c key opens commands",
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'c'}},
keyMsg: tea.KeyPressMsg{Code: 'c', Text: "c"},
expectCommands: true,
},
{
name: "other keys do nothing",
keyMsg: tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'x'}},
keyMsg: tea.KeyPressMsg{Code: 'x', Text: "x"},
},
}
+2 -2
View File
@@ -6,11 +6,11 @@ import (
"tunnel_pls/internal/random"
"tunnel_pls/types"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
type commandItem struct {
@@ -77,7 +77,7 @@ type keymap struct {
type tickMsg time.Time
func (m *model) Init() tea.Cmd {
return tea.Batch(textinput.Blink, tea.WindowSize())
return tea.RequestWindowSize
}
func getResponsiveWidth(screenWidth, padding, minWidth, maxWidth int) int {
+8 -10
View File
@@ -5,26 +5,24 @@ import (
"strings"
"tunnel_pls/types"
tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
func (m *model) slugUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
func (m *model) slugUpdate(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
if m.tunnelType != types.TunnelTypeHTTP {
m.editingSlug = false
m.slugError = ""
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
}
switch msg.String() {
case "esc", "ctrl+c":
m.editingSlug = false
m.slugError = ""
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
case "enter":
inputValue := m.slugInput.Value()
if err := m.interaction.sessionRegistry.Update(m.interaction.user, types.SessionKey{
@@ -39,18 +37,18 @@ func (m *model) slugUpdate(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
}
m.editingSlug = false
m.slugError = ""
return m, tea.Batch(tea.ClearScreen, textinput.Blink)
return m, nil
default:
if key.Matches(msg, m.keymap.random) {
newSubdomain, err := m.randomizer.String(20)
if err != nil {
return m, cmd
return m, nil
}
m.slugInput.SetValue(newSubdomain)
}
m.slugError = ""
m.slugInput, cmd = m.slugInput.Update(msg)
return m, cmd
m.slugInput, _ = m.slugInput.Update(msg)
return m, nil
}
}