@@ -367,23 +367,23 @@ class Window {
367
367
}
368
368
void Clear () { ::wclear (m_window); }
369
369
void Erase () { ::werase (m_window); }
370
- Rect GetBounds () {
370
+ Rect GetBounds () const {
371
371
return Rect (GetParentOrigin (), GetSize ());
372
372
} // Get the rectangle in our parent window
373
373
int GetChar () { return ::wgetch (m_window); }
374
- int GetCursorX () { return getcurx (m_window); }
375
- int GetCursorY () { return getcury (m_window); }
376
- Rect GetFrame () {
374
+ int GetCursorX () const { return getcurx (m_window); }
375
+ int GetCursorY () const { return getcury (m_window); }
376
+ Rect GetFrame () const {
377
377
return Rect (Point (), GetSize ());
378
378
} // Get our rectangle in our own coordinate system
379
- Point GetParentOrigin () { return Point (GetParentX (), GetParentY ()); }
380
- Size GetSize () { return Size (GetWidth (), GetHeight ()); }
381
- int GetParentX () { return getparx (m_window); }
382
- int GetParentY () { return getpary (m_window); }
383
- int GetMaxX () { return getmaxx (m_window); }
384
- int GetMaxY () { return getmaxy (m_window); }
385
- int GetWidth () { return GetMaxX (); }
386
- int GetHeight () { return GetMaxY (); }
379
+ Point GetParentOrigin () const { return Point (GetParentX (), GetParentY ()); }
380
+ Size GetSize () const { return Size (GetWidth (), GetHeight ()); }
381
+ int GetParentX () const { return getparx (m_window); }
382
+ int GetParentY () const { return getpary (m_window); }
383
+ int GetMaxX () const { return getmaxx (m_window); }
384
+ int GetMaxY () const { return getmaxy (m_window); }
385
+ int GetWidth () const { return GetMaxX (); }
386
+ int GetHeight () const { return GetMaxY (); }
387
387
void MoveCursor (int x, int y) { ::wmove (m_window, y, x); }
388
388
void MoveWindow (int x, int y) { MoveWindow (Point (x, y)); }
389
389
void Resize (int w, int h) { ::wresize (m_window, h, w); }
@@ -396,7 +396,7 @@ class Window {
396
396
::wbkgd (m_window, COLOR_PAIR(color_pair_idx));
397
397
}
398
398
399
- void PutCStringTruncated (const char *s, int right_pad ) {
399
+ void PutCStringTruncated (int right_pad, const char *s) {
400
400
int bytes_left = GetWidth () - GetCursorX ();
401
401
if (bytes_left > right_pad) {
402
402
bytes_left -= right_pad;
@@ -438,6 +438,20 @@ class Window {
438
438
va_end (args);
439
439
}
440
440
441
+ void PrintfTruncated (int right_pad, const char *format, ...)
442
+ __attribute__((format(printf, 3 , 4 ))) {
443
+ va_list args;
444
+ va_start (args, format);
445
+ StreamString strm;
446
+ strm.PrintfVarArg (format, args);
447
+ va_end (args);
448
+ PutCStringTruncated (right_pad, strm.GetData ());
449
+ }
450
+
451
+ size_t LimitLengthToRestOfLine (size_t length) const {
452
+ return std::min<size_t >(length, std::max (0 , GetWidth () - GetCursorX () - 1 ));
453
+ }
454
+
441
455
void Touch () {
442
456
::touchwin (m_window);
443
457
if (m_parent)
@@ -553,7 +567,7 @@ class Window {
553
567
} else {
554
568
MoveCursor (1 , GetHeight () - 1 );
555
569
PutChar (' [' );
556
- PutCStringTruncated (bottom_message, 1 );
570
+ PutCStringTruncated (1 , bottom_message );
557
571
}
558
572
}
559
573
if (attr)
@@ -1911,7 +1925,7 @@ class FrameTreeDelegate : public TreeDelegate {
1911
1925
if (FormatEntity::Format (m_format, strm, &sc, &exe_ctx, nullptr ,
1912
1926
nullptr , false , false )) {
1913
1927
int right_pad = 1 ;
1914
- window.PutCStringTruncated (strm.GetString ().str ().c_str (), right_pad );
1928
+ window.PutCStringTruncated (right_pad, strm.GetString ().str ().c_str ());
1915
1929
}
1916
1930
}
1917
1931
}
@@ -1970,7 +1984,7 @@ class ThreadTreeDelegate : public TreeDelegate {
1970
1984
if (FormatEntity::Format (m_format, strm, nullptr , &exe_ctx, nullptr ,
1971
1985
nullptr , false , false )) {
1972
1986
int right_pad = 1 ;
1973
- window.PutCStringTruncated (strm.GetString ().str ().c_str (), right_pad );
1987
+ window.PutCStringTruncated (right_pad, strm.GetString ().str ().c_str ());
1974
1988
}
1975
1989
}
1976
1990
}
@@ -2060,7 +2074,7 @@ class ThreadsTreeDelegate : public TreeDelegate {
2060
2074
if (FormatEntity::Format (m_format, strm, nullptr , &exe_ctx, nullptr ,
2061
2075
nullptr , false , false )) {
2062
2076
int right_pad = 1 ;
2063
- window.PutCStringTruncated (strm.GetString ().str ().c_str (), right_pad );
2077
+ window.PutCStringTruncated (right_pad, strm.GetString ().str ().c_str ());
2064
2078
}
2065
2079
}
2066
2080
}
@@ -2363,29 +2377,29 @@ class ValueObjectListDelegate : public WindowDelegate {
2363
2377
window.AttributeOn (A_REVERSE);
2364
2378
2365
2379
if (type_name && type_name[0 ])
2366
- window.Printf ( " (%s) " , type_name);
2380
+ window.PrintfTruncated ( 1 , " (%s) " , type_name);
2367
2381
2368
2382
if (name && name[0 ])
2369
- window.PutCString ( name);
2383
+ window.PutCStringTruncated ( 1 , name);
2370
2384
2371
2385
attr_t changd_attr = 0 ;
2372
2386
if (valobj->GetValueDidChange ())
2373
2387
changd_attr = COLOR_PAIR (5 ) | A_BOLD;
2374
2388
2375
2389
if (value && value[0 ]) {
2376
- window.PutCString ( " = " );
2390
+ window.PutCStringTruncated ( 1 , " = " );
2377
2391
if (changd_attr)
2378
2392
window.AttributeOn (changd_attr);
2379
- window.PutCString ( value);
2393
+ window.PutCStringTruncated ( 1 , value);
2380
2394
if (changd_attr)
2381
2395
window.AttributeOff (changd_attr);
2382
2396
}
2383
2397
2384
2398
if (summary && summary[0 ]) {
2385
- window.PutChar ( ' ' );
2399
+ window.PutCStringTruncated ( 1 , " " );
2386
2400
if (changd_attr)
2387
2401
window.AttributeOn (changd_attr);
2388
- window.PutCString ( summary);
2402
+ window.PutCStringTruncated ( 1 , summary);
2389
2403
if (changd_attr)
2390
2404
window.AttributeOff (changd_attr);
2391
2405
}
@@ -2823,7 +2837,7 @@ bool HelpDialogDelegate::WindowDelegateDraw(Window &window, bool force) {
2823
2837
while (y <= max_y) {
2824
2838
window.MoveCursor (x, y);
2825
2839
window.PutCStringTruncated (
2826
- m_text.GetStringAtIndex (m_first_visible_line + y - min_y), 1 );
2840
+ 1 , m_text.GetStringAtIndex (m_first_visible_line + y - min_y));
2827
2841
++y;
2828
2842
}
2829
2843
return true ;
@@ -3251,7 +3265,7 @@ class StatusBarWindowDelegate : public WindowDelegate {
3251
3265
if (thread && FormatEntity::Format (m_format, strm, nullptr , &exe_ctx,
3252
3266
nullptr , nullptr , false , false )) {
3253
3267
window.MoveCursor (40 , 0 );
3254
- window.PutCStringTruncated (strm.GetString ().str ().c_str (), 1 );
3268
+ window.PutCStringTruncated (1 , strm.GetString ().str ().c_str ());
3255
3269
}
3256
3270
3257
3271
window.MoveCursor (60 , 0 );
@@ -3477,7 +3491,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
3477
3491
window.AttributeOn (A_REVERSE);
3478
3492
window.MoveCursor (1 , 1 );
3479
3493
window.PutChar (' ' );
3480
- window.PutCStringTruncated (m_title.GetString ().str ().c_str (), 1 );
3494
+ window.PutCStringTruncated (1 , m_title.GetString ().str ().c_str ());
3481
3495
int x = window.GetCursorX ();
3482
3496
if (x < window_width - 1 ) {
3483
3497
window.Printf (" %*s" , window_width - x - 1 , " " );
@@ -3549,8 +3563,8 @@ class SourceFileWindowDelegate : public WindowDelegate {
3549
3563
3550
3564
if (highlight_attr)
3551
3565
window.AttributeOn (highlight_attr);
3552
- const uint32_t line_len =
3553
- m_file_sp->GetLineLength (curr_line + 1 , false );
3566
+ const uint32_t line_len = window. LimitLengthToRestOfLine (
3567
+ m_file_sp->GetLineLength (curr_line + 1 , false )) ;
3554
3568
if (line_len > 0 )
3555
3569
window.PutCString (m_file_sp->PeekLineData (curr_line + 1 ), line_len);
3556
3570
@@ -3564,11 +3578,12 @@ class SourceFileWindowDelegate : public WindowDelegate {
3564
3578
if (stop_description && stop_description[0 ]) {
3565
3579
size_t stop_description_len = strlen (stop_description);
3566
3580
int desc_x = window_width - stop_description_len - 16 ;
3567
- window.Printf (" %*s" , desc_x - window.GetCursorX (), " " );
3568
- // window.MoveCursor(window_width - stop_description_len - 15,
3569
- // line_y);
3570
- window.Printf (" <<< Thread %u: %s " , thread->GetIndexID (),
3571
- stop_description);
3581
+ if (desc_x - window.GetCursorX () > 0 )
3582
+ window.Printf (" %*s" , desc_x - window.GetCursorX (), " " );
3583
+ window.MoveCursor (window_width - stop_description_len - 15 ,
3584
+ line_y);
3585
+ window.PrintfTruncated (1 , " <<< Thread %u: %s " ,
3586
+ thread->GetIndexID (), stop_description);
3572
3587
}
3573
3588
} else {
3574
3589
window.Printf (" %*s" , window_width - window.GetCursorX () - 1 , " " );
@@ -3699,7 +3714,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
3699
3714
strm.Printf (" %s" , mnemonic);
3700
3715
3701
3716
int right_pad = 1 ;
3702
- window.PutCStringTruncated (strm.GetData (), right_pad );
3717
+ window.PutCStringTruncated (right_pad, strm.GetData ());
3703
3718
3704
3719
if (is_pc_line && frame_sp &&
3705
3720
frame_sp->GetConcreteFrameIndex () == 0 ) {
@@ -3711,11 +3726,12 @@ class SourceFileWindowDelegate : public WindowDelegate {
3711
3726
if (stop_description && stop_description[0 ]) {
3712
3727
size_t stop_description_len = strlen (stop_description);
3713
3728
int desc_x = window_width - stop_description_len - 16 ;
3714
- window.Printf (" %*s" , desc_x - window.GetCursorX (), " " );
3715
- // window.MoveCursor(window_width - stop_description_len - 15,
3716
- // line_y);
3717
- window.Printf (" <<< Thread %u: %s " , thread->GetIndexID (),
3718
- stop_description);
3729
+ if (desc_x - window.GetCursorX () > 0 )
3730
+ window.Printf (" %*s" , desc_x - window.GetCursorX (), " " );
3731
+ window.MoveCursor (window_width - stop_description_len - 15 ,
3732
+ line_y);
3733
+ window.PrintfTruncated (1 , " <<< Thread %u: %s " ,
3734
+ thread->GetIndexID (), stop_description);
3719
3735
}
3720
3736
} else {
3721
3737
window.Printf (" %*s" , window_width - window.GetCursorX () - 1 , " " );
0 commit comments