Skip to content

Commit 8a38105

Browse files
committed
Improve shutdown behavior
- Flush messages to data channel when closing connection - Show cursor in admin interface only on shutdown (fixes #36) - Shutdown when trying to open admin interface in invalid context (fixes #35)
1 parent 7c17261 commit 8a38105

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+177
-85
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
### Fixed
66

77
- Improve logic for SSH exec commands.
8+
- Flush messages to data channel when closing connection.
9+
- Show cursor in admin interface only on shutdown.
810

911
### Changed
1012

1113
- Update dependencies.
14+
- **BREAKING**: Shutdown when trying to open admin interface in invalid context.
1215

1316
## 0.4.0 (2025-02-11)
1417

Cargo.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ chrono = "0.4.39"
2222
clap = { version = "4.5.30", features = ["derive", "string"] }
2323
crossterm = "0.28.1"
2424
dashmap = "6.1.0"
25+
enumflags2 = "0.7.11"
2526
env_logger = "0.11.6"
2627
hickory-resolver = "0.24.4"
2728
http = "1.2.0"

src/admin.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use human_bytes::human_bytes;
1010
use itertools::Itertools;
1111
use ratatui::{
1212
buffer::Buffer,
13-
layout::{Constraint, Flex, Layout, Margin, Rect},
13+
layout::{Constraint, Flex, Layout, Margin, Position, Rect},
1414
prelude::CrosstermBackend,
1515
style::{Color, Modifier, Style, Stylize},
1616
symbols::border,
@@ -140,6 +140,8 @@ enum AdminPrompt {
140140
struct AdminState {
141141
// Reference to the server for collecting data and interacting with user keys.
142142
server: Arc<SandholeServer>,
143+
// Whether data should be rendered to the terminal.
144+
enabled: bool,
143145
// Whether this is rendered in a pseudo-terminal or not.
144146
is_pty: bool,
145147
// Currently selected tab.
@@ -568,6 +570,7 @@ impl AdminInterface {
568570
terminal: Terminal::with_options(backend, options).unwrap(),
569571
state: AdminState {
570572
server,
573+
enabled: true,
571574
tab: TabData { tabs, current: 0 },
572575
is_pty: false,
573576
table_state: Default::default(),
@@ -582,14 +585,17 @@ impl AdminInterface {
582585
{
583586
let mut interface = interface.lock().unwrap();
584587
let AdminTerminal { terminal, state } = interface.deref_mut();
585-
terminal
586-
.draw(|frame| {
587-
// Render the terminal
588-
state.render(frame.area(), frame.buffer_mut());
589-
// Update the cursor position (avoids cursor from disappearing on disconnect)
590-
frame.set_cursor_position((0, 0));
591-
})
592-
.unwrap();
588+
if state.enabled {
589+
if terminal
590+
.draw(|frame| {
591+
// Render the terminal
592+
state.render(frame.area(), frame.buffer_mut());
593+
})
594+
.is_err()
595+
{
596+
break;
597+
}
598+
}
593599
}
594600
// Wait one second or for an user-generated event to refresh the interface
595601
tokio::select! {
@@ -906,4 +912,13 @@ impl AdminInterface {
906912
let _ = self.change_notifier.send(());
907913
}
908914
}
915+
916+
// Disable updates to the terminal for shutdown
917+
pub(crate) fn disable(&mut self) {
918+
let mut interface = self.interface.lock().unwrap();
919+
let _ = interface.terminal.show_cursor();
920+
let _ = interface.terminal.set_cursor_position(Position::ORIGIN);
921+
let _ = interface.terminal.flush();
922+
interface.state.enabled = false;
923+
}
909924
}

0 commit comments

Comments
 (0)