Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added
- add `--maximized` and `--fullscreen` flags to start the window in that mode
- add `window.copy_on_select` to control whether mouse selection auto-copies to the clipboard
- persist and restore window size, maximized, and fullscreen state per session
- REP (`CSI Ps b`): repeat the last printed character `Ps` times

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ width = 800
height = 600
title = "mmterm"
cursor_blink_ms = 500
copy_on_select = true # auto-copy mouse selection to the clipboard

[shell]
# program = "/bin/zsh" # defaults to $SHELL
Expand Down
1 change: 1 addition & 0 deletions assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ title = "mmterm"
cursor_blink_ms = 500
inactive_dim = 0.55
detect_urls = true
copy_on_select = true

[shell]
# program = "/bin/zsh"
Expand Down
1 change: 1 addition & 0 deletions doc/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Screenshot capture is a two-step flow: region selection followed by a name promp
| window | cursor_blink_ms | uint | `500` |
| window | inactive_dim | float | `0.55` |
| window | detect_urls | bool | `true` |
| window | copy_on_select | bool | `true` |
| terminal | scrollback_lines | uint | `10000` (min 100) |
| shell | program | string? | `$SHELL` |
| logging | auto_log | bool | `false` |
Expand Down
34 changes: 34 additions & 0 deletions src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ palette = []
assert!(cfg.window.detect_urls);
}

#[test]
fn default_copy_on_select_value() {
assert!(default_copy_on_select());
}

#[test]
fn default_copy_on_select_is_true() {
let cfg = Config::default();
assert!(cfg.window.copy_on_select);
}

#[test]
fn copy_on_select_default_applied_when_missing() {
let toml = r###"
[font]
family = "Mono"
size = 14.0
[window]
width = 800
height = 600
title = "t"
cursor_blink_ms = 500
[shell]
[colors]
background = "#000000"
foreground = "#ffffff"
cursor = "#ffffff"
selection = "#333333"
palette = []
"###;
let cfg: Config = toml::from_str(toml).expect("parse failed");
assert!(cfg.window.copy_on_select);
}

#[test]
fn save_does_not_panic() {
Config::default().save();
Expand Down
5 changes: 5 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ fn default_inactive_dim() -> f32 {
fn default_detect_urls() -> bool {
true
}
fn default_copy_on_select() -> bool {
true
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct WindowConfig {
Expand All @@ -158,6 +161,8 @@ pub struct WindowConfig {
pub inactive_dim: f32,
#[serde(default = "default_detect_urls")]
pub detect_urls: bool,
#[serde(default = "default_copy_on_select")]
pub copy_on_select: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down
13 changes: 13 additions & 0 deletions src/config/tui_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const F_AUTO_UPDATE_CHECK: usize = 37;
const F_AUTO_UPDATE_INSTALL: usize = 38;
const F_SHELL_INTEGRATION: usize = 39;
const F_DESKTOP_NOTIFICATIONS: usize = 40;
const F_COPY_ON_SELECT: usize = 41;

const PALETTE_LABELS: [&str; 16] = [
"Palette 0 black",
Expand Down Expand Up @@ -302,6 +303,14 @@ impl ConfigPanel {
section: None,
});

fields.push(Field {
label: "Copy On Select",
hint: "true or false — auto-copy mouse selection to clipboard",
value: cfg.window.copy_on_select.to_string(),
kind: FieldKind::Bool,
section: None,
});

let mut collapsed = HashSet::new();
collapsed.insert("Palette");

Expand Down Expand Up @@ -624,6 +633,9 @@ impl ConfigPanel {
let detect_urls = get(F_DETECT_URLS)
.parse::<bool>()
.map_err(|_| "Invalid detect_urls — use true or false")?;
let copy_on_select = get(F_COPY_ON_SELECT)
.parse::<bool>()
.map_err(|_| "Invalid copy_on_select — use true or false")?;
let shell = {
let s = get(F_SHELL);
if s.is_empty() { None } else { Some(s) }
Expand Down Expand Up @@ -687,6 +699,7 @@ impl ConfigPanel {
cursor_blink_ms: blink_ms,
inactive_dim,
detect_urls,
copy_on_select,
},
shell: ShellConfig { program: shell },
terminal: TerminalConfig { scrollback_lines },
Expand Down
32 changes: 23 additions & 9 deletions src/config/tui_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ fn make_panel() -> ConfigPanel {
#[test]
fn from_config_has_correct_field_count() {
let panel = make_panel();
// 9 base + 1 scrollback + 2 logging + 1 theme + 4 colors + 16 palette + 1 status_bar + 3 general + 2 updates + 2 shell/notify = 41
assert_eq!(panel.fields.len(), 41);
// 9 base + 1 scrollback + 2 logging + 1 theme + 4 colors + 16 palette + 1 status_bar + 3 general + 2 updates + 2 shell/notify + 1 copy_on_select = 42
assert_eq!(panel.fields.len(), 42);
}

#[test]
Expand Down Expand Up @@ -305,6 +305,7 @@ fn distinct_config() -> Config {
cursor_blink_ms: 523,
inactive_dim: 0.42,
detect_urls: true,
copy_on_select: false,
},
shell: ShellConfig {
program: Some("/bin/xyzsh".into()),
Expand Down Expand Up @@ -375,6 +376,7 @@ fn field_index_sanity() {
F_AUTO_UPDATE_INSTALL,
F_SHELL_INTEGRATION,
F_DESKTOP_NOTIFICATIONS,
F_COPY_ON_SELECT,
];
occupied.extend((0..16).map(|i| F_PALETTE + i));
occupied.sort_unstable();
Expand Down Expand Up @@ -433,6 +435,18 @@ fn build_config_roundtrip_toggles_desktop_notifications() {
}
}

#[test]
fn build_config_roundtrip_toggles_copy_on_select() {
let mut panel = make_panel();
assert_eq!(panel.fields[F_COPY_ON_SELECT].value, "true");
panel.fields[F_COPY_ON_SELECT].value = "false".to_string();
if let ConfigAction::Save(cfg) = panel.save() {
assert!(!cfg.window.copy_on_select);
} else {
panic!("expected Save action");
}
}

#[test]
fn build_config_shell_empty_becomes_none() {
let mut panel = make_panel();
Expand Down Expand Up @@ -680,8 +694,8 @@ fn palette_collapsed_by_default() {
#[test]
fn visible_indices_hides_palette_body() {
let panel = make_panel();
// 41 total - 15 palette body fields = 26 visible
assert_eq!(panel.visible_indices().len(), 26);
// 42 total - 15 palette body fields = 27 visible
assert_eq!(panel.visible_indices().len(), 27);
}

#[test]
Expand All @@ -690,7 +704,7 @@ fn toggle_on_palette_header_expands() {
panel.selected = F_PALETTE;
panel.toggle_collapse();
assert!(!panel.collapsed.contains("Palette"));
assert_eq!(panel.visible_indices().len(), 41);
assert_eq!(panel.visible_indices().len(), 42);
}

#[test]
Expand All @@ -700,7 +714,7 @@ fn toggle_twice_restores_collapsed() {
panel.toggle_collapse();
panel.toggle_collapse();
assert!(panel.collapsed.contains("Palette"));
assert_eq!(panel.visible_indices().len(), 26);
assert_eq!(panel.visible_indices().len(), 27);
}

#[test]
Expand Down Expand Up @@ -755,10 +769,10 @@ fn move_up_skips_collapsed_palette() {
#[test]
fn move_down_at_last_visible_clamps() {
let mut panel = make_panel();
// F_DESKTOP_NOTIFICATIONS is the last field and is always visible
panel.selected = F_DESKTOP_NOTIFICATIONS;
// F_COPY_ON_SELECT is the last field and is always visible
panel.selected = F_COPY_ON_SELECT;
panel.handle_down();
assert_eq!(panel.selected, F_DESKTOP_NOTIFICATIONS);
assert_eq!(panel.selected, F_COPY_ON_SELECT);
}

#[test]
Expand Down
12 changes: 10 additions & 2 deletions src/input/mouse_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ impl App {
cur_row: row,
anchored: true,
};
self.copy_selection_to_clipboard(start, row, end, row);
if self.state.config.window.copy_on_select {
self.copy_selection_to_clipboard(start, row, end, row);
}
}
self.state.mouse_selecting = false;
if let Some(w) = &self.window {
Expand Down Expand Up @@ -185,7 +187,9 @@ impl App {
}
return;
}
self.copy_selection_to_clipboard(start_col, start_row, cur_col, cur_row);
if self.state.config.window.copy_on_select {
self.copy_selection_to_clipboard(start_col, start_row, cur_col, cur_row);
}
}
if let Some(w) = &self.window {
w.request_redraw();
Expand Down Expand Up @@ -224,3 +228,7 @@ impl App {
}
}
}

#[cfg(test)]
#[path = "mouse_ops_test.rs"]
mod tests;
Loading