Skip to content

Commit 77dc211

Browse files
committed
Quote name if it contains space when listing modules
Update formatListEltToDisplay and formatListEltToLongDisplay to enclose element name in single quote if it contains a space character. As a result list and avail output will now report enclosed module names if space character if found in them, like it is done when reporting module designation as loading/unloading header. Only enclose element name and not suffix, to follow the same output approach than 'ls' command.
1 parent 7cec68b commit 77dc211

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

NEWS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ Modules 5.1.0 (not yet released)
221221
* When loading a module with some extra tags defined through the
222222
:option:`--tag` option, if this module is already loaded the new tags are
223223
added to those already set.
224+
* When reporting result of :subcmd:`avail` or :subcmd:`list` sub-commands,
225+
enclose module names in single quotes if they contain a space character.
224226

225227
.. _Code of conduct: https://github.com/cea-hpc/modules/blob/master/CODE_OF_CONDUCT.md
226228
.. _codespell: https://github.com/codespell-project/codespell

tcl/report.tcl.in

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,18 @@ proc formatListEltToDisplay {elt eltsgr eltsuffix sym_list symsgr show_syms\
942942
}
943943
}
944944
945-
set disp $elt$eltsuffix
945+
set displen 0
946+
set disp $elt
946947
lappend eltsgrlist $eltsgr
947-
set dispsgr [sgr $eltsgrlist $elt $himatchmap $tagsgrlist]$eltsuffix
948+
set dispsgr [sgr $eltsgrlist $elt $himatchmap $tagsgrlist]
949+
# enclose name between quotes if a space is found
950+
if {[string first { } $elt] != -1} {
951+
incr displen 2
952+
set dispsgr '$dispsgr'
953+
}
954+
# append suffix
955+
append disp $eltsuffix
956+
append dispsgr $eltsuffix
948957
949958
# format variant list if any
950959
if {$show_vrs && [llength $vr_list] > 0} {
@@ -1011,21 +1020,37 @@ proc formatListEltToDisplay {elt eltsgr eltsuffix sym_list symsgr show_syms\
10111020
append dispsgr $tagssgr
10121021
}
10131022
1014-
return [list $disp $dispsgr]
1023+
# compute length
1024+
incr displen [string length $disp]
1025+
1026+
return [list $disp $dispsgr $displen]
10151027
}
10161028
10171029
# format an element with its syms for a long/detailed display in a list
10181030
proc formatListEltToLongDisplay {elt eltsgr eltsuffix sym_list symsgr mtime\
10191031
sgrdef {himatchmap {}}} {
1020-
set disp $elt$eltsuffix
1021-
set displen [string length $disp]
10221032
# display default sym graphically over element name
10231033
if {[set defidx [lsearch -exact $sym_list default]] != -1 && $sgrdef} {
10241034
set sym_list [lreplace $sym_list $defidx $defidx]
10251035
lappend eltsgrlist de
10261036
}
10271037
lappend eltsgrlist $eltsgr
1028-
set dispsgr [sgr $eltsgrlist $elt $himatchmap]$eltsuffix
1038+
1039+
set displen 0
1040+
set disp $elt
1041+
set dispsgr [sgr $eltsgrlist $elt $himatchmap]
1042+
# enclose name between quotes if a space is found
1043+
if {[string first { } $elt] != -1} {
1044+
incr displen 2
1045+
set dispsgr '$dispsgr'
1046+
}
1047+
# append suffix
1048+
append disp $eltsuffix
1049+
append dispsgr $eltsuffix
1050+
1051+
# compute length
1052+
incr displen [string length $disp]
1053+
10291054
# format remaining sym list
10301055
if {[llength $sym_list] > 0} {
10311056
set symslen [string length [join $sym_list :]]
@@ -1044,7 +1069,7 @@ proc formatListEltToLongDisplay {elt eltsgr eltsuffix sym_list symsgr mtime\
10441069
set nbws1 [expr {40 - $displen}]
10451070
set nbws2 [expr {20 - $symslen + [expr {$nbws1 < 0 ? $nbws1 : 0}]}]
10461071
return [list $disp $dispsgr[string repeat { } $nbws1]$symssgr[string\
1047-
repeat { } $nbws2]$mtime]
1072+
repeat { } $nbws2]$mtime $displen]
10481073
}
10491074
10501075
proc formatArrayValToJson {vallist} {
@@ -1159,11 +1184,11 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
11591184
} elseif {$show_mtime} {
11601185
# append / char after name to clearly indicate this is a dir
11611186
lassign [formatListEltToLongDisplay $elt di / $sym_list sy {}\
1162-
$default_colored $himatchmap] disp dispsgr
1187+
$default_colored $himatchmap] disp dispsgr displen
11631188
} else {
11641189
lassign [formatListEltToDisplay $elt di / $sym_list sy\
11651190
$report_sym $default_colored {} 0 {} {} 0 $himatchmap] disp\
1166-
dispsgr
1191+
dispsgr displen
11671192
}
11681193
}
11691194
modulefile - virtual {
@@ -1178,11 +1203,12 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
11781203
# add to display file modification time in addition
11791204
# to potential syms
11801205
lassign [formatListEltToLongDisplay $elt {} {} $sym_list sy\
1181-
$clock_mtime $default_colored $himatchmap] disp dispsgr
1206+
$clock_mtime $default_colored $himatchmap] disp dispsgr\
1207+
displen
11821208
} else {
11831209
lassign [formatListEltToDisplay $elt {} {} $sym_list sy\
11841210
$report_sym $default_colored $tag_list $report_tag $vr_list\
1185-
va $report_variant $himatchmap] disp dispsgr
1211+
va $report_variant $himatchmap] disp dispsgr displen
11861212
}
11871213
}
11881214
alias {
@@ -1193,7 +1219,7 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
11931219
} elseif {$show_mtime} {
11941220
lassign [formatListEltToLongDisplay $elt al " -> [lindex\
11951221
$mod_list($elt) 1]" $sym_list sy {} $default_colored\
1196-
$himatchmap] disp dispsgr
1222+
$himatchmap] disp dispsgr displen
11971223
} elseif {$report_alias} {
11981224
# add a '@' sym to indicate elt is an alias if not colored
11991225
if {!$alias_colored} {
@@ -1205,7 +1231,7 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
12051231
}
12061232
lassign [formatListEltToDisplay $elt al {} $sym_list sy\
12071233
$report_sym $default_colored $tag_list $report_tag {} {} 0\
1208-
$himatchmap] disp dispsgr
1234+
$himatchmap] disp dispsgr displen
12091235
}
12101236
}
12111237
}
@@ -1215,6 +1241,7 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
12151241
} else {
12161242
lappend clean_list $disp
12171243
set sgrmap($disp) $dispsgr
1244+
set lenmap($disp) $displen
12181245
}
12191246
}
12201247
}
@@ -1235,9 +1262,9 @@ proc reportModules {mod header hsgrkey hstyle show_mtime show_idx\
12351262
foreach disp $clean_list {
12361263
# compute display element length list on sorted result
12371264
lappend display_list $sgrmap($disp)
1238-
lappend len_list [set len [string length $disp]]
1239-
if {$len > $max_len} {
1240-
set max_len $len
1265+
lappend len_list $lenmap($disp)
1266+
if {$lenmap($disp) > $max_len} {
1267+
set max_len $lenmap($disp)
12411268
}
12421269
}
12431270
}

0 commit comments

Comments
 (0)