diff options
| author | Ellie Huxtable <ellie@atuin.sh> | 2026-01-22 15:33:12 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-22 15:33:12 -0800 |
| commit | 8990f61820c5b1d688f2e01f9d06b3736556889e (patch) | |
| tree | 26d087b212b013cf7f8816de6860b68cd502f07e /crates/atuin-client/src/settings.rs | |
| parent | Update regex for AWS Access Key ID pattern (#3088) (diff) | |
| download | atuin-8990f61820c5b1d688f2e01f9d06b3736556889e.zip | |
feat: add custom column support (#3089)
Configure the interactive search UI appearance. Resolves #998
```toml
[ui]
columns = ["duration", "time", "command"]
```
### `columns`
Default: `["duration", "time", "command"]`
Columns to display in the interactive search, from left to right. The
selection
indicator (`" > "`) is always shown first implicitly.
Each column can be specified as:
- A simple string (uses default width): `"duration"`
- An object with type and optional width/expand: `{ type = "directory",
width = 30 }`
#### Available column types
| Column | Default Width | Description |
| --------- | ------------- |
----------------------------------------------- |
| duration | 5 | Command execution duration (e.g., "123ms") |
| time | 8 | Relative time since execution (e.g., "59m ago") |
| datetime | 16 | Absolute timestamp (e.g., "2025-01-22 14:35") |
| directory | 20 | Working directory (truncated if too long) |
| host | 15 | Hostname |
| user | 10 | Username |
| exit | 3 | Exit code (colored by success/failure) |
| command | * | The command itself (expands by default) |
#### Column options
- **type**: The column type (required when using object format)
- **width**: Custom width in characters (optional, uses default if not
specified)
- **expand**: If `true`, the column fills remaining space. Default is
`true` for `command`, `false` for others. Only one column should have
`expand = true`.
#### Examples
```toml
# Minimal - more space for commands
columns = ["duration", "command"]
# With custom directory width
columns = ["duration", { type = "directory", width = 30 }, "command"]
# Show host for multi-machine sync users
columns = ["duration", "time", "host", "command"]
# Show exit codes prominently
columns = ["exit", "duration", "command"]
# Make directory expand instead of command
columns = ["duration", "time", { type = "directory", expand = true }, { type = "command", expand = false }]
```
Diffstat (limited to 'crates/atuin-client/src/settings.rs')
| -rw-r--r-- | crates/atuin-client/src/settings.rs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index 87ed9383..bfe9278d 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -451,6 +451,184 @@ pub enum PreviewStrategy { Fixed, } +/// Column types available for the interactive search UI. +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum UiColumnType { + /// Command execution duration (e.g., "123ms") + Duration, + /// Relative time since execution (e.g., "59s ago") + Time, + /// Absolute timestamp (e.g., "2025-01-22 14:35") + Datetime, + /// Working directory + Directory, + /// Hostname + Host, + /// Username + User, + /// Exit code + Exit, + /// The command itself (should be last, expands to fill) + Command, +} + +impl UiColumnType { + /// Returns the default width for this column type (in characters). + /// The Command column returns 0 as it expands to fill remaining space. + pub fn default_width(&self) -> u16 { + match self { + UiColumnType::Duration => 5, + UiColumnType::Time => 8, // "59m ago" with padding + UiColumnType::Datetime => 16, // "2025-01-22 14:35" + UiColumnType::Directory => 20, + UiColumnType::Host => 15, + UiColumnType::User => 10, + UiColumnType::Exit => 3, + UiColumnType::Command => 0, // Expands to fill + } + } +} + +/// A column configuration with type and optional custom width. +/// Can be specified as just a string (uses default width) or as an object with type and width. +#[derive(Clone, Debug, Serialize)] +pub struct UiColumn { + pub column_type: UiColumnType, + pub width: u16, + /// If true, this column expands to fill remaining space. Only one column should expand. + pub expand: bool, +} + +impl UiColumn { + pub fn new(column_type: UiColumnType) -> Self { + Self { + width: column_type.default_width(), + expand: column_type == UiColumnType::Command, + column_type, + } + } + + pub fn with_width(column_type: UiColumnType, width: u16) -> Self { + Self { + column_type, + width, + expand: column_type == UiColumnType::Command, + } + } +} + +// Custom deserialize to handle both string and object formats: +// "duration" or { type = "duration", width = 8, expand = true } +impl<'de> serde::Deserialize<'de> for UiColumn { + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> + where + D: serde::Deserializer<'de>, + { + use serde::de::{self, MapAccess, Visitor}; + + struct UiColumnVisitor; + + impl<'de> Visitor<'de> for UiColumnVisitor { + type Value = UiColumn; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str( + "a column type string or an object with 'type' and optional 'width'/'expand'", + ) + } + + fn visit_str<E>(self, value: &str) -> Result<UiColumn, E> + where + E: de::Error, + { + let column_type: UiColumnType = + serde::Deserialize::deserialize(serde::de::value::StrDeserializer::new(value))?; + Ok(UiColumn::new(column_type)) + } + + fn visit_map<M>(self, mut map: M) -> Result<UiColumn, M::Error> + where + M: MapAccess<'de>, + { + let mut column_type: Option<UiColumnType> = None; + let mut width: Option<u16> = None; + let mut expand: Option<bool> = None; + + while let Some(key) = map.next_key::<String>()? { + match key.as_str() { + "type" => { + column_type = Some(map.next_value()?); + } + "width" => { + width = Some(map.next_value()?); + } + "expand" => { + expand = Some(map.next_value()?); + } + _ => { + let _: serde::de::IgnoredAny = map.next_value()?; + } + } + } + + let column_type = column_type.ok_or_else(|| de::Error::missing_field("type"))?; + let width = width.unwrap_or_else(|| column_type.default_width()); + let expand = expand.unwrap_or(column_type == UiColumnType::Command); + Ok(UiColumn { + column_type, + width, + expand, + }) + } + } + + deserializer.deserialize_any(UiColumnVisitor) + } +} + +/// UI-specific settings for the interactive search. +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Ui { + /// Columns to display in interactive search, from left to right. + /// The indicator column (" > ") is always shown first implicitly. + /// The "command" column should be last as it expands to fill remaining space. + /// Can be simple strings or objects with type and width. + #[serde(default = "Ui::default_columns")] + pub columns: Vec<UiColumn>, +} + +impl Ui { + fn default_columns() -> Vec<UiColumn> { + vec![ + UiColumn::new(UiColumnType::Duration), + UiColumn::new(UiColumnType::Time), + UiColumn::new(UiColumnType::Command), + ] + } + + /// Validate the UI configuration. + /// Returns an error if more than one column has expand = true. + pub fn validate(&self) -> Result<()> { + let expand_count = self.columns.iter().filter(|c| c.expand).count(); + if expand_count > 1 { + bail!( + "Only one column can have expand = true, but {} columns are set to expand", + expand_count + ); + } + Ok(()) + } +} + +impl Default for Ui { + fn default() -> Self { + Self { + columns: Self::default_columns(), + } + } +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Settings { pub dialect: Dialect, @@ -531,6 +709,9 @@ pub struct Settings { pub theme: Theme, #[serde(default)] + pub ui: Ui, + + #[serde(default)] pub scripts: scripts::Settings, #[serde(default)] @@ -905,6 +1086,9 @@ impl Settings { settings.session_path = Self::expand_path(settings.session_path)?; settings.daemon.socket_path = Self::expand_path(settings.daemon.socket_path)?; + // Validate UI settings + settings.ui.validate()?; + Ok(settings) } |
