Skip to content

Commit 5a25653

Browse files
committed
feat(editor): add title; move banner back to top
1 parent 05f43e5 commit 5a25653

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

cmd/pago/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ func (cmd *EditCmd) Run(config *Config) error {
599599
return fmt.Errorf("entry doesn't exist: %v", name)
600600
}
601601

602-
newContent, err := editor.Edit(content, cmd.Save)
602+
newContent, err := editor.Edit(name, content, cmd.Save)
603603
if err != nil && !errors.Is(err, editor.CancelError) {
604604
return fmt.Errorf("editor failed: %v", err)
605605
}

editor/editor.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type editor struct {
1919
err error
2020
save bool
2121
textarea textarea.Model
22+
title string
2223
}
2324

2425
type cancelError struct{}
@@ -61,7 +62,7 @@ func (e editor) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6162

6263
case tea.WindowSizeMsg:
6364
e.textarea.SetWidth(msg.Width)
64-
e.textarea.SetHeight(msg.Height - 3) // Negative height works.
65+
e.textarea.SetHeight(msg.Height - 2) // Negative height works.
6566
}
6667

6768
e.textarea, cmd = e.textarea.Update(msg)
@@ -74,11 +75,11 @@ func (e editor) View() string {
7475
banner = bannerSave
7576
}
7677

77-
return fmt.Sprintf("\n%s\n\n%s", e.textarea.View(), banner)
78+
return fmt.Sprintf("%q %s\n\n%s", e.title, banner, e.textarea.View())
7879
}
7980

80-
// Edit presents an editor with the given initial content and returns the edited text.
81-
func Edit(initial string, save bool) (string, error) {
81+
// Edit presents an editor with a given title and initial content and returns the edited text.
82+
func Edit(title, initial string, save bool) (string, error) {
8283
if len(initial) > editorCharLimit {
8384
return "", fmt.Errorf("initial text too long")
8485
}
@@ -99,6 +100,7 @@ func Edit(initial string, save bool) (string, error) {
99100

100101
e := editor{
101102
save: save,
103+
title: title,
102104
textarea: ta,
103105
}
104106

0 commit comments

Comments
 (0)