monitor: Enable to exec into the container

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
Kohei Tokunaga
2023-02-14 21:16:29 +09:00
parent eefe27ff42
commit e8f55a3cf7
14 changed files with 1249 additions and 481 deletions

View File

@ -133,6 +133,27 @@ func (m *MuxIO) Enable(i int) {
m.enabled[i] = struct{}{}
}
func (m *MuxIO) SwitchTo(i int) error {
m.mu.Lock()
defer m.mu.Unlock()
if m.cur == i {
return nil
}
if _, ok := m.enabled[i]; !ok {
return errors.Errorf("IO index %d isn't active", i)
}
if m.outs[m.cur].DisableHook != nil {
m.outs[m.cur].DisableHook()
}
prev := m.cur
m.cur = i
if m.outs[m.cur].EnableHook != nil {
m.outs[m.cur].EnableHook()
}
fmt.Fprint(m.in.Stdout, m.toggleMessage(prev, i))
return nil
}
func (m *MuxIO) Disable(i int) error {
m.mu.Lock()
defer m.mu.Unlock()