(block *waveobj.Block)
| 20 | ) |
| 21 | |
| 22 | func makeTerminalBlockDesc(block *waveobj.Block) string { |
| 23 | connection, hasConnection := block.Meta["connection"].(string) |
| 24 | cwd, hasCwd := block.Meta["cmd:cwd"].(string) |
| 25 | |
| 26 | blockORef := waveobj.MakeORef(waveobj.OType_Block, block.OID) |
| 27 | rtInfo := wstore.GetRTInfo(blockORef) |
| 28 | hasCurCwd := rtInfo != nil && rtInfo.ShellHasCurCwd |
| 29 | |
| 30 | var desc string |
| 31 | if hasConnection && connection != "" { |
| 32 | desc = fmt.Sprintf("CLI terminal connected to %q", connection) |
| 33 | } else { |
| 34 | desc = "local CLI terminal" |
| 35 | } |
| 36 | |
| 37 | if rtInfo != nil && rtInfo.ShellType != "" { |
| 38 | desc += fmt.Sprintf(" (%s", rtInfo.ShellType) |
| 39 | if rtInfo.ShellVersion != "" { |
| 40 | desc += fmt.Sprintf(" %s", rtInfo.ShellVersion) |
| 41 | } |
| 42 | desc += ")" |
| 43 | } |
| 44 | |
| 45 | if rtInfo != nil { |
| 46 | if rtInfo.ShellIntegration { |
| 47 | var stateStr string |
| 48 | switch rtInfo.ShellState { |
| 49 | case "ready": |
| 50 | stateStr = "waiting for input" |
| 51 | case "running-command": |
| 52 | stateStr = "running command" |
| 53 | if rtInfo.ShellLastCmd != "" { |
| 54 | cmdStr := rtInfo.ShellLastCmd |
| 55 | if len(cmdStr) > 30 { |
| 56 | cmdStr = cmdStr[:27] + "..." |
| 57 | } |
| 58 | cmdJSON := utilfn.MarshalJSONString(cmdStr) |
| 59 | stateStr = fmt.Sprintf("running command %s", cmdJSON) |
| 60 | } |
| 61 | default: |
| 62 | stateStr = "state unknown" |
| 63 | } |
| 64 | desc += fmt.Sprintf(", %s", stateStr) |
| 65 | } else { |
| 66 | desc += ", no shell integration" |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if hasCurCwd && hasCwd && cwd != "" { |
| 71 | desc += fmt.Sprintf(", in directory %q", cwd) |
| 72 | } |
| 73 | |
| 74 | return desc |
| 75 | } |
| 76 | |
| 77 | func MakeBlockShortDesc(block *waveobj.Block) string { |
| 78 | if block.Meta == nil { |
no test coverage detected