bugstalker 0.4.5

BugStalker is a modern and lightweight debugger for rust applications.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
pub mod port;

use crate::debugger::Error;
use crate::ui::command;
use crate::ui::command::r#break::BreakpointIdentity;
use crate::ui::command::watch::WatchpointIdentity;
use crate::ui::command::{CommandError, r#break, run, watch};
use crate::ui::proto::ClientExchanger;
use crate::ui::tui::app::port::{
    AsyncResponsesPort, DebuggerEventQueue, DebuggerEventsPort, LoggerPort, OutputPort, UserEvent,
};
use crate::ui::tui::components::asm::Asm;
use crate::ui::tui::components::breakpoint::Breakpoints;
use crate::ui::tui::components::control::GlobalControl;
use crate::ui::tui::components::input::{Input, InputStringType};
use crate::ui::tui::components::logs::Logs;
use crate::ui::tui::components::oracle::make_oracle_tab_window;
use crate::ui::tui::components::output::Output;
use crate::ui::tui::components::popup::{Popup, YesNoLabels};
use crate::ui::tui::components::source::Source;
use crate::ui::tui::components::status::Status;
use crate::ui::tui::components::threads::Threads;
use crate::ui::tui::components::variables::Variables;
use crate::ui::tui::utils::logger::TuiLogLine;
use crate::ui::tui::utils::tab;
use crate::ui::tui::utils::tab::TabWindow;
use anyhow::anyhow;
use chumsky::Parser;
use log::warn;
use std::borrow::Cow;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use tuirealm::listener::SyncPort;
use tuirealm::props::{PropPayload, PropValue, TextSpan};
use tuirealm::ratatui::layout::Alignment;
use tuirealm::ratatui::layout::{Constraint, Direction, Layout};
use tuirealm::ratatui::style::Color;
use tuirealm::terminal::{CrosstermTerminalAdapter, TerminalBridge};
use tuirealm::{
    Application, AttrValue, Attribute, EventListenerCfg, Sub, SubClause, SubEventClause, props,
};

use super::{BreakpointsAddType, ConfirmedAction, DebugeeStreamBuffer, Id, Msg};

pub struct Model {
    /// Application
    pub app: Application<Id, Msg, UserEvent>,
    /// Indicates that the application must quit
    pub quit: bool,
    /// Tells whether to redraw interface
    pub redraw: bool,
    /// Used to draw to terminal
    pub terminal: TerminalBridge<CrosstermTerminalAdapter>,
    /// Message exchanger with tracer (debugger) thread
    exchanger: Arc<ClientExchanger>,
    /// Layout of main tabs
    tabs_layout: [Constraint; 2],
}

impl Model {
    const DEFAULT_TABS_LAYOUT: [Constraint; 2] =
        [Constraint::Percentage(25), Constraint::Percentage(75)];
    const LEFT_TAB_FOCUS_LAYOUT: [Constraint; 2] =
        [Constraint::Percentage(90), Constraint::Percentage(10)];
    const RIGHT_TAB_FOCUS_LAYOUT: [Constraint; 2] =
        [Constraint::Percentage(10), Constraint::Percentage(90)];

    pub fn new(
        output_buf: DebugeeStreamBuffer,
        event_queue: DebuggerEventQueue,
        client_exchanger: ClientExchanger,
        log_buffer: Arc<Mutex<Vec<TuiLogLine>>>,
    ) -> anyhow::Result<Self> {
        let exchanger = Arc::new(client_exchanger);
        Ok(Self {
            app: Self::init_app(output_buf, event_queue, exchanger.clone(), log_buffer)?,
            quit: false,
            redraw: true,
            terminal: TerminalBridge::init_crossterm().expect("Cannot initialize terminal"),
            exchanger,
            tabs_layout: Self::DEFAULT_TABS_LAYOUT,
        })
    }
}

impl Model {
    pub fn view(&mut self) {
        _ = self.terminal.raw_mut().draw(|f| {
            let input_in_focus = self.app.focus() == Some(&Id::Input);
            let popup_in_focus = self.app.focus() == Some(&Id::Popup);

            let mut constraints = vec![Constraint::Min(9), Constraint::Max(3)];
            if input_in_focus {
                constraints.push(Constraint::Max(3));
            }

            let main_chunks = Layout::default()
                .direction(Direction::Vertical)
                .margin(1)
                .constraints(constraints)
                .split(f.area());

            let tabs_rect = main_chunks[0];
            let tab_chunks = Layout::default()
                .direction(Direction::Horizontal)
                .constraints(self.tabs_layout)
                .split(tabs_rect);

            self.app.view(&Id::LeftTabs, f, tab_chunks[0]);
            self.app.view(&Id::RightTabs, f, tab_chunks[1]);

            if input_in_focus {
                self.app.view(&Id::Input, f, main_chunks[1]);
                self.app.view(&Id::Status, f, main_chunks[2]);
            } else {
                self.app.view(&Id::Status, f, main_chunks[1]);
            }

            if popup_in_focus {
                self.app.view(&Id::Popup, f, f.area());
            }
        });
    }

    fn init_app(
        output_buf: DebugeeStreamBuffer,
        event_queue: DebuggerEventQueue,
        exchanger: Arc<ClientExchanger>,
        log_buffer: Arc<Mutex<Vec<TuiLogLine>>>,
    ) -> anyhow::Result<Application<Id, Msg, UserEvent>> {
        let mut app: Application<Id, Msg, UserEvent> = Application::init(
            EventListenerCfg::default()
                .crossterm_input_listener(Duration::from_millis(20), 3)
                .port(SyncPort::new(
                    Box::new(OutputPort::new(output_buf.data.clone())),
                    Duration::from_millis(10),
                    1,
                ))
                .port(SyncPort::new(
                    Box::new(DebuggerEventsPort::new(event_queue)),
                    Duration::from_millis(10),
                    1,
                ))
                .port(SyncPort::new(
                    Box::new(AsyncResponsesPort::new(exchanger.clone())),
                    Duration::from_millis(10),
                    1,
                ))
                .port(SyncPort::new(
                    Box::new(LoggerPort::new(log_buffer)),
                    Duration::from_millis(10),
                    1,
                ))
                .poll_timeout(Duration::from_millis(10))
                .tick_interval(Duration::from_millis(200)),
        );

        let pid = exchanger
            .request_sync(|dbg| dbg.process().pid())
            .expect("messaging enabled at tui start");
        app.mount(
            Id::GlobalControl,
            Box::new(GlobalControl::new(exchanger.clone(), pid)),
            GlobalControl::subscriptions(),
        )?;

        app.mount(Id::Popup, Box::<Popup>::default(), vec![])?;
        app.mount(Id::Input, Box::<Input>::default(), vec![])?;

        let mb_err = exchanger
            .request_sync(|dbg| run::Handler::new(dbg).handle(run::Command::DryStart))
            .expect("messaging enabled at tui start");
        let already_run = matches!(mb_err.err(), Some(CommandError::Handle(Error::AlreadyRun)));

        let output = output_buf.data.lock().unwrap().clone();
        let oracles: Vec<_> = exchanger
            .request_sync(|dbg| dbg.all_oracles_arc().collect())
            .expect("messaging enabled at tui start");

        app.mount(
            Id::Status,
            Box::new(Status::new(already_run)),
            Status::subscriptions(),
        )?;

        let mut left_tab_sub = Variables::subscriptions();
        left_tab_sub.extend(Threads::subscriptions());
        left_tab_sub.extend(vec![Sub::new(SubEventClause::Tick, SubClause::Always)]);

        let left_tab = TabWindow::new(
            "[1]",
            &["🔴 Breakpoints", "🧩 Variables", "🧵 Threads"],
            vec![
                Box::new(Breakpoints::new(exchanger.clone())),
                Box::new(Variables::new(exchanger.clone())),
                Box::new(Threads::new(exchanger.clone())),
            ],
            Some(|rewind_direction| match rewind_direction {
                tuirealm::command::Direction::Left => Msg::RightTabsInFocus {
                    reset_to: Some(props::Direction::Right),
                },
                tuirealm::command::Direction::Right => Msg::RightTabsInFocus {
                    reset_to: Some(props::Direction::Left),
                },
                _ => {
                    unreachable!()
                }
            }),
        );
        app.mount(Id::LeftTabs, Box::new(left_tab), left_tab_sub)?;

        let mut right_tab_sub = Source::subscriptions();
        right_tab_sub.extend(Asm::subscriptions());
        right_tab_sub.extend(Output::subscriptions());
        right_tab_sub.extend(vec![Sub::new(SubEventClause::Tick, SubClause::Always)]);

        let right_tab = TabWindow::new(
            "[2]",
            &["</> Source", "📃 Output", "🤖 Asm", "🔮 Oracles", "💾 Logs"],
            vec![
                Box::new(Source::new(exchanger.clone())?),
                Box::new(Output::new(&output)),
                Box::new(Asm::new(exchanger.clone())?),
                Box::new(make_oracle_tab_window(&oracles)),
                Box::<Logs>::default(),
            ],
            Some(|rewind_direction| match rewind_direction {
                tuirealm::command::Direction::Left => Msg::LeftTabsInFocus {
                    reset_to: Some(props::Direction::Right),
                },
                tuirealm::command::Direction::Right => Msg::LeftTabsInFocus {
                    reset_to: Some(props::Direction::Left),
                },
                _ => {
                    unreachable!()
                }
            }),
        );
        app.mount(Id::RightTabs, Box::new(right_tab), right_tab_sub)?;

        app.active(&Id::LeftTabs)?;

        Ok(app)
    }
}

impl Model {
    fn update_breakpoints(&mut self) -> anyhow::Result<()> {
        Ok(self.app.attr(
            &Id::LeftTabs,
            Attribute::Custom("update_breakpoints"),
            AttrValue::Flag(true),
        )?)
    }

    pub fn update(&mut self, msg: Option<Msg>) -> anyhow::Result<Option<Msg>> {
        if let Some(msg) = msg {
            // Set redraw
            self.redraw = true;
            // Match message
            match msg {
                Msg::AppClose => {
                    self.exchanger.send_exit();
                    self.quit = true;
                }
                Msg::AppRunning => {
                    self.app.attr(
                        &Id::Status,
                        Attribute::Text,
                        AttrValue::Payload(PropPayload::Vec(vec![PropValue::TextSpan(
                            TextSpan::new("running").fg(Color::Red),
                        )])),
                    )?;
                }
                Msg::SwitchUI => {
                    self.exchanger.send_switch_ui();
                    self.quit = true;
                }
                Msg::LeftTabsInFocus { reset_to } => {
                    self.app.active(&Id::LeftTabs)?;
                    if let Some(direction) = reset_to {
                        self.app.attr(
                            &Id::LeftTabs,
                            TabWindow::RESET_CHOICE_ATTR,
                            AttrValue::Direction(direction),
                        )?;
                    }
                    // change the focus again to prevent the situation
                    // when the focus was removed
                    // when call active for an already active component
                    _ = self
                        .app
                        .attr(&Id::LeftTabs, Attribute::Focus, AttrValue::Flag(true));
                }
                Msg::RightTabsInFocus { reset_to } => {
                    self.app.active(&Id::RightTabs)?;
                    if let Some(direction) = reset_to {
                        self.app.attr(
                            &Id::RightTabs,
                            TabWindow::RESET_CHOICE_ATTR,
                            AttrValue::Direction(direction),
                        )?;
                    }
                    // change the focus again to prevent the situation
                    // when the focus was removed
                    // when call active for an already active component
                    _ = self
                        .app
                        .attr(&Id::RightTabs, Attribute::Focus, AttrValue::Flag(true));
                }
                Msg::BreakpointAdd(r#type) => {
                    if !self.exchanger.is_messaging_enabled() {
                        warn!(target: "tui", "trying to add breakpoint but messaging is disabled");
                        return Ok(None);
                    }

                    let (input_validator, input_data_type): (fn(&str) -> bool, _) = match r#type {
                        BreakpointsAddType::AtLine => (
                            |s| -> bool {
                                command::parser::brkpt_at_line_parser()
                                    .parse(s)
                                    .into_result()
                                    .is_ok()
                            },
                            InputStringType::BreakpointAddAtLine,
                        ),
                        BreakpointsAddType::AtFunction => (
                            |s| -> bool {
                                command::parser::brkpt_at_fn()
                                    .parse(s)
                                    .into_result()
                                    .is_ok()
                            },
                            InputStringType::BreakpointAddAtFunction,
                        ),
                        BreakpointsAddType::AtAddress => (
                            |s| -> bool {
                                command::parser::brkpt_at_addr_parser()
                                    .parse(s)
                                    .into_result()
                                    .is_ok()
                            },
                            InputStringType::BreakpointAddAtAddress,
                        ),
                        BreakpointsAddType::Watchpoint => (
                            |s| -> bool {
                                command::parser::watchpoint_cond()
                                    .then(
                                        command::parser::watchpoint_at_dqe()
                                            .or(command::parser::watchpoint_at_address()),
                                    )
                                    .parse(s)
                                    .into_result()
                                    .is_ok()
                            },
                            InputStringType::Watchpoint,
                        ),
                    };

                    let title = if matches!(r#type, BreakpointsAddType::Watchpoint) {
                        "Add watchpoint".to_string()
                    } else {
                        "Add breakpoint".to_string()
                    };

                    self.app.attr(
                        &Id::Input,
                        Attribute::InputType,
                        AttrValue::InputType(props::InputType::Custom(
                            input_validator,
                            |_, _| -> bool { true },
                        )),
                    )?;
                    self.app.attr(
                        &Id::Input,
                        Attribute::Title,
                        AttrValue::Title((title, Alignment::Left)),
                    )?;
                    self.app.attr(
                        &Id::Input,
                        Attribute::Custom("input_data_type"),
                        AttrValue::String(input_data_type.to_string()),
                    )?;

                    self.app.active(&Id::Input)?;
                    self.app.lock_subs();
                }
                Msg::Input(input) => {
                    let input_data_type = InputStringType::from_str(
                        &self
                            .app
                            .query(&Id::Input, Attribute::Custom("input_data_type"))?
                            .expect("infallible")
                            .unwrap_string(),
                    )
                    .expect("infallible");
                    return match input_data_type {
                        InputStringType::BreakpointAddAtFunction
                        | InputStringType::BreakpointAddAtLine
                        | InputStringType::BreakpointAddAtAddress => {
                            let identity = match input_data_type {
                                InputStringType::BreakpointAddAtLine => {
                                    let file_line: Vec<_> = input.split(':').collect();
                                    let file = file_line[0];
                                    let line: u64 = file_line[1].parse().expect("infallible");
                                    BreakpointIdentity::Line(file.to_string(), line)
                                }
                                InputStringType::BreakpointAddAtFunction => {
                                    BreakpointIdentity::Function(input.trim().to_string())
                                }
                                InputStringType::BreakpointAddAtAddress => {
                                    let input = input.trim().to_lowercase();
                                    let hex = input
                                        .strip_prefix("0x")
                                        .ok_or(anyhow!("invalid hex format"))?;
                                    let addr = usize::from_str_radix(hex, 16)
                                        .map_err(|e| anyhow!("invalid hex format: {e}"))?;
                                    BreakpointIdentity::Address(addr)
                                }
                                _ => unreachable!(),
                            };

                            let cmd = r#break::Command::Add(identity);
                            self.exchanger
                                .request_sync(move |dbg| -> anyhow::Result<()> {
                                    command::r#break::Handler::new(dbg).handle(&cmd)?;
                                    Ok(())
                                })
                                .expect("messaging enabled")?;

                            self.app.unlock_subs();
                            self.app.blur()?;
                            self.update_breakpoints()?;
                            self.app.active(&Id::LeftTabs)?;
                            self.app.attr(
                                &Id::LeftTabs,
                                TabWindow::ACTIVATE_TAB,
                                AttrValue::Flag(true),
                            )?;
                            Ok(None)
                        }
                        InputStringType::Watchpoint => {
                            // TODO two times parsing
                            let (cond, identity) = command::parser::watchpoint_cond()
                                .then(
                                    command::parser::watchpoint_at_dqe()
                                        .or(command::parser::watchpoint_at_address()),
                                )
                                .parse(&input)
                                .into_result()
                                .expect("infallible");
                            let cmd = watch::Command::Add(identity, cond);
                            self.exchanger
                                .request_sync(move |dbg| -> anyhow::Result<()> {
                                    command::watch::Handler::new(dbg).handle(cmd)?;
                                    Ok(())
                                })
                                .expect("messaging enabled")?;

                            self.app.unlock_subs();
                            self.app.blur()?;
                            self.update_breakpoints()?;
                            self.app.active(&Id::LeftTabs)?;
                            self.app.attr(
                                &Id::LeftTabs,
                                TabWindow::ACTIVATE_TAB,
                                AttrValue::Flag(true),
                            )?;
                            Ok(None)
                        }
                    };
                }
                Msg::InputCancel => {
                    self.app.unlock_subs();
                    self.app.blur()?;
                    self.update_breakpoints()?;
                    // FIXME: currently input cancel are possible only from breakpoints window,
                    // that's why breakpoints window come into focus here.
                    // This behaviour may be changed in future.
                    self.app.active(&Id::LeftTabs)?;
                    self.app.attr(
                        &Id::LeftTabs,
                        TabWindow::ACTIVATE_TAB,
                        AttrValue::Flag(true),
                    )?;
                }
                Msg::UpdateBreakpointList => {
                    self.update_breakpoints()?;
                }
                Msg::ShowOkPopup(title, text) => {
                    if let Some(title) = title {
                        self.app
                            .attr(&Id::Popup, Attribute::Title, AttrValue::String(title))?;
                    }
                    self.app
                        .attr(&Id::Popup, Attribute::Text, AttrValue::String(text))?;
                    let (ok_attr, ok_attr_val) = Popup::ok_attrs();
                    self.app.attr(&Id::Popup, ok_attr, ok_attr_val)?;
                    self.app.active(&Id::Popup)?;
                }
                Msg::PopupOk => {
                    self.app.blur()?;
                }
                Msg::PopupConfirmDebuggerRestart => {
                    self.app.attr(
                        &Id::Popup,
                        Attribute::Text,
                        AttrValue::String("Restart a program?".to_string()),
                    )?;
                    let (attr, attr_val) = Popup::yes_no_attrs(YesNoLabels::default());
                    self.app.attr(&Id::Popup, attr, attr_val)?;
                    let action = ConfirmedAction::Restart;
                    self.app.attr(
                        &Id::Popup,
                        Attribute::Custom("action"),
                        AttrValue::String(action.to_string()),
                    )?;
                    self.app.active(&Id::Popup)?;
                }
                Msg::PopupBreakpoint(brkpt) => {
                    let place = &brkpt.place;
                    let file = place
                        .as_ref()
                        .map(|p| p.file.to_string_lossy())
                        .unwrap_or(Cow::from("unknown"));
                    let line = place
                        .as_ref()
                        .map(|p| p.line_number.to_string())
                        .unwrap_or("unknown".to_string());
                    let text = format!(
                        "Breakpoint #{}\nAt: {:?}:{}\nAddress: {}",
                        brkpt.number, file, line, brkpt.addr
                    );

                    self.app
                        .attr(&Id::Popup, Attribute::Text, AttrValue::String(text))?;
                    let (attr, attr_val) = Popup::yes_no_attrs(YesNoLabels::new("OK", "Remove"));
                    self.app.attr(&Id::Popup, attr, attr_val)?;
                    self.app.attr(
                        &Id::Popup,
                        Attribute::Custom("action"),
                        AttrValue::String(ConfirmedAction::RemoveBreakpoint.to_string()),
                    )?;
                    self.app.active(&Id::Popup)?;
                }
                Msg::PopupWatchpoint(wp) => {
                    let dqe = if let Some(ref dqe) = wp.source_dqe {
                        format!("For: {dqe}\n")
                    } else {
                        String::new()
                    };

                    let text = format!(
                        "Watchpoint #{}\n{dqe}Address: {}\nCondition: {}, size: {}",
                        wp.number, wp.address, wp.condition, wp.size
                    );

                    self.app
                        .attr(&Id::Popup, Attribute::Text, AttrValue::String(text))?;
                    let (attr, attr_val) = Popup::yes_no_attrs(YesNoLabels::new("OK", "Remove"));
                    self.app.attr(&Id::Popup, attr, attr_val)?;
                    self.app.attr(
                        &Id::Popup,
                        Attribute::Custom("action"),
                        AttrValue::String(ConfirmedAction::RemoveWatchpoint.to_string()),
                    )?;
                    self.app.active(&Id::Popup)?;
                }
                Msg::PopupYes(action) => match action {
                    ConfirmedAction::Restart => {
                        self.exchanger
                            .request_async(|dbg| {
                                Ok(run::Handler::new(dbg).handle(run::Command::Restart)?)
                            })
                            .expect("messaging enabled");
                        self.exchanger.disable_messaging();
                        self.app.blur()?;
                        return Ok(Some(Msg::AppRunning));
                    }
                    _ => {
                        self.app.blur()?;
                    }
                },
                Msg::PopupNo(action) => match action {
                    ConfirmedAction::RemoveBreakpoint => {
                        // the left tab must contain a breakpoints as active window
                        let brkpt_num = self.app.state(&Id::LeftTabs)?.unwrap_one().unwrap_u32();
                        self.exchanger
                            .request_sync(move |dbg| -> anyhow::Result<()> {
                                let cmd =
                                    r#break::Command::Remove(BreakpointIdentity::Number(brkpt_num));
                                command::r#break::Handler::new(dbg).handle(&cmd)?;
                                Ok(())
                            })
                            .expect("messaging enabled")?;
                        self.app.blur()?;
                        self.update_breakpoints()?;
                    }
                    ConfirmedAction::RemoveWatchpoint => {
                        // the left tab must contain a watchpoint as active window
                        let wp_num = self.app.state(&Id::LeftTabs)?.unwrap_one().unwrap_u32();
                        self.exchanger
                            .request_sync(move |dbg| -> anyhow::Result<()> {
                                let cmd =
                                    watch::Command::Remove(WatchpointIdentity::Number(wp_num));
                                command::watch::Handler::new(dbg).handle(cmd)?;
                                Ok(())
                            })
                            .expect("messaging enabled")?;
                        self.app.blur()?;
                        self.update_breakpoints()?;
                    }
                    _ => {
                        self.app.blur()?;
                    }
                },
                Msg::ExpandTab(tab_id) => {
                    debug_assert!(tab_id == Id::RightTabs || tab_id == Id::LeftTabs);
                    match tab_id {
                        Id::RightTabs
                            if self.tabs_layout == Self::DEFAULT_TABS_LAYOUT
                                || self.tabs_layout == Self::LEFT_TAB_FOCUS_LAYOUT =>
                        {
                            self.app.attr(
                                &Id::RightTabs,
                                TabWindow::VIEW_SIZE_ATTR,
                                tab::ViewSize::Expand.into(),
                            )?;
                            self.app.attr(
                                &Id::LeftTabs,
                                TabWindow::VIEW_SIZE_ATTR,
                                tab::ViewSize::Compacted.into(),
                            )?;

                            self.tabs_layout = Self::RIGHT_TAB_FOCUS_LAYOUT;
                        }
                        Id::LeftTabs
                            if self.tabs_layout == Self::DEFAULT_TABS_LAYOUT
                                || self.tabs_layout == Self::RIGHT_TAB_FOCUS_LAYOUT =>
                        {
                            self.app.attr(
                                &Id::LeftTabs,
                                TabWindow::VIEW_SIZE_ATTR,
                                tab::ViewSize::Expand.into(),
                            )?;
                            self.app.attr(
                                &Id::RightTabs,
                                TabWindow::VIEW_SIZE_ATTR,
                                tab::ViewSize::Compacted.into(),
                            )?;

                            self.tabs_layout = Self::LEFT_TAB_FOCUS_LAYOUT;
                        }
                        _ => {
                            for id in [&Id::LeftTabs, &Id::RightTabs] {
                                self.app.attr(
                                    id,
                                    TabWindow::VIEW_SIZE_ATTR,
                                    tab::ViewSize::Default.into(),
                                )?;
                            }
                            self.tabs_layout = Self::DEFAULT_TABS_LAYOUT;
                        }
                    }
                }

                Msg::None => {}
            }
        }

        Ok(None)
    }
}