Skip to content
Merged
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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to bench51. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and versions follow
[Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- Vim keybindings in the GUI editor, on by default: Normal, Insert, Visual
and Visual Line modes, motions with counts, operators with text objects,
registers, undo/redo, `.` repeat, macros, search with highlighting, and
`:w :q :wq :e :make`. A block cursor and a mode line show the state, and
`gd` jumps to a label's definition.
- A Settings menu with Keybindings (Vim / Standard) and Theme, and a
`--keymap vim|standard` flag.

### Changed

- Theme moved from the View menu to Settings.

### Fixed

- `--theme`, `--keymap` and `--clock` no longer overwrite the saved
settings; they only apply to that run.

## [0.2.0] - 2026-11-01

### Added
Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ Linux, in a window or right in the terminal.
UART #1, Ports, Timers and Interrupts windows. Every window docks and tabs
wherever you drag it; the edit and debug layouts are remembered separately,
as in µVision.
- **Editor** with syntax highlighting, undo/redo, find, and breakpoint, error
and PC markers in the gutter.
- **Editor** with Vim keybindings (or standard ones, in Settings), syntax
highlighting, find, and breakpoint, error and PC markers in the gutter.
- **Two-pass assembler** for the full 8051 instruction set (all 255 opcodes):
- labels, expressions (`+ - * / MOD AND OR XOR NOT SHL SHR HIGH LOW`, `$`)
- number formats `42`, `2Ah`, `0x2A`, `101010b`, `52o`, `'*'`
Expand Down Expand Up @@ -132,9 +132,10 @@ bench51-gui firmware.hex # disassemble & debug a HEX file
bench51-gui --theme light
```

`--theme system|dark|light` overrides the theme chosen in View → Theme, and
`--clock <MHz>` the Xtal set in Project → Options for Target (default
11.0592), which is used for the elapsed-time display.
`--theme system|dark|light` and `--keymap vim|standard` override the choices
in the Settings menu for one run. `--clock <MHz>` overrides the Xtal set in
Project → Options for Target (default 11.0592), which is used for the
elapsed-time display.

On Linux it runs on Wayland and X11 and uses the XDG desktop portal for file
dialogs. Building it from source on Debian or Ubuntu needs the packages egui
Expand Down Expand Up @@ -164,6 +165,33 @@ change it, click a pin in Ports to hold it low from outside, and click the
bit chips in Registers, Timers and Interrupts to flip SFR bits. Files can be
dropped onto the window.

### Editing with Vim keys

The editor starts in Vim's Normal mode, with a block cursor and a mode line
along its bottom edge:

- **Modes:** `i a I A o O` to insert, `v V` for Visual and Visual Line, Esc
to go back.
- **Motions:** `h j k l w b e W B E 0 ^ $ gg G f t F T ; , % { } H M L`,
Ctrl-D/U/F/B. All take counts (`5j`, `3w`).
- **Operators:** `d c y > <` with any motion or text object (`iw aw i" a"
i( a( ip`), doubled for whole lines (`dd`, `yy`, `>>`). Also
`x X D C s S r J ~ p P`.
- **Repeat and undo:** `u` undoes, Ctrl-R redoes, `.` repeats the last
change, and `qa`…`q` / `@a` record and replay a macro.
- **Search:** `/ ? n N * #`; `:noh` clears the highlight.
- **Assembly helpers:** `gd` jumps to a label's definition, `gt`/`gT`
switch files, and new lines line up with the instruction column after a
label.
- **Commands:** `:w`, `:q`, `:wq`, `:e file`, `:42`, and `:make` to build.
- **Clipboard:** yanks and deletes also go to the system clipboard, and
Ctrl+V pastes from it.
- **Debug sessions:** the editor is read-only, but moving, searching and
yanking still work.

Settings → Keybindings → Standard switches to ordinary editing: type to
insert, with Ctrl+Z to undo. F1 lists the keys for whichever is active.

## Terminal version

`bench51` is the same IDE in a terminal, the way `emacs -nw` is Emacs
Expand Down
64 changes: 56 additions & 8 deletions crates/bench51-gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ use eframe::egui::{
use egui_tiles::Tree;

use crate::layout::{self, Pane, PaneBehavior};
use crate::state::{Action, BuildTab, LogKind, LogLine, Modal, Mode, Prefs, State, ThemePref};
use crate::state::{
Action, BuildTab, Keymap, LogKind, LogLine, Modal, Mode, Prefs, State, ThemePref,
};
use crate::theme::{self, palette};
use crate::{chrome, modals};
use crate::{chrome, editor, modals};

/// One simulation chunk, as in the TUI's frame loop.
const TICK: f64 = 1.0 / 30.0;
Expand Down Expand Up @@ -43,6 +45,10 @@ pub struct GuiApp {
/// The user confirmed quitting with unsaved changes.
allow_close: bool,
title: String,
/// Prefs as saved before the command line overrode them; those
/// overrides last only for this run.
saved_prefs: Prefs,
cli: Prefs,
}

fn theme_preference(t: ThemePref) -> ThemePreference {
Expand Down Expand Up @@ -76,23 +82,31 @@ impl GuiApp {
files: Vec<PathBuf>,
clock: Option<f64>,
theme: Option<ThemePref>,
keymap: Option<Keymap>,
) -> Self {
let ctx = &cc.egui_ctx;
theme::install(ctx);
let mut prefs: Prefs = cc
.storage
.and_then(|s| eframe::get_value(s, "prefs"))
.unwrap_or_default();
let saved_prefs = prefs.clone();
if let Some(c) = clock {
prefs.clock_mhz = c;
}
if let Some(t) = theme {
prefs.theme = t;
}
if let Some(k) = keymap {
prefs.keymap = k;
}
prefs.speed = prefs.speed.min(bench51_core::session::SPEEDS.len() - 1);
ctx.set_theme(theme_preference(prefs.theme));
ctx.set_zoom_factor(prefs.zoom.clamp(0.5, 3.0));
let cli = prefs.clone();
let mut app = Self {
saved_prefs,
cli,
st: State::new(prefs),
edit_tree: load_tree(cc, "edit_layout", layout::edit_tree),
debug_tree: load_tree(cc, "debug_layout", layout::debug_tree),
Expand Down Expand Up @@ -125,6 +139,12 @@ impl GuiApp {
let none = Modifiers::NONE;
let running = self.st.running();
let active = self.st.active;
// In Vim mode a focused editor keeps Ctrl+F (page down) for itself.
let vim_editor = self.st.prefs.keymap == Keymap::Vim
&& self
.st
.doc()
.is_some_and(|d| ctx.memory(|m| m.has_focus(editor::edit_id(d.id))));
// Most specific first: `consume_key` ignores extra Shift.
let table: [(Modifiers, Key, Action); 25] = [
(cmd_shift, Key::S, Action::SaveAs),
Expand Down Expand Up @@ -155,6 +175,9 @@ impl GuiApp {
];
ctx.input_mut(|i| {
for (mods, key, action) in table {
if vim_editor && action == Action::Find {
continue;
}
if i.consume_key(mods, key) {
self.st.actions.push(action);
}
Expand Down Expand Up @@ -299,13 +322,16 @@ impl GuiApp {
}
}

fn save(&mut self, ask: bool) {
/// Saves the active document: to `to`, to its own path, or wherever the
/// user picks (always when `ask`).
fn save(&mut self, ask: bool, to: Option<PathBuf>) {
let dir = self.start_dir();
let Some(doc) = self.st.doc_mut() else {
return;
};
let path = match (&doc.path, ask) {
(Some(p), false) => Some(p.clone()),
let path = match (to, &doc.path, ask) {
(Some(p), _, _) => Some(p),
(None, Some(p), false) => Some(p.clone()),
_ => {
let name = doc.name();
let stem = name.rsplit_once('.').map_or(name.as_str(), |(s, _)| s);
Expand Down Expand Up @@ -350,6 +376,8 @@ impl GuiApp {
if self.st.active >= i && self.st.active > 0 {
self.st.active -= 1;
}
self.st.vim.abandon();
self.st.focus_editor = true;
if self.st.docs.is_empty() {
self.st.mode = Mode::Edit;
self.st.active = 0;
Expand All @@ -368,7 +396,9 @@ impl GuiApp {
if i < self.st.docs.len() && i != self.st.active {
self.pause_active();
self.st.active = i;
self.st.vim.abandon();
}
self.st.focus_editor = true;
}

// ---- Build & debug ----
Expand Down Expand Up @@ -461,8 +491,9 @@ impl GuiApp {
}
Action::Open => self.open_dialog(),
Action::OpenPath(p) => self.open_path(&p),
Action::Save => self.save(false),
Action::SaveAs => self.save(true),
Action::Save => self.save(false, None),
Action::SaveAs => self.save(true, None),
Action::SaveTo(p) => self.save(false, Some(p)),
Action::Close(i) => {
if self.st.docs.get(i).is_some_and(|d| d.dirty()) {
self.st.modal = Some(Modal::ConfirmClose(i));
Expand Down Expand Up @@ -554,6 +585,11 @@ impl GuiApp {
self.st.prefs.theme = t;
ctx.set_theme(theme_preference(t));
}
Action::SetKeymap(k) => {
self.st.prefs.keymap = k;
self.st.vim.abandon();
self.st.focus_editor = true;
}
Action::Zoom(d) => ctx.set_zoom_factor((ctx.zoom_factor() + d).clamp(0.5, 3.0)),
Action::ZoomReset => ctx.set_zoom_factor(1.0),
Action::Find => {
Expand Down Expand Up @@ -643,7 +679,19 @@ impl eframe::App for GuiApp {
}

fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, "prefs", &self.st.prefs);
// A setting still at its command-line value is saved as it was
// before; one changed in the app since is saved as changed.
let mut prefs = self.st.prefs.clone();
if prefs.theme == self.cli.theme {
prefs.theme = self.saved_prefs.theme;
}
if prefs.keymap == self.cli.keymap {
prefs.keymap = self.saved_prefs.keymap;
}
if prefs.clock_mhz == self.cli.clock_mhz {
prefs.clock_mhz = self.saved_prefs.clock_mhz;
}
eframe::set_value(storage, "prefs", &prefs);
eframe::set_value(storage, "edit_layout", &self.edit_tree);
eframe::set_value(storage, "debug_layout", &self.debug_tree);
}
Expand Down
38 changes: 26 additions & 12 deletions crates/bench51-gui/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eframe::egui::{self, Align, Button, FontId, Layout, RichText, Stroke, Ui};

use crate::icons::Icon;
use crate::layout::Pane;
use crate::state::{Action, Modal, Mode, State, ThemePref};
use crate::state::{Action, Keymap, Modal, Mode, State, ThemePref};
use crate::theme::{ACCENT, LABEL, LABEL_TRACKING, palette};
use crate::widgets;

Expand Down Expand Up @@ -99,17 +99,6 @@ pub fn menu_bar(ui: &mut Ui, st: &mut State) {
}
}
ui.separator();
ui.menu_button(title(ui, "Theme"), |ui| {
for (t, name) in [
(ThemePref::System, "System"),
(ThemePref::Dark, "Dark"),
(ThemePref::Light, "Light"),
] {
if check(ui, name, st.prefs.theme == t) {
acts.push(Action::SetTheme(t));
}
}
});
if item(ui, "Zoom in", "Ctrl++") {
acts.push(Action::Zoom(0.1));
}
Expand Down Expand Up @@ -185,6 +174,26 @@ pub fn menu_bar(ui: &mut Ui, st: &mut State) {
}
}
});
ui.menu_button(title(ui, "Settings"), |ui| {
ui.menu_button(title(ui, "Keybindings"), |ui| {
for (k, name) in [(Keymap::Vim, "Vim"), (Keymap::Standard, "Standard")] {
if check(ui, name, st.prefs.keymap == k) {
acts.push(Action::SetKeymap(k));
}
}
});
ui.menu_button(title(ui, "Theme"), |ui| {
for (t, name) in [
(ThemePref::System, "System"),
(ThemePref::Dark, "Dark"),
(ThemePref::Light, "Light"),
] {
if check(ui, name, st.prefs.theme == t) {
acts.push(Action::SetTheme(t));
}
}
});
});
ui.menu_button(title(ui, "Help"), |ui| {
if item(ui, "Keyboard shortcuts", "F1") {
acts.push(Action::Modal(Modal::Shortcuts));
Expand Down Expand Up @@ -374,6 +383,11 @@ pub fn status_bar(ui: &mut Ui, st: &State) {
"edit"
};
ui.label(text(mode.into()).color(p.text_disabled));
let keys = match st.prefs.keymap {
Keymap::Vim => "vim",
Keymap::Standard => "std",
};
ui.label(text(keys.into()).color(p.text_disabled));
// Running: a dot that blinks in hard 2 Hz steps.
let (r, _) = ui.allocate_exact_size(egui::vec2(8.0, 8.0), egui::Sense::hover());
let on = !live || (ui.input(|i| i.time) * 4.0) as i64 % 2 == 0;
Expand Down
Loading
Loading