ソースを参照

Simplifies deleteConfirm and adds delete to issue viewer

arianagiroux 1 週間 前
コミット
dbdb04761c
1 ファイル変更11 行追加31 行削除
  1. 11 31
      tui.go

+ 11 - 31
tui.go

@@ -48,9 +48,6 @@ var (
 			Margin(1).
 			BorderStyle(lipgloss.NormalBorder())
 
-	indexStyle = lipgloss.NewStyle().
-			Italic(true)
-
 	pointerStyle = lipgloss.NewStyle().
 			Faint(true)
 
@@ -641,6 +638,8 @@ func (i Issue) update(msg tea.Msg) (widget, tea.Cmd) {
 			cmds = append(cmds, i.edit)
 		case "esc":
 			cmds = append(cmds, i.back)
+		case "d":
+			return i, func() tea.Msg { return deletePath(i.Path) }
 		}
 	}
 	return i, tea.Batch(cmds...)
@@ -707,9 +706,9 @@ func (i Issue) keyhelp() string {
 	var escStr string
 	remainder, _ := filepath.Split(i.Path)
 	if IsIssueCollection(remainder) {
-		escStr = "\t\tesc: back"
+		escStr = "esc: back\t\t"
 	}
-	output = output + fmt.Sprintf("e: edit%s\t\tctrl+c: quit", escStr)
+	output = output + fmt.Sprintf("e: edit\t\td: delete\n\n%sctrl+c: quit", escStr)
 	return output
 }
 
@@ -839,13 +838,14 @@ func (w setTitle) render() tea.Msg {
 
 func (w setTitle) keyhelp() string { return "enter: submit" }
 
+// -------- confirmDelete widget definitions ----------------------------------
+// ----------------------------------------------------------------------------
+
 type confirmDelete struct {
 	Path           string
 	input          textinput.Model
 	prompt         string
 	validateString string
-	err            string
-	success        bool
 }
 
 func (w confirmDelete) update(msg tea.Msg) (widget, tea.Cmd) {
@@ -858,11 +858,7 @@ func (w confirmDelete) update(msg tea.Msg) (widget, tea.Cmd) {
 	case tea.KeyMsg:
 		switch msg.String() {
 		case "enter":
-			if w.success {
-				cmds = append(cmds, w.back)
-			} else {
-				cmds = append(cmds, w.validate)
-			}
+			cmds = append(cmds, w.validate)
 		case "esc":
 			cmds = append(cmds, w.back)
 		}
@@ -875,34 +871,18 @@ func (w confirmDelete) update(msg tea.Msg) (widget, tea.Cmd) {
 			cmds = append(cmds, w.back)
 		}
 	case deleteResult:
-		if len(msg) > 0 {
-			w.success = true
-			cmds = append(cmds, w.render)
-		} else {
-			w.err = string(msg)
-		}
+		cmds = append(cmds, w.back)
 	}
 
 	return w, tea.Batch(cmds...)
 }
 
 func (w confirmDelete) render() tea.Msg {
-	if len(w.err) == 0 {
-		if w.success {
-			return fmt.Sprintf("Successfully deleted %s", w.Path)
-		}
-		prompt := fmt.Sprintf("%s (%s)...\n", w.prompt, w.Path)
-		return fmt.Sprintf("%s%s", prompt, w.input.View())
-	}
-
-	// wrap in string so its caught by the content update signal
-	return w.err
+	prompt := fmt.Sprintf("%s (%s)...\n", w.prompt, w.Path)
+	return fmt.Sprintf("%s%s", prompt, w.input.View())
 }
 
 func (w confirmDelete) keyhelp() string {
-	if w.success {
-		return "enter: continue\t\tesc: continue"
-	}
 	return "enter: submit\t\tesc: cancel"
 }