summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-06-22 00:54:10 +0000
committerGitHub <[email protected]>2025-06-22 00:54:10 +0000
commit63f6a497cba61299a1c24aa96795a55479740ac6 (patch)
tree34781289e6296340e7cf76300413b06f8994c1ab /packages/cli/src/ui/utils
parente20171e7ddb7c4d0935dcb578b8395dc560005ec (diff)
Jacob314/overflow notification and one MaxSizedBox bug fix (#1288)
Diffstat (limited to 'packages/cli/src/ui/utils')
-rw-r--r--packages/cli/src/ui/utils/CodeColorizer.tsx17
1 files changed, 9 insertions, 8 deletions
diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx
index f96e6c9a..9bb7c362 100644
--- a/packages/cli/src/ui/utils/CodeColorizer.tsx
+++ b/packages/cli/src/ui/utils/CodeColorizer.tsx
@@ -16,7 +16,10 @@ import type {
} from 'hast';
import { themeManager } from '../themes/theme-manager.js';
import { Theme } from '../themes/theme.js';
-import { MaxSizedBox } from '../components/shared/MaxSizedBox.js';
+import {
+ MaxSizedBox,
+ MINIMUM_MAX_HEIGHT,
+} from '../components/shared/MaxSizedBox.js';
// Configure themeing and parsing utilities.
const lowlight = createLowlight(common);
@@ -85,8 +88,6 @@ function renderHastNode(
return null;
}
-const RESERVED_LINES_FOR_TRUNCATION_MESSAGE = 2;
-
/**
* Renders syntax-highlighted code for Ink applications using a selected theme.
*
@@ -111,11 +112,11 @@ export function colorizeCode(
let hiddenLinesCount = 0;
- // Optimizaiton to avoid highlighting lines that cannot possibly be displayed.
- if (availableHeight && lines.length > availableHeight) {
- const sliceIndex =
- lines.length - availableHeight + RESERVED_LINES_FOR_TRUNCATION_MESSAGE;
- if (sliceIndex > 0) {
+ // Optimization to avoid highlighting lines that cannot possibly be displayed.
+ if (availableHeight !== undefined) {
+ availableHeight = Math.max(availableHeight, MINIMUM_MAX_HEIGHT);
+ if (lines.length > availableHeight) {
+ const sliceIndex = lines.length - availableHeight;
hiddenLinesCount = sliceIndex;
lines = lines.slice(sliceIndex);
}