Skip to content

Commit

Permalink
Switched editor to tea.Cmd implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
waelmahrous committed Oct 31, 2024
1 parent 14b6e1e commit 1d6f46e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
20 changes: 5 additions & 15 deletions internal/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@ package editor
import (
"os/exec"

tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/coral"
)

var defaultEditor = "vim"

var (
name string
program = "vim"
)

// Opens the current slide as a split window in tmux.
func OpenNewWindow(fileName string) error {
var cmd *exec.Cmd

switch name {
case "vim", "nvim":
cmd = exec.Command("tmux", "split-window", "-h", name, fileName)
case "code":
cmd = exec.Command(name, fileName)
}

return cmd.Start()
func OpenNewWindow(fileName string) tea.Cmd {
return tea.ExecProcess(exec.Command(program, fileName), nil)
}

func InitEditorFlag(rootCmd *coral.Command) {
rootCmd.PersistentFlags().StringVarP(&name, "editor", "e", defaultEditor, "Specify the editor to use")
rootCmd.PersistentFlags().StringVarP(&program, "editor", "e", program, "Specify the editor to use")
}
5 changes: 1 addition & 4 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Quit
case "ctrl+o":
// Opens the current slide in an editor
err := editor.OpenNewWindow(m.FileName)
if err != nil {
return m, nil
}
return m, editor.OpenNewWindow(m.FileName)
default:
newState := navigation.Navigate(navigation.State{
Buffer: m.buffer,
Expand Down

0 comments on commit 1d6f46e

Please sign in to comment.