add running command indicator

This commit is contained in:
Casual 2024-05-11 04:53:43 +03:00
parent 7f7ae26f4e
commit c293ad0e57
2 changed files with 75 additions and 20 deletions

91
tui.go
View File

@ -10,6 +10,7 @@ import (
// "strings" // "strings"
// "time" // "time"
// "log"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/viewport" "github.com/charmbracelet/bubbles/viewport"
@ -74,11 +75,33 @@ func (m *model) Init() tea.Cmd {
return nil return nil
} }
type continueExec string
var fileUpdatedBool bool
var choiceActionBool bool
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// var ( var (
// // cmd tea.Cmd cmd tea.Cmd
// cmds []tea.Cmd // cmds []tea.Cmd
// ) // continueExec string
)
if fileUpdatedBool {
m.viewport.SetContent(watchRun())
m.viewport.GotoBottom()
fileUpdatedBool = false
}
if choiceActionBool {
i, ok := m.list.SelectedItem().(item)
if ok {
m.viewport.SetContent(choiceAction(string(i)))
m.viewport.GotoBottom()
}
fileUpdatedBool = false
choiceActionBool = false
}
switch msg := msg.(type) { switch msg := msg.(type) {
@ -106,15 +129,18 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// The "enter" key and the spacebar (a literal space) toggle // The "enter" key and the spacebar (a literal space) toggle
// the selected state for the item that the cursor is pointing at. // the selected state for the item that the cursor is pointing at.
case "enter", " ": case "enter", " ":
i, ok := m.list.SelectedItem().(item) skipNextViewportUpdate = true
if ok { m.viewport.SetContent("[Running...]") //TODO not working, probably need do in another update, so need to mkae it set here and return msg
// m.choice = string(i) // continueExecVar = "choiceAction"
skipNextViewportUpdate = true // TUI.Send(func() tea.Msg{return continueExecVar})
m.viewport.SetContent("[Running...]") // continueExecVar = ""
m.viewport.SetContent(choiceAction(string(i))) go TUI.Send(func() tea.Msg { // foroce rerender probably there are better solutions
m.viewport.GotoBottom() // time.Sleep(time.Second / 10)
return ""
})
choiceActionBool = true
return m, nil
}
} }
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
headerHeight := lipgloss.Height(m.headerView()) headerHeight := lipgloss.Height(m.headerView())
@ -154,18 +180,43 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// } // }
case fileUpdated: case fileUpdated:
if !skipNextViewportUpdate { // if !skipNextViewportUpdate { //TODO useless
m.viewport.SetContent("[Running...]") m.viewport.SetContent("[Running...]")
m.viewport.SetContent(watchRun())
m.viewport.GotoBottom() go TUI.Send(func() tea.Msg { //probably there are better solutions
return m, nil // time.Sleep(time.Second / 10)
} return ""
skipNextViewportUpdate = false })
fileUpdatedBool = true
// time.Sleep(time.Second*2)
// continueExecVar = ""
// return m, nil
// }
// skipNextViewportUpdate = false //TODO useless
// case continueExec:
// switch msg{
// case "choiceAction":
// i, ok := m.list.SelectedItem().(item)
// if ok {
// m.viewport.SetContent(choiceAction(string(i)))
// m.viewport.GotoBottom()
// }
// // return m, nil
// case "watchRun":
// // log.Println("tets")
// m.viewport.SetContent(watchRun())
// m.viewport.GotoBottom()
// // return m, nil
//
// }
} }
// Return the updated model to the Bubble Tea runtime for processing. // Return the updated model to the Bubble Tea runtime for processing.
// Note that we're not returning a command. // Note that we're not returning a command.
var cmd tea.Cmd // var cmd tea.Cmd
m.list, cmd = m.list.Update(msg) m.list, cmd = m.list.Update(msg)
return m, cmd return m, cmd
// return m, nil // return m, nil

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"os/exec" "os/exec"
// "os"
"strings" "strings"
"github.com/charmbracelet/bubbles/list" "github.com/charmbracelet/bubbles/list"
@ -108,6 +109,9 @@ func choiceAction(input string) string {
case "git commit": case "git commit":
// TODO add input message box // TODO add input message box
case "git push": case "git push":
// cmd := exec.Command("git","push")
// cmd.Env = os.Environ() // for using ssh keys
// output, err := cmd.CombinedOutput()
output, err := exec.Command("git", "push").CombinedOutput() output, err := exec.Command("git", "push").CombinedOutput()
if err != nil { if err != nil {
return "[ERROR] - executing command failed\n" + string(output) return "[ERROR] - executing command failed\n" + string(output)