refactor: extracted padding logic into reusable utility function with optimized buffer allocation

- Extracted manual space padding logic into a reusable `padding()` utility function across all UI components and utilities.
- Optimized padding operations by introducing a pre-allocated 512-space buffer in the `padding()` function to reduce repeated string allocations.
- Updated all imports across 30 files to use the new `padding()` function from pi-tui instead of inline `' '.repeat()` calls.
- Renamed local variables from `padding` to `pad`, `padSize`, `indent`, or `linePad` to avoid naming conflicts with the imported `padding()` function.
- Exported the `padding()` utility function from the tui package index for public use.
This commit is contained in:
can1357
2026-01-31 13:36:54 +01:00
parent 9a22622f9c
commit cc90ed37f8
30 changed files with 121 additions and 92 deletions
+3 -1
View File
@@ -4,6 +4,8 @@
* Handles line endings, BOM, whitespace, and Unicode normalization.
*/
import { padding } from "@oh-my-pi/pi-tui";
// ═══════════════════════════════════════════════════════════════════════════
// Line Ending Utilities
// ═══════════════════════════════════════════════════════════════════════════
@@ -194,7 +196,7 @@ export function convertLeadingTabsToSpaces(text: string, spacesPerTab: number):
if (trimmed.length === 0) return line;
const leading = getLeadingWhitespace(line);
if (!leading.includes("\t") || leading.includes(" ")) return line;
const converted = " ".repeat(leading.length * spacesPerTab);
const converted = padding(leading.length * spacesPerTab);
return converted + trimmed;
})
.join("\n");