@@ -25,7 +25,7 @@ mod term_size {
25
25
26
26
use unicode_width:: UnicodeWidthStr ;
27
27
28
- use strext:: _StrExt;
28
+ // use strext::_StrExt;
29
29
30
30
fn str_width ( s : & str ) -> usize {
31
31
UnicodeWidthStr :: width ( s)
@@ -336,7 +336,6 @@ impl<'a> Help<'a> {
336
336
let width = self . term_w ;
337
337
debugln ! ( "Term width...{}" , width) ;
338
338
let too_long = str_width ( h) >= width;
339
- debugln ! ( "Too long...{:?}" , too_long) ;
340
339
341
340
debug ! ( "Too long..." ) ;
342
341
if too_long {
@@ -355,41 +354,7 @@ impl<'a> Help<'a> {
355
354
}
356
355
lw
357
356
} ;
358
- debugln ! ( "Longest word...{}" , longest_w) ;
359
- debug ! ( "Enough space to wrap..." ) ;
360
- if longest_w < width {
361
- sdebugln ! ( "Yes" ) ;
362
- let mut indices = vec ! [ ] ;
363
- let mut idx = 0 ;
364
- loop {
365
- idx += width - 1 ;
366
- if idx >= help. len ( ) {
367
- break ;
368
- }
369
- // 'a' arbitrary non space char
370
- if help. chars ( ) . nth ( idx) . unwrap_or ( 'a' ) != ' ' {
371
- idx = find_idx_of_space ( & * help, idx) ;
372
- }
373
- debugln ! ( "Adding idx: {}" , idx) ;
374
- debugln ! ( "At {}: {:?}" , idx, help. chars( ) . nth( idx) ) ;
375
- indices. push ( idx) ;
376
- if str_width ( & help[ idx..] ) <= width {
377
- break ;
378
- }
379
- }
380
- for ( i, idx) in indices. iter ( ) . enumerate ( ) {
381
- debugln ! ( "iter;i={},idx={}" , i, idx) ;
382
- let j = idx + ( 2 * i) ;
383
- debugln ! ( "removing: {}" , j) ;
384
- debugln ! ( "at {}: {:?}" , j, help. chars( ) . nth( j) ) ;
385
- help. remove ( j) ;
386
- help. insert ( j, '{' ) ;
387
- help. insert ( j + 1 , 'n' ) ;
388
- help. insert ( j + 2 , '}' ) ;
389
- }
390
- } else {
391
- sdebugln ! ( "No" ) ;
392
- }
357
+ wrap_help ( & mut help, longest_w, width) ;
393
358
} else {
394
359
sdebugln ! ( "No" ) ;
395
360
}
@@ -427,15 +392,15 @@ impl<'a> Help<'a> {
427
392
let width = self . term_w ;
428
393
debugln ! ( "Term width...{}" , width) ;
429
394
let too_long = spcs + str_width ( h) + str_width ( & * spec_vals) >= width;
430
- debugln ! ( "Too long...{:? }" , too_long ) ;
395
+ debugln ! ( "Spaces: { }" , spcs ) ;
431
396
432
397
// Is help on next line, if so newline + 2x tab
433
398
if self . next_line_help || arg. is_set ( ArgSettings :: NextLineHelp ) {
434
399
try!( write ! ( self . writer, "\n {}{}" , TAB , TAB ) ) ;
435
400
}
436
401
437
402
debug ! ( "Too long..." ) ;
438
- if too_long {
403
+ if too_long && spcs <= width {
439
404
sdebugln ! ( "Yes" ) ;
440
405
help. push_str ( h) ;
441
406
help. push_str ( & * spec_vals) ;
@@ -453,35 +418,7 @@ impl<'a> Help<'a> {
453
418
}
454
419
lw
455
420
} ;
456
- debugln ! ( "Longest word...{}" , longest_w) ;
457
- debug ! ( "Enough space to wrap..." ) ;
458
- if longest_w < avail_chars {
459
- sdebugln ! ( "Yes" ) ;
460
- let mut prev_space = 0 ;
461
- let mut j = 0 ;
462
- let mut i = 0 ;
463
- for ( idx, g) in ( & * help. clone ( ) ) . grapheme_indices ( true ) {
464
- debugln ! ( "iter;idx={},g={}" , idx, g) ;
465
- if g != " " { continue ; }
466
- if str_width ( & help[ j..idx] ) < avail_chars {
467
- debugln ! ( "Still enough space..." ) ;
468
- prev_space = idx;
469
- continue ;
470
- }
471
- debugln ! ( "Adding Newline..." ) ;
472
- j = prev_space + ( 2 * i) ;
473
- debugln ! ( "i={},prev_space={},j={}" , i, prev_space, j) ;
474
- debugln ! ( "removing: {}" , j) ;
475
- debugln ! ( "char at {}: {}" , j, & help[ j..j] ) ;
476
- help. remove ( j) ;
477
- help. insert ( j, '{' ) ;
478
- help. insert ( j + 1 , 'n' ) ;
479
- help. insert ( j + 2 , '}' ) ;
480
- i += 1 ;
481
- }
482
- } else {
483
- sdebugln ! ( "No" ) ;
484
- }
421
+ wrap_help ( & mut help, longest_w, avail_chars) ;
485
422
} else {
486
423
sdebugln ! ( "No" ) ;
487
424
}
@@ -946,24 +883,34 @@ impl<'a> Help<'a> {
946
883
}
947
884
}
948
885
949
-
950
- fn find_idx_of_space ( full : & str , mut start : usize ) -> usize {
951
- debugln ! ( "fn=find_idx_of_space;" ) ;
952
- let haystack = if full. _is_char_boundary ( start) {
953
- & full[ ..start]
954
- } else {
955
- while !full. _is_char_boundary ( start) {
956
- start -= 1 ;
957
- }
958
- & full[ ..start]
959
- } ;
960
- debugln ! ( "haystack: {}" , haystack) ;
961
- for ( i, c) in haystack. chars ( ) . rev ( ) . enumerate ( ) {
962
- debugln ! ( "iter;c={},i={}" , c, i) ;
963
- if c == ' ' {
964
- debugln ! ( "Found space returning start-i...{}" , start - ( i + 1 ) ) ;
965
- return start - ( i + 1 ) ;
886
+ fn wrap_help ( help : & mut String , longest_w : usize , avail_chars : usize ) {
887
+ debugln ! ( "fn=wrap_help;longest_w={},avail_chars={}" , longest_w, avail_chars) ;
888
+ debug ! ( "Enough space to wrap..." ) ;
889
+ if longest_w < avail_chars {
890
+ sdebugln ! ( "Yes" ) ;
891
+ let mut prev_space = 0 ;
892
+ let mut j = 0 ;
893
+ let mut i = 0 ;
894
+ for ( idx, g) in ( & * help. clone ( ) ) . grapheme_indices ( true ) {
895
+ debugln ! ( "iter;idx={},g={}" , idx, g) ;
896
+ if g != " " { continue ; }
897
+ if str_width ( & help[ j..idx + ( 2 * i) ] ) < avail_chars {
898
+ debugln ! ( "Still enough space..." ) ;
899
+ prev_space = idx;
900
+ continue ;
901
+ }
902
+ debugln ! ( "Adding Newline..." ) ;
903
+ j = prev_space + ( 2 * i) ;
904
+ debugln ! ( "i={},prev_space={},j={}" , i, prev_space, j) ;
905
+ debugln ! ( "removing: {}" , j) ;
906
+ debugln ! ( "char at {}: {}" , j, & help[ j..j] ) ;
907
+ help. remove ( j) ;
908
+ help. insert ( j, '{' ) ;
909
+ help. insert ( j + 1 , 'n' ) ;
910
+ help. insert ( j + 2 , '}' ) ;
911
+ i += 1 ;
966
912
}
913
+ } else {
914
+ sdebugln ! ( "No" ) ;
967
915
}
968
- 0
969
916
}
0 commit comments