@@ -48,6 +48,7 @@ contains |
| 48 | 48 | integer, intent(in) :: line_num |
| 49 | 49 | integer(i64), intent(in) :: byte_off |
| 50 | 50 | type(grep_options), intent(in) :: opts |
| 51 | + character(len=16) :: num_fmt |
| 51 | 52 | |
| 52 | 53 | ! Quiet mode - no output |
| 53 | 54 | if (opts%quiet) return |
@@ -62,9 +63,14 @@ contains |
| 62 | 63 | end if |
| 63 | 64 | end if |
| 64 | 65 | |
| 65 | | - ! Print line number prefix |
| 66 | + ! Print line number prefix (use width for -T alignment) |
| 66 | 67 | if (opts%show_line_number) then |
| 67 | | - write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 68 | + if (opts%initial_tab .and. opts%line_number_width > 1) then |
| 69 | + write(num_fmt, '(A,I0,A)') '(I', opts%line_number_width, ',A)' |
| 70 | + write(output_unit, num_fmt, advance='no') line_num, ':' |
| 71 | + else |
| 72 | + write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 73 | + end if |
| 68 | 74 | end if |
| 69 | 75 | |
| 70 | 76 | ! Print byte offset prefix |
@@ -72,8 +78,10 @@ contains |
| 72 | 78 | write(output_unit, '(I0,A)', advance='no') byte_off, ':' |
| 73 | 79 | end if |
| 74 | 80 | |
| 75 | | - ! Print tab alignment if requested |
| 76 | | - if (opts%initial_tab) then |
| 81 | + ! Print tab alignment if requested (only when there's a prefix) |
| 82 | + if (opts%initial_tab .and. & |
| 83 | + ((opts%show_filename .and. .not. opts%hide_filename) .or. & |
| 84 | + opts%show_line_number .or. opts%show_byte_offset)) then |
| 77 | 85 | write(output_unit, '(A)', advance='no') char(9) ! TAB |
| 78 | 86 | end if |
| 79 | 87 | |
@@ -98,6 +106,7 @@ contains |
| 98 | 106 | integer, intent(in) :: line_num |
| 99 | 107 | integer(i64), intent(in) :: byte_off |
| 100 | 108 | type(grep_options), intent(in) :: opts |
| 109 | + character(len=16) :: num_fmt |
| 101 | 110 | |
| 102 | 111 | if (opts%quiet) return |
| 103 | 112 | |
@@ -111,9 +120,14 @@ contains |
| 111 | 120 | end if |
| 112 | 121 | end if |
| 113 | 122 | |
| 114 | | - ! Print line number prefix with - separator |
| 123 | + ! Print line number prefix with - separator (use width for -T alignment) |
| 115 | 124 | if (opts%show_line_number) then |
| 116 | | - write(output_unit, '(I0,A)', advance='no') line_num, '-' |
| 125 | + if (opts%initial_tab .and. opts%line_number_width > 1) then |
| 126 | + write(num_fmt, '(A,I0,A)') '(I', opts%line_number_width, ',A)' |
| 127 | + write(output_unit, num_fmt, advance='no') line_num, '-' |
| 128 | + else |
| 129 | + write(output_unit, '(I0,A)', advance='no') line_num, '-' |
| 130 | + end if |
| 117 | 131 | end if |
| 118 | 132 | |
| 119 | 133 | ! Print byte offset prefix with - separator |
@@ -121,8 +135,10 @@ contains |
| 121 | 135 | write(output_unit, '(I0,A)', advance='no') byte_off, '-' |
| 122 | 136 | end if |
| 123 | 137 | |
| 124 | | - ! Print tab alignment if requested |
| 125 | | - if (opts%initial_tab) then |
| 138 | + ! Print tab alignment if requested (only when there's a prefix) |
| 139 | + if (opts%initial_tab .and. & |
| 140 | + ((opts%show_filename .and. .not. opts%hide_filename) .or. & |
| 141 | + opts%show_line_number .or. opts%show_byte_offset)) then |
| 126 | 142 | write(output_unit, '(A)', advance='no') char(9) |
| 127 | 143 | end if |
| 128 | 144 | |
@@ -229,6 +245,7 @@ contains |
| 229 | 245 | integer, intent(in) :: line_num |
| 230 | 246 | integer(i64), intent(in) :: byte_off |
| 231 | 247 | type(grep_options), intent(in) :: opts |
| 248 | + character(len=16) :: num_fmt |
| 232 | 249 | |
| 233 | 250 | if (opts%quiet) return |
| 234 | 251 | |
@@ -242,9 +259,14 @@ contains |
| 242 | 259 | end if |
| 243 | 260 | end if |
| 244 | 261 | |
| 245 | | - ! Print line number prefix |
| 262 | + ! Print line number prefix (use width for -T alignment) |
| 246 | 263 | if (opts%show_line_number) then |
| 247 | | - write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 264 | + if (opts%initial_tab .and. opts%line_number_width > 1) then |
| 265 | + write(num_fmt, '(A,I0,A)') '(I', opts%line_number_width, ',A)' |
| 266 | + write(output_unit, num_fmt, advance='no') line_num, ':' |
| 267 | + else |
| 268 | + write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 269 | + end if |
| 248 | 270 | end if |
| 249 | 271 | |
| 250 | 272 | ! Print byte offset prefix (offset to start of match) |
@@ -252,8 +274,10 @@ contains |
| 252 | 274 | write(output_unit, '(I0,A)', advance='no') byte_off + match_start - 1, ':' |
| 253 | 275 | end if |
| 254 | 276 | |
| 255 | | - ! Print tab alignment if requested |
| 256 | | - if (opts%initial_tab) then |
| 277 | + ! Print tab alignment if requested (only when there's a prefix) |
| 278 | + if (opts%initial_tab .and. & |
| 279 | + ((opts%show_filename .and. .not. opts%hide_filename) .or. & |
| 280 | + opts%show_line_number .or. opts%show_byte_offset)) then |
| 257 | 281 | write(output_unit, '(A)', advance='no') char(9) |
| 258 | 282 | end if |
| 259 | 283 | |
@@ -286,6 +310,7 @@ contains |
| 286 | 310 | |
| 287 | 311 | integer :: i, pos, line_len |
| 288 | 312 | logical :: use_color |
| 313 | + character(len=16) :: num_fmt |
| 289 | 314 | |
| 290 | 315 | if (opts%quiet) return |
| 291 | 316 | |
@@ -320,13 +345,26 @@ contains |
| 320 | 345 | end if |
| 321 | 346 | end if |
| 322 | 347 | |
| 323 | | - ! Print line number prefix |
| 348 | + ! Print line number prefix (use width for -T alignment) |
| 324 | 349 | if (opts%show_line_number) then |
| 325 | | - if (use_color) then |
| 326 | | - write(output_unit, '(A,I0,A)', advance='no') COLOR_LINENUM, line_num, COLOR_RESET |
| 327 | | - write(output_unit, '(A,A,A)', advance='no') COLOR_SEP, ':', COLOR_RESET |
| 350 | + if (opts%initial_tab .and. opts%line_number_width > 1) then |
| 351 | + write(num_fmt, '(A,I0,A)') '(I', opts%line_number_width, ')' |
| 352 | + if (use_color) then |
| 353 | + write(output_unit, '(A)', advance='no') COLOR_LINENUM |
| 354 | + write(output_unit, num_fmt, advance='no') line_num |
| 355 | + write(output_unit, '(A)', advance='no') COLOR_RESET |
| 356 | + write(output_unit, '(A,A,A)', advance='no') COLOR_SEP, ':', COLOR_RESET |
| 357 | + else |
| 358 | + write(output_unit, num_fmt, advance='no') line_num |
| 359 | + write(output_unit, '(A)', advance='no') ':' |
| 360 | + end if |
| 328 | 361 | else |
| 329 | | - write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 362 | + if (use_color) then |
| 363 | + write(output_unit, '(A,I0,A)', advance='no') COLOR_LINENUM, line_num, COLOR_RESET |
| 364 | + write(output_unit, '(A,A,A)', advance='no') COLOR_SEP, ':', COLOR_RESET |
| 365 | + else |
| 366 | + write(output_unit, '(I0,A)', advance='no') line_num, ':' |
| 367 | + end if |
| 330 | 368 | end if |
| 331 | 369 | end if |
| 332 | 370 | |
@@ -340,8 +378,10 @@ contains |
| 340 | 378 | end if |
| 341 | 379 | end if |
| 342 | 380 | |
| 343 | | - ! Print tab alignment if requested |
| 344 | | - if (opts%initial_tab) then |
| 381 | + ! Print tab alignment if requested (only when there's a prefix) |
| 382 | + if (opts%initial_tab .and. & |
| 383 | + ((opts%show_filename .and. .not. opts%hide_filename) .or. & |
| 384 | + opts%show_line_number .or. opts%show_byte_offset)) then |
| 345 | 385 | write(output_unit, '(A)', advance='no') char(9) |
| 346 | 386 | end if |
| 347 | 387 | |