feat(text-display): implemented configurable tab width

- Added a `display.tabWidth` setting to control default tab rendering.
- Integrated `.editorconfig` resolution for c ontext-aware tab indentation.
- Updated native text processing to use the resolved tab width for calculations.
- Improved tab visualization in diffs and other UI elements for consistency.
This commit is contained in:
can1357
2026-02-23 14:58:59 +01:00
parent 8f5e0c9785
commit 4b60af5c47
13 changed files with 641 additions and 77 deletions
+5 -3
View File
@@ -1,4 +1,5 @@
import { sliceWithWidth } from "@oh-my-pi/pi-natives";
import { getDefaultTabWidth, getIndentation } from "@oh-my-pi/pi-utils";
export { Ellipsis, extractSegments, sliceWithWidth, truncateToWidth, wrapTextWithAnsi } from "@oh-my-pi/pi-natives";
@@ -6,10 +7,10 @@ export { Ellipsis, extractSegments, sliceWithWidth, truncateToWidth, wrapTextWit
const SPACE_BUFFER = " ".repeat(512);
/*
* Replace tabs with 3 spaces for consistent rendering.
* Replace tabs with configured spacing for consistent rendering.
*/
export function replaceTabs(text: string): string {
return text.replaceAll("\t", " ");
return text.replaceAll("\t", getIndentation());
}
/**
@@ -42,10 +43,11 @@ export function visibleWidthRaw(str: string): number {
// Fast path: pure ASCII printable
let isPureAscii = true;
let tabLength = 0;
const tabWidth = getDefaultTabWidth();
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
if (code === 9) {
tabLength += 3;
tabLength += tabWidth;
} else if (code < 0x20 || code > 0x7e) {
isPureAscii = false;
}