Commit f83b1bc9 authored by liming6's avatar liming6
Browse files

fix 修复主界面按esc恢复慢的问题

parent 7b273277
# Todo
待办清单:
解决非root用户执行出错的问题
优化抓取数据逻辑,避免卡顿
- 减少无效数据的收集
- 多goroutine收集数据,收集数据的goroutine不阻塞tui相关goroutine的运行
- 优化数据结构,降低时间复杂度
......@@ -92,8 +92,8 @@ func (m *ModelDCUInfo) View() string {
strBuilder := strings.Builder{}
strCache := strings.Builder{}
var targetDCU int = -1
if m.actionMsg != nil && m.actionMsg.TargetDCUIndex != nil {
targetDCU = *m.actionMsg.TargetDCUIndex
if m.actionMsg != nil {
targetDCU = m.actionMsg.TargetDCUIndex
}
var borderStr string = myBorder.Left
if m.darkModule {
......
......@@ -104,7 +104,7 @@ type ActionMsg struct {
PointPid *int32 // 指针指向的pid,为null表示没有选择进程,在主视图和进程树视图起作用
PidEnvView *int32 // 进程环境变量视图的pid号,为null表示不进入进程环境变量视图
PidTreePids []int32 // pid tree视图下,进程id的顺序列表
TargetDCUIndex *int // PointPid使用的dcu index
TargetDCUIndex int // PointPid使用的dcu index,为-1表示没有选择任何dcu
}
// ModelMain tui主模型类
......@@ -468,9 +468,9 @@ func (m *ModelMain) handleKeyEsc() tea.Cmd {
m.actionMsg.Action = nil
} else if m.actionMsg.SelectPids != nil {
m.actionMsg.SelectPids = nil
} else if m.actionMsg.PointPid != nil || m.actionMsg.TargetDCUIndex != nil {
} else if m.actionMsg.PointPid != nil {
m.actionMsg.PointPid = nil
m.actionMsg.TargetDCUIndex = nil
m.actionMsg.TargetDCUIndex = -1
}
header, _ := m.Header.Update(m.actionMsg)
dcuInfo, _ := m.DCUInfo.Update(m.actionMsg)
......@@ -650,8 +650,7 @@ func (m *ModelMain) handleKeyUp() tea.Cmd {
}
pid := processes[index].Info.Pid
m.actionMsg.PointPid = &pid
idx := processes[index].DCU
m.actionMsg.TargetDCUIndex = &idx
m.actionMsg.TargetDCUIndex = processes[index].DCU
m1, cmd1 := m.ProcessInfo.Update(m.actionMsg)
m2, cmd2 := m.DCUInfo.Update(m.actionMsg)
m3, cmd3 := m.SysLoad.Update(m.actionMsg)
......@@ -738,8 +737,7 @@ func (m *ModelMain) handleKeyDown() tea.Cmd {
}
pid := processes[index].Info.Pid
m.actionMsg.PointPid = &pid
idx := processes[index].DCU
m.actionMsg.TargetDCUIndex = &idx
m.actionMsg.TargetDCUIndex = processes[index].DCU
m1, cmd1 := m.ProcessInfo.Update(m.actionMsg)
m2, cmd2 := m.DCUInfo.Update(m.actionMsg)
m3, cmd3 := m.SysLoad.Update(m.actionMsg)
......
......@@ -171,10 +171,10 @@ func (m *ModelSysLoad) Update(inputMsg tea.Msg) (tea.Model, tea.Cmd) {
// handleAction 处理ActionMsg
func (m *ModelSysLoad) handleAction() {
if m.actionMsg == nil || m.actionMsg.TargetDCUIndex == nil || m.actionMsg.VM != VMMain {
if m.actionMsg == nil || m.actionMsg.VM != VMMain {
return
}
targetIndex := int32(*m.actionMsg.TargetDCUIndex)
targetIndex := int32(m.actionMsg.TargetDCUIndex)
oldIndex := m.DCUToShow.Swap(targetIndex)
if oldIndex == targetIndex {
// 没有变
......@@ -212,11 +212,11 @@ func (m *ModelSysLoad) View() string {
mem = LowLeightStyle.Render(mem)
}
var dcuMem, dcu string
if m.actionMsg == nil || m.actionMsg.TargetDCUIndex == nil {
if m.actionMsg == nil {
dcuMem = fmt.Sprintf(" DCU AVG MEM: %.1f%%", m.current.DCUMemUsageAvg)
dcu = fmt.Sprintf(" DCU AVG UTL: %.1f%%", m.current.DCUUsageAvg)
} else {
index := int(*m.actionMsg.TargetDCUIndex)
index := m.actionMsg.TargetDCUIndex
if index == -1 {
dcuMem = fmt.Sprintf(" DCU AVG MEM: %.1f%%", m.current.DCUMemUsageAvg)
dcu = fmt.Sprintf(" DCU AVG UTL: %.1f%%", m.current.DCUUsageAvg)
......@@ -338,11 +338,11 @@ func (m *ModelSysLoad) updateInfo(t *ModelMsg) {
m.current = &s
needUpdate, index := false, -1
if m.actionMsg != nil && m.actionMsg.TargetDCUIndex != nil {
index = *m.actionMsg.TargetDCUIndex
if m.actionMsg != nil {
index = m.actionMsg.TargetDCUIndex
// 需要进入特定DCU的图表
oldIndex := m.DCUToShow.Swap(int32(index))
if oldIndex != int32(*m.actionMsg.TargetDCUIndex) {
if oldIndex != int32(m.actionMsg.TargetDCUIndex) {
// 需要更新
needUpdate = true
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment