(cmd *cobra.Command, args []string)
| 44 | } |
| 45 | |
| 46 | func termScrollbackRun(cmd *cobra.Command, args []string) (rtnErr error) { |
| 47 | defer func() { |
| 48 | sendActivity("termscrollback", rtnErr == nil) |
| 49 | }() |
| 50 | |
| 51 | // Resolve the block argument |
| 52 | fullORef, err := resolveBlockArg() |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | // Get block metadata to verify it's a terminal block |
| 58 | metaData, err := wshclient.GetMetaCommand(RpcClient, wshrpc.CommandGetMetaData{ |
| 59 | ORef: *fullORef, |
| 60 | }, &wshrpc.RpcOpts{Timeout: 2000}) |
| 61 | if err != nil { |
| 62 | return fmt.Errorf("error getting block metadata: %w", err) |
| 63 | } |
| 64 | |
| 65 | // Check if the block is a terminal block |
| 66 | viewType, ok := metaData[waveobj.MetaKey_View].(string) |
| 67 | if !ok || viewType != "term" { |
| 68 | return fmt.Errorf("block %s is not a terminal block (view type: %s)", fullORef.OID, viewType) |
| 69 | } |
| 70 | |
| 71 | // Make the RPC call to get scrollback |
| 72 | scrollbackData := wshrpc.CommandTermGetScrollbackLinesData{ |
| 73 | LineStart: termScrollbackLineStart, |
| 74 | LineEnd: termScrollbackLineEnd, |
| 75 | LastCommand: termScrollbackLastCmd, |
| 76 | } |
| 77 | |
| 78 | result, err := wshclient.TermGetScrollbackLinesCommand(RpcClient, scrollbackData, &wshrpc.RpcOpts{ |
| 79 | Route: wshutil.MakeFeBlockRouteId(fullORef.OID), |
| 80 | Timeout: 5000, |
| 81 | }) |
| 82 | if err != nil { |
| 83 | return fmt.Errorf("error getting terminal scrollback: %w", err) |
| 84 | } |
| 85 | |
| 86 | // Format the output |
| 87 | output := strings.Join(result.Lines, "\n") |
| 88 | if len(result.Lines) > 0 { |
| 89 | output += "\n" // Add final newline |
| 90 | } |
| 91 | |
| 92 | // Write to file or stdout |
| 93 | if termScrollbackOutputFile != "" { |
| 94 | err = os.WriteFile(termScrollbackOutputFile, []byte(output), 0644) |
| 95 | if err != nil { |
| 96 | return fmt.Errorf("error writing to file %s: %w", termScrollbackOutputFile, err) |
| 97 | } |
| 98 | fmt.Printf("terminal scrollback written to %s (%d lines)\n", termScrollbackOutputFile, len(result.Lines)) |
| 99 | } else { |
| 100 | fmt.Print(output) |
| 101 | } |
| 102 | |
| 103 | return nil |
nothing calls this directly
no test coverage detected