mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
Try using internal string-width in node:readline (#26306)
### What does this PR do? Remove NFKDC normalization and stripVTControlCharacters since Bun.stringWidth does this now ### How did you verify your code works? ci --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -172,10 +172,7 @@ export function createConsoleConstructor(console: typeof globalThis.console) {
|
||||
* Returns the number of columns required to display the given string.
|
||||
*/
|
||||
var getStringWidth = function getStringWidth(str, removeControlChars = true) {
|
||||
if (removeControlChars) str = stripVTControlCharacters(str);
|
||||
str = StringPrototypeNormalize.$call(str, "NFC");
|
||||
|
||||
return internalGetStringWidth(str);
|
||||
return internalGetStringWidth(str, removeControlChars);
|
||||
};
|
||||
|
||||
const tableChars = {
|
||||
|
||||
@@ -98,9 +98,7 @@ const ObjectCreate = Object.create;
|
||||
* Returns the number of columns required to display the given string.
|
||||
*/
|
||||
var getStringWidth = function getStringWidth(str, removeControlChars = true) {
|
||||
if (removeControlChars) str = stripVTControlCharacters(str);
|
||||
str = StringPrototypeNormalize.$call(str, "NFC");
|
||||
return internalGetStringWidth(str);
|
||||
return internalGetStringWidth(str, removeControlChars);
|
||||
};
|
||||
|
||||
const stripANSI = Bun.stripANSI;
|
||||
|
||||
@@ -1093,20 +1093,15 @@ pub const String = extern struct {
|
||||
extern fn JSC__createRangeError(*jsc.JSGlobalObject, str: *const String) jsc.JSValue;
|
||||
|
||||
pub fn jsGetStringWidth(globalObject: *jsc.JSGlobalObject, callFrame: *jsc.CallFrame) bun.JSError!jsc.JSValue {
|
||||
const args = callFrame.arguments_old(1).slice();
|
||||
const argument = callFrame.argument(0);
|
||||
const str = try argument.toJSString(globalObject);
|
||||
const view = str.view(globalObject);
|
||||
|
||||
if (args.len == 0 or !args.ptr[0].isString()) {
|
||||
if (view.isEmpty()) {
|
||||
return .jsNumber(@as(i32, 0));
|
||||
}
|
||||
|
||||
const str = try args[0].toBunString(globalObject);
|
||||
defer str.deref();
|
||||
|
||||
if (str.isEmpty()) {
|
||||
return .jsNumber(@as(i32, 0));
|
||||
}
|
||||
|
||||
const width = str.visibleWidth(false);
|
||||
const width = bun.String.init(view).visibleWidth(false);
|
||||
return .jsNumber(width);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
" catch bun.outOfMemory()": 0,
|
||||
"!= alloc.ptr": 0,
|
||||
"!= allocator.ptr": 0,
|
||||
".arguments_old(": 264,
|
||||
".arguments_old(": 263,
|
||||
".jsBoolean(false)": 0,
|
||||
".jsBoolean(true)": 0,
|
||||
".stdDir()": 42,
|
||||
|
||||
Reference in New Issue
Block a user