add open with micro
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
@@ -145,6 +146,10 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
_, cmd := m.noteView.Update(loadNote{path: msg.path})
|
_, cmd := m.noteView.Update(loadNote{path: msg.path})
|
||||||
return m, cmd
|
return m, cmd
|
||||||
|
|
||||||
|
case loadNote:
|
||||||
|
_, cmd := m.noteView.Update(msg)
|
||||||
|
return m, cmd
|
||||||
|
|
||||||
case loadedNote:
|
case loadedNote:
|
||||||
// Forward loaded note to noteView
|
// Forward loaded note to noteView
|
||||||
_, cmd := m.noteView.Update(msg)
|
_, cmd := m.noteView.Update(msg)
|
||||||
@@ -215,6 +220,16 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.showStatusBar = !m.showStatusBar
|
m.showStatusBar = !m.showStatusBar
|
||||||
m.layout(m.terminalWidth, m.terminalHeight)
|
m.layout(m.terminalWidth, m.terminalHeight)
|
||||||
return m, m.resizeChildren()
|
return m, m.resizeChildren()
|
||||||
|
case "o":
|
||||||
|
if m.tree != nil && m.tree.selectedNode != nil {
|
||||||
|
c := exec.Command("micro", m.tree.selectedNode.path)
|
||||||
|
c.Stdin = os.Stdin
|
||||||
|
c.Stdout = os.Stdout
|
||||||
|
c.Stderr = os.Stderr
|
||||||
|
return m, tea.ExecProcess(c, func(err error) tea.Msg {
|
||||||
|
return loadNote{path: m.tree.selectedNode.path, force: true}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ type NoteView struct {
|
|||||||
|
|
||||||
// ================== messages ===================
|
// ================== messages ===================
|
||||||
type loadNote struct {
|
type loadNote struct {
|
||||||
path string
|
path string
|
||||||
|
force bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type loadedNote struct {
|
type loadedNote struct {
|
||||||
@@ -157,7 +158,7 @@ func (m *NoteView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
return m, cmd
|
return m, cmd
|
||||||
|
|
||||||
case loadNote:
|
case loadNote:
|
||||||
if m.path == msg.path {
|
if m.path == msg.path && !msg.force {
|
||||||
return m, nil //noop
|
return m, nil //noop
|
||||||
}
|
}
|
||||||
m.path = msg.path
|
m.path = msg.path
|
||||||
|
|||||||
Reference in New Issue
Block a user