Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion internal/app/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case tea.KeyMsg:
switch msg.String() {

case "enter":
if m.executing {
return m, nil
}
if sqlTerminationChecker(m.input.Value()) {
return m, editline.InputComplete
}

var cmd tea.Cmd
m.input, cmd = m.input.Update(msg)
return m, cmd

case "ctrl+c":
m.input.Reset()
if m.executing {
Expand All @@ -117,7 +130,6 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil
}
}

return m, nil
}
}
Expand Down Expand Up @@ -302,6 +314,17 @@ func applyEditlineConfig(el *editline.Model, historyFile string, pgKeywords []st
return nil
}

func sqlTerminationChecker(s string) bool {
trimmed := strings.TrimSpace(s)
if trimmed == "" {
return true
}
if strings.HasPrefix(trimmed, "\\") {
return true
}
return strings.HasSuffix(trimmed, ";")
}
Comment on lines +317 to +326
Comment on lines +317 to +326

func getHistoryFilePath() string {
homeDir, err := os.UserHomeDir()
if err != nil {
Expand Down
Loading