From b41a4d7c4494e7c8efe1ffdf0e215c3f3827e7bb Mon Sep 17 00:00:00 2001 From: kriyanshii Date: Fri, 27 Feb 2026 23:24:52 +0530 Subject: [PATCH] GH-37958: [MATLAB] Centralize Command Window hyperlink formatting Reduce duplicate hyperlink formatting logic in Command Window display helpers. * Add a shared hyperlink utility in MATLAB display helpers. * Use it in schema string rendering and test helpers. Not run (manual check in MATLAB Command Window). Yes. Command Window display now uses a shared hyperlink helper. * GitHub Issue: #37958 --- .../+internal/+display/makeLinkString.m | 40 +++++++++++++++++++ .../+internal/+test/+display/makeLinkString.m | 12 ++---- .../+internal/+display/getSchemaString.m | 25 +++--------- 3 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 matlab/src/matlab/+arrow/+internal/+display/makeLinkString.m diff --git a/matlab/src/matlab/+arrow/+internal/+display/makeLinkString.m b/matlab/src/matlab/+arrow/+internal/+display/makeLinkString.m new file mode 100644 index 00000000000..c93cbda4d3e --- /dev/null +++ b/matlab/src/matlab/+arrow/+internal/+display/makeLinkString.m @@ -0,0 +1,40 @@ +%MAKELINKSTRING Creates a hyperlink string if possible. + +% Licensed to the Apache Software Foundation (ASF) under one or more +% contributor license agreements. See the NOTICE file distributed with +% this work for additional information regarding copyright ownership. +% The ASF licenses this file to you under the Apache License, Version +% 2.0 (the "License"); you may not use this file except in compliance +% with the License. You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +% implied. See the License for the specific language governing +% permissions and limitations under the License. + +function link = makeLinkString(opts) + arguments + opts.HelpTarget(1, 1) string {mustBeNonzeroLengthText} + opts.Text(1, 1) string {mustBeNonzeroLengthText} + % When displaying heterogeneous arrays, only the name of the + % closest shared ancestor class is displayed in bold. All other + % class names are not bolded. + opts.BoldFont(1, 1) logical = false + end + + if usejava("desktop") + if opts.BoldFont + link = compose("%s", ... + opts.HelpTarget, opts.Text); + else + link = compose("%s", ... + opts.HelpTarget, opts.Text); + end + else + link = opts.Text; + end +end diff --git a/matlab/src/matlab/+arrow/+internal/+test/+display/makeLinkString.m b/matlab/src/matlab/+arrow/+internal/+test/+display/makeLinkString.m index e99dd7d7848..37daa009160 100644 --- a/matlab/src/matlab/+arrow/+internal/+test/+display/makeLinkString.m +++ b/matlab/src/matlab/+arrow/+internal/+test/+display/makeLinkString.m @@ -25,12 +25,8 @@ opts.BoldFont(1, 1) logical end - if opts.BoldFont - link = compose("%s", ... - opts.FullClassName, opts.ClassName); - else - link = compose("%s", ... - opts.FullClassName, opts.ClassName); - end + link = arrow.internal.display.makeLinkString( ... + HelpTarget=opts.FullClassName, ... + Text=opts.ClassName, ... + BoldFont=opts.BoldFont); end \ No newline at end of file diff --git a/matlab/src/matlab/+arrow/+tabular/+internal/+display/getSchemaString.m b/matlab/src/matlab/+arrow/+tabular/+internal/+display/getSchemaString.m index 724b4873c92..665a9f4ef37 100644 --- a/matlab/src/matlab/+arrow/+tabular/+internal/+display/getSchemaString.m +++ b/matlab/src/matlab/+arrow/+tabular/+internal/+display/getSchemaString.m @@ -26,25 +26,12 @@ idx = strlength(names) == 0; names(idx) = ""; - if usejava("desktop") - % When in desktop mode, the Command Window can interpret HTML tags - % to display bold font and hyperlinks. - names = compose("%s", names); - classNames = arrayfun(@(type) string(class(type)), types); - - % Creates a string array with the following form: - % - % ["arrow.type.BooleanType" "Boolean" "arrow.type.StringType" "String" ...] - % - % This string array is passed to the compose call below. The - % format specifier operator supplied to compose contains two - % formatting operators (%s), so compose uses two elements from the - % string array (classNameAndIDs) at a time. - classNameAndIDs = strings([1 numel(typeIDs) * 2]); - classNameAndIDs(1:2:end-1) = classNames; - classNameAndIDs(2:2:end) = typeIDs; - typeIDs = compose("%s", classNameAndIDs); - end + % When in desktop mode, the Command Window can interpret HTML tags + % to display bold font and hyperlinks. + names = arrayfun(@arrow.internal.display.boldFontIfPossible, names); + classNames = arrayfun(@(type) string(class(type)), types); + typeIDs = arrayfun(@(className, typeID) arrow.internal.display.makeLinkString( ... + HelpTarget=className, Text=typeID, BoldFont=true), classNames, typeIDs); text = names + ": " + typeIDs; text = strjoin(text, " | ");