Fix: various bug fix
This commit is contained in:
@@ -1,23 +1,52 @@
|
||||
package stages
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"gitea.konchin.com/ytshih/inp2025/types"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
queue *[]*tea.Program
|
||||
stack []types.Program
|
||||
client *resty.Client
|
||||
|
||||
// after login
|
||||
loginCount int
|
||||
}
|
||||
|
||||
func NewBaseModel(
|
||||
queue *[]*tea.Program,
|
||||
endpoint string,
|
||||
) *BaseModel {
|
||||
return &BaseModel{
|
||||
queue: queue,
|
||||
stack: []types.Program{},
|
||||
client: resty.New().
|
||||
SetBaseURL(endpoint).
|
||||
SetDisableWarn(true),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *BaseModel) Size() int {
|
||||
return len(m.stack)
|
||||
}
|
||||
|
||||
func (m *BaseModel) Pop() types.Program {
|
||||
stack := m.stack[:]
|
||||
var ret types.Program
|
||||
ret, stack = stack[len(stack)-1], stack[:len(stack)-1]
|
||||
m.stack = stack
|
||||
return ret
|
||||
}
|
||||
|
||||
func (m *BaseModel) Push(program types.Program) error {
|
||||
stack := m.stack[:]
|
||||
for len(stack) > 0 && stack[len(stack)-1].Stage > program.Stage {
|
||||
var p types.Program
|
||||
p, stack = stack[len(stack)-1], stack[:len(stack)-1]
|
||||
|
||||
if err := p.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
stack = append(stack, program)
|
||||
m.stack = stack
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user