How to Switch Between Unified and Side-by-Side Diff View Modes in tuicr
Use the :diff command to toggle between unified and side-by-side diff views in tuicr, or set diff_view = "side-by-side" in your config for a permanent default.
tuicr is a terminal-based code review tool that supports two distinct ways of visualizing file changes. The unified diff presents changes in a single column with + and - markers, while the side-by-side diff displays the original and modified versions in parallel columns. These modes are controlled by the app.diff_view_mode field, an enum that determines which rendering module handles the display.
Interactive Commands to Switch Diff Modes
tuicr provides Vim-style command mode for explicit control over the diff view. Press : to enter command mode, then type one of the following:
:diff— toggles between unified and side-by-side modes:diff unified— forces the unified layout:diff side-by-side— forces the side-by-side layout
After pressing Enter, tuicr immediately updates app.diff_view_mode and redraws the diff pane. The toggle logic is implemented in src/app/tree.rs through the toggle_diff_view_mode() function, which simply switches the enum value between DiffViewMode::Unified and DiffViewMode::SideBySide.
// The toggle function in src/app/tree.rs
pub fn toggle_diff_view_mode(&mut self) {
self.diff_view_mode = match self.diff_view_mode {
DiffViewMode::Unified => DiffViewMode::SideBySide,
DiffViewMode::SideBySide => DiffViewMode::Unified,
};
}
Keyboard Shortcuts for Quick Switching
For faster navigation, bind the Action::ToggleDiffViewMode action to a key combination. The default shortcut is Ctrl+d, which invokes the same toggle function without entering command mode. This action is connected through src/handler.rs, the central event handler that maps user input to application methods.
View all available shortcuts by opening the help popup — the diff-view toggle appears in the list maintained in src/ui/help_popup.rs.
Setting a Default Diff View Mode
To always start tuicr with your preferred layout, add the diff_view setting to ~/.config/tuicr/config.toml:
# ~/.config/tuicr/config.toml
diff_view = "side-by-side" # or "unified"
The configuration parser in src/config/mod.rs reads this key during App::new() initialization. The parser validates the value against the DiffViewMode enum, falling back to the default if an unrecognized mode is specified. The test suite includes should_parse_diff_view_unified and should_parse_diff_view_side_by_side cases to verify correct parsing.
How the Rendering System Works
The diff view selection happens at render time in src/ui/diff_view.rs. This module checks app.diff_view_mode and dispatches to the appropriate renderer:
src/ui/diff_unified.rs— handles unified diff formattingsrc/ui/diff_side_by_side.rs— handles side-by-side column layout
Both renderers operate on the same diff data structures but produce different terminal output.
Programmatic Mode Switching
Custom plugins or commands can manipulate the view mode directly through the App struct:
// Explicit mode assignment
app.diff_view_mode = DiffViewMode::SideBySide;
// Or use the toggle method
app.toggle_diff_view_mode();
Match against user input strings to implement custom commands:
match user_input.as_str() {
"unified" => app.diff_view_mode = DiffViewMode::Unified,
"side-by-side" => app.diff_view_mode = DiffViewMode::SideBySide,
_ => app.toggle_diff_view_mode(), // default: toggle
}
Key Source Files
| File | Purpose |
|---|---|
src/app/tree.rs |
Contains toggle_diff_view_mode() for enum switching |
src/ui/diff_view.rs |
Dispatches rendering based on app.diff_view_mode |
src/ui/diff_unified.rs |
Unified diff rendering implementation |
src/ui/diff_side_by_side.rs |
Side-by-side rendering implementation |
src/config/mod.rs |
Parses diff_view from configuration file |
src/handler.rs |
Connects key bindings to toggle action |
src/ui/help_popup.rs |
Displays keyboard shortcut documentation |
Summary
- Command mode: Type
:diffto toggle, or:diff unified/:diff side-by-sidefor explicit selection - Keyboard shortcut: Press Ctrl+d for instant toggling
- Configuration: Set
diff_view = "side-by-side"or"unified"in~/.config/tuicr/config.toml - Implementation: The
DiffViewModeenum insrc/app/tree.rscontrols which renderer insrc/ui/diff_view.rsdraws the output
Frequently Asked Questions
What is the default diff view mode in tuicr?
The default mode is unified diff, consistent with traditional diff command output. This can be overridden through the diff_view configuration setting in config.toml as parsed by src/config/mod.rs.
Can I bind a different key to toggle diff views?
Yes. The toggle action Action::ToggleDiffViewMode can be remapped through tuicr's keybinding system. Modify your configuration to assign a preferred key combination, which src/handler.rs will process.
Does switching diff modes preserve my scroll position?
tuicr maintains relative positioning within the file when switching modes. The scroll offset is preserved across toggle_diff_view_mode() calls, so you won't lose your place in large diffs.
Why does side-by-side mode truncate long lines?
Side-by-side rendering in src/ui/diff_side_by_side.rs splits terminal width between two columns. Lines exceeding half the terminal width are truncated or wrapped based on your terminal settings. Use unified mode for reviewing files with very long lines without truncation.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →