Skip to content

Commit 99c4860

Browse files
authored
feat(terminal): share terminal size constants across kernel and stream processing (#418)
Creates a new `terminal_size` module with shared constants: - TERMINAL_COLUMNS: 80 (consistent with classic terminal width) - TERMINAL_LINES: 100 Sets COLUMNS and LINES environment variables on all kernel launches so that subprocesses (IPython, shell commands, etc.) format output to the same width as our stream terminal emulator processes it. This ensures consistent output formatting and makes it easier to display side-by-side on typical displays. Also updates stream_terminal.rs to use the shared constants instead of local 128-column default.
1 parent d59a31f commit 99c4860

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

crates/runtimed/src/kernel_manager.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::notebook_sync_server::persist_notebook_bytes;
3232
use crate::output_store::{self, DEFAULT_INLINE_THRESHOLD};
3333
use crate::protocol::{CompletionItem, HistoryEntry, NotebookBroadcast};
3434
use crate::stream_terminal::{StreamOutputState, StreamTerminals};
35+
use crate::terminal_size::{TERMINAL_COLUMNS_STR, TERMINAL_LINES_STR};
3536
use crate::PooledEnv;
3637

3738
// ── Launched Environment Config ─────────────────────────────────────────────
@@ -643,6 +644,10 @@ impl RoomKernel {
643644
};
644645
cmd.current_dir(&cwd);
645646

647+
// Set terminal size for consistent output formatting
648+
cmd.env("COLUMNS", TERMINAL_COLUMNS_STR);
649+
cmd.env("LINES", TERMINAL_LINES_STR);
650+
646651
#[cfg(unix)]
647652
cmd.process_group(0);
648653

crates/runtimed/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub mod singleton;
3535
pub mod stream_terminal;
3636
pub mod sync_client;
3737
pub mod sync_server;
38+
pub mod terminal_size;
3839

3940
// ============================================================================
4041
// Development Mode and Worktree Isolation

crates/runtimed/src/stream_terminal.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ use alacritty_terminal::term::Config;
1616
use alacritty_terminal::vte::ansi::{Color, NamedColor, Processor, Rgb};
1717
use alacritty_terminal::Term;
1818

19-
/// Default terminal width in columns.
20-
const DEFAULT_COLUMNS: usize = 128;
21-
22-
/// Default terminal height in lines.
23-
/// We use a small height since we don't need scrollback for notebook outputs.
24-
const DEFAULT_LINES: usize = 100;
19+
use crate::terminal_size::{TERMINAL_COLUMNS, TERMINAL_LINES};
2520

2621
/// Maximum scrollback history.
2722
/// Keep minimal since notebook outputs don't need scrollback.
@@ -117,7 +112,7 @@ impl StreamTerminals {
117112
scrolling_history: SCROLLBACK_HISTORY,
118113
..Config::default()
119114
};
120-
let dimensions = TermDimensions::new(DEFAULT_COLUMNS, DEFAULT_LINES);
115+
let dimensions = TermDimensions::new(TERMINAL_COLUMNS, TERMINAL_LINES);
121116
Term::new(config, &dimensions, VoidListener)
122117
});
123118

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Terminal size constants for kernel output.
2+
//!
3+
//! These constants define the terminal dimensions used for:
4+
//! 1. Kernel environment variables (COLUMNS, LINES) - what subprocesses see
5+
//! 2. Stream terminal emulation - how we process escape sequences
6+
//!
7+
//! Using 80 columns provides good compatibility with side-by-side window layouts
8+
//! on typical displays. Both values should match to ensure consistent output
9+
//! formatting between what the kernel produces and how we render it.
10+
11+
/// Terminal width in columns.
12+
///
13+
/// This is passed to kernels via COLUMNS env var and used for stream terminal
14+
/// emulation. 80 is the classic terminal width that works well for side-by-side
15+
/// layouts and produces readable tracebacks.
16+
pub const TERMINAL_COLUMNS: usize = 80;
17+
18+
/// Terminal height in lines.
19+
///
20+
/// Passed to kernels via LINES env var. The actual value matters less for
21+
/// notebooks since we don't have scrolling viewports, but some tools check it.
22+
pub const TERMINAL_LINES: usize = 100;
23+
24+
/// String version of TERMINAL_COLUMNS for env var.
25+
pub const TERMINAL_COLUMNS_STR: &str = "80";
26+
27+
/// String version of TERMINAL_LINES for env var.
28+
pub const TERMINAL_LINES_STR: &str = "100";

0 commit comments

Comments
 (0)