use cobra/fang

This commit is contained in:
2025-07-12 22:40:08 -07:00
parent f2358a1ab5
commit 686cb97eb3
15 changed files with 1427 additions and 1736 deletions

91
internal/app/edit_cell.go Normal file
View File

@@ -0,0 +1,91 @@
package app
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
)
// Edit Cell Model
type EditCellModel struct {
Shared *SharedData
rowIndex int
colIndex int
value string
cursor int
}
func NewEditCellModel(shared *SharedData, rowIndex, colIndex int) *EditCellModel {
value := ""
if rowIndex < len(shared.FilteredData) && colIndex < len(shared.FilteredData[rowIndex]) {
value = shared.FilteredData[rowIndex][colIndex]
}
return &EditCellModel{
Shared: shared,
rowIndex: rowIndex,
colIndex: colIndex,
value: value,
cursor: len(value),
}
}
func (m *EditCellModel) Init() tea.Cmd {
return nil
}
func (m *EditCellModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "esc":
return m, func() tea.Msg { return SwitchToRowDetailMsg{RowIndex: m.rowIndex} }
case "enter":
return m, func() tea.Msg {
return UpdateCellMsg{
RowIndex: m.rowIndex,
ColIndex: m.colIndex,
Value: m.value,
}
}
case "backspace":
if m.cursor > 0 {
m.value = m.value[:m.cursor-1] + m.value[m.cursor:]
m.cursor--
}
case "left":
if m.cursor > 0 {
m.cursor--
}
case "right":
if m.cursor < len(m.value) {
m.cursor++
}
default:
if len(msg.String()) == 1 {
m.value = m.value[:m.cursor] + msg.String() + m.value[m.cursor:]
m.cursor++
}
}
}
return m, nil
}
func (m *EditCellModel) View() string {
columnName := ""
if m.colIndex < len(m.Shared.Columns) {
columnName = m.Shared.Columns[m.colIndex]
}
content := TitleStyle.Render(fmt.Sprintf("Edit Cell: %s", columnName)) + "\n\n"
content += fmt.Sprintf("Value: %s\n", m.value)
content += fmt.Sprintf("Cursor: %d\n\n", m.cursor)
content += HelpStyle.Render("enter: save • esc: cancel")
return content
}