* Print a single block with formatting.
(block: DeepnoteBlock, options: CatOptions)
| 189 | * Print a single block with formatting. |
| 190 | */ |
| 191 | async function printBlock(block: DeepnoteBlock, options: CatOptions): Promise<void> { |
| 192 | const chalk = getChalk() |
| 193 | const typeColor = getTypeColor(block.type) |
| 194 | |
| 195 | output(`${chalk.dim('─'.repeat(60))}`) |
| 196 | output(`${typeColor(block.type)} ${chalk.dim(`(${block.id})`)}`) |
| 197 | |
| 198 | // Show label for input blocks |
| 199 | if (block.type.startsWith('input-')) { |
| 200 | const metadata = block.metadata as { deepnote_variable_name?: string } | undefined |
| 201 | if (metadata?.deepnote_variable_name) { |
| 202 | output(chalk.dim(` Variable: ${metadata.deepnote_variable_name}`)) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // Show content unless --tree mode |
| 207 | if (!options.tree) { |
| 208 | let content = getBlockContent(block) |
| 209 | if (content) { |
| 210 | output('') |
| 211 | if (block.type === 'markdown' || block.type.startsWith('text-cell-')) { |
| 212 | content = wrapAnsi(content, TEXT_BLOCK_MAX_WIDTH, { hard: true }) |
| 213 | } |
| 214 | const highlighted = await highlightContent(content, block.type) |
| 215 | // Indent each line |
| 216 | const lines = highlighted.split('\n') |
| 217 | for (const line of lines) { |
| 218 | output(` ${line}`) |
| 219 | } |
| 220 | } else if (content === '') { |
| 221 | output(chalk.dim(' (empty)')) |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | output('') |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Filter blocks by type if --type option is provided. |
no test coverage detected