feat: add Refresh command to re-detect session state
- Expose via Acme tag bar and 9P ctl file - No arg refreshes all sessions, with arg refreshes one
This commit is contained in:
parent
e28d39aab6
commit
341436a6fd
|
|
@ -331,7 +331,7 @@ func (s *Server) write(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
}
|
||||
args := strings.Fields(input)
|
||||
if len(args) == 0 {
|
||||
return errFcall(fc, "usage: stop | kill")
|
||||
return errFcall(fc, "usage: stop | kill | refresh")
|
||||
}
|
||||
switch args[0] {
|
||||
case "stop":
|
||||
|
|
@ -342,6 +342,11 @@ func (s *Server) write(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
case "kill":
|
||||
sess.Close()
|
||||
s.mgr.Remove(sess.ID())
|
||||
case "refresh":
|
||||
ctx := context.Background()
|
||||
if err := sess.Refresh(ctx); err != nil {
|
||||
return errFcall(fc, err.Error())
|
||||
}
|
||||
default:
|
||||
return errFcall(fc, "unknown command")
|
||||
}
|
||||
|
|
|
|||
19
main.go
19
main.go
|
|
@ -91,7 +91,7 @@ func main() {
|
|||
defer w.CloseFiles()
|
||||
|
||||
w.Name(windowName)
|
||||
w.Write("tag", []byte("Get Attach Kill Alias Context Sandbox "))
|
||||
w.Write("tag", []byte("Get Attach Kill Refresh Alias Context Sandbox "))
|
||||
refreshList(w, mgr)
|
||||
w.Ctl("clean")
|
||||
|
||||
|
|
@ -217,6 +217,23 @@ func main() {
|
|||
srv.OnAliasChange(sess)
|
||||
}
|
||||
refreshList(w, mgr)
|
||||
case "Refresh":
|
||||
if arg == "" {
|
||||
// Refresh all sessions
|
||||
for _, id := range mgr.List() {
|
||||
if sess := mgr.Get(id); sess != nil {
|
||||
sess.Refresh(context.Background())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sess := mgr.Get(arg)
|
||||
if sess == nil {
|
||||
fmt.Fprintf(os.Stderr, "Session not found: %s\n", arg)
|
||||
continue
|
||||
}
|
||||
sess.Refresh(context.Background())
|
||||
}
|
||||
refreshList(w, mgr)
|
||||
case "Context":
|
||||
if arg == "" {
|
||||
fmt.Fprintf(os.Stderr, "Usage: Context <session-id>\n")
|
||||
|
|
|
|||
Reference in New Issue