mirror of
https://github.com/taigrr/teaqlite.git
synced 2026-04-02 04:59:03 -07:00
remove q to quit
This commit is contained in:
6
main.go
6
main.go
@@ -498,7 +498,7 @@ func max(a, b int) int {
|
||||
}
|
||||
|
||||
func initialModel(dbPath string) model {
|
||||
db, err := sql.Open("sqlite3", dbPath)
|
||||
db, err := sql.Open("sqlite", dbPath)
|
||||
if err != nil {
|
||||
return model{err: err}
|
||||
}
|
||||
@@ -533,7 +533,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// Add similar updates for other model types as needed
|
||||
|
||||
case tea.KeyMsg:
|
||||
if msg.String() == "ctrl+c" || msg.String() == "q" {
|
||||
if msg.String() == "ctrl+c" {
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m model) View() string {
|
||||
if m.err != nil {
|
||||
return errorStyle.Render(fmt.Sprintf("Error: %v\n\nPress 'q' to quit", m.err))
|
||||
return errorStyle.Render(fmt.Sprintf("Error: %v\n\nPress 'ctrl+c' to quit", m.err))
|
||||
}
|
||||
return m.currentView.View()
|
||||
}
|
||||
|
||||
19
query.go
19
query.go
@@ -17,6 +17,7 @@ type queryModel struct {
|
||||
columns []string
|
||||
focusOnInput bool // true = input focused, false = results focused
|
||||
selectedRow int
|
||||
errorMsg string // Error message to display
|
||||
}
|
||||
|
||||
func newQueryModel(shared *sharedData) *queryModel {
|
||||
@@ -42,6 +43,11 @@ func (m *queryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
func (m *queryModel) handleInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
// Clear error message if present, otherwise go back
|
||||
if m.errorMsg != "" {
|
||||
m.errorMsg = ""
|
||||
return m, nil
|
||||
}
|
||||
return m, func() tea.Msg { return switchToTableListMsg{} }
|
||||
|
||||
case "tab":
|
||||
@@ -59,7 +65,9 @@ func (m *queryModel) handleInput(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if m.focusOnInput {
|
||||
// Execute query when input is focused
|
||||
if err := m.executeQuery(); err != nil {
|
||||
// TODO: Handle error - could set an error field
|
||||
m.errorMsg = err.Error()
|
||||
} else {
|
||||
m.errorMsg = "" // Clear error on successful query
|
||||
}
|
||||
} else {
|
||||
// View row detail when results are focused
|
||||
@@ -281,6 +289,15 @@ func (m *queryModel) View() string {
|
||||
content.WriteString(titleStyle.Render("SQL Query"))
|
||||
content.WriteString("\n\n")
|
||||
|
||||
// Display error modal if there's an error
|
||||
if m.errorMsg != "" {
|
||||
errorBox := errorStyle.Render(fmt.Sprintf("Error: %s", m.errorMsg))
|
||||
content.WriteString(errorBox)
|
||||
content.WriteString("\n\n")
|
||||
content.WriteString(helpStyle.Render("esc: dismiss error"))
|
||||
return content.String()
|
||||
}
|
||||
|
||||
// Display query with cursor and focus indicator
|
||||
if m.focusOnInput {
|
||||
content.WriteString("Query: ")
|
||||
|
||||
@@ -166,8 +166,7 @@ func (m *rowDetailModel) View() string {
|
||||
}
|
||||
|
||||
content.WriteString("\n")
|
||||
content.WriteString(helpStyle.Render("↑/↓: select field • enter: edit • esc: back • q: quit"))
|
||||
content.WriteString(helpStyle.Render("↑/↓: select field • enter: edit • esc: back • ctrl+c: quit"))
|
||||
|
||||
return content.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -221,9 +221,8 @@ func (m *tableDataModel) View() string {
|
||||
if m.searching {
|
||||
content.WriteString(helpStyle.Render("Type to search • enter/esc: finish search"))
|
||||
} else {
|
||||
content.WriteString(helpStyle.Render("↑/↓: select row • ←/→: page • /: search • enter: view row • esc: back • r: refresh • q: quit"))
|
||||
content.WriteString(helpStyle.Render("↑/↓: select row • ←/→: page • /: search • enter: view row • esc: back • r: refresh • ctrl+c: quit"))
|
||||
}
|
||||
|
||||
return content.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ func (m *tableListModel) View() string {
|
||||
if m.searching {
|
||||
content.WriteString(helpStyle.Render("Type to search • enter/esc: finish search"))
|
||||
} else {
|
||||
content.WriteString(helpStyle.Render("↑/↓: navigate • ←/→: page • /: search • enter: view • s: SQL • r: refresh • q: quit"))
|
||||
content.WriteString(helpStyle.Render("↑/↓: navigate • ←/→: page • /: search • enter: view • s: SQL • r: refresh • ctrl+c: quit"))
|
||||
}
|
||||
|
||||
return content.String()
|
||||
|
||||
Reference in New Issue
Block a user