Skip to content

Commit 1d6f46e

Browse files
committed
Switched editor to tea.Cmd implementation
1 parent 14b6e1e commit 1d6f46e

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

internal/editor/editor.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,19 @@ package editor
33
import (
44
"os/exec"
55

6+
tea "github.com/charmbracelet/bubbletea"
67
"github.com/muesli/coral"
78
)
89

9-
var defaultEditor = "vim"
10-
1110
var (
12-
name string
11+
program = "vim"
1312
)
1413

1514
// Opens the current slide as a split window in tmux.
16-
func OpenNewWindow(fileName string) error {
17-
var cmd *exec.Cmd
18-
19-
switch name {
20-
case "vim", "nvim":
21-
cmd = exec.Command("tmux", "split-window", "-h", name, fileName)
22-
case "code":
23-
cmd = exec.Command(name, fileName)
24-
}
25-
26-
return cmd.Start()
15+
func OpenNewWindow(fileName string) tea.Cmd {
16+
return tea.ExecProcess(exec.Command(program, fileName), nil)
2717
}
2818

2919
func InitEditorFlag(rootCmd *coral.Command) {
30-
rootCmd.PersistentFlags().StringVarP(&name, "editor", "e", defaultEditor, "Specify the editor to use")
20+
rootCmd.PersistentFlags().StringVarP(&program, "editor", "e", program, "Specify the editor to use")
3121
}

internal/model/model.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
180180
return m, tea.Quit
181181
case "ctrl+o":
182182
// Opens the current slide in an editor
183-
err := editor.OpenNewWindow(m.FileName)
184-
if err != nil {
185-
return m, nil
186-
}
183+
return m, editor.OpenNewWindow(m.FileName)
187184
default:
188185
newState := navigation.Navigate(navigation.State{
189186
Buffer: m.buffer,

0 commit comments

Comments
 (0)