raffi 0.25.0

A simple fuzzel launcher based on YAML file
Documentation
---
title: Calculator
description: Built-in mathematical expression evaluator
---

import { Aside, Tabs, TabItem } from '@astrojs/starlight/components';
import { Image } from 'astro:assets';
import calculatorScreenshot from '../../../assets/screenshots/calculator.png';

The native interface includes a built-in calculator that evaluates mathematical expressions as you type.

<Aside type="note">
The calculator is only available in **native mode**. It is not available when using Fuzzel mode.
</Aside>

## Overview

Simply type a mathematical expression in the launcher, and the calculator will automatically detect and evaluate it. Results can be copied to the clipboard using Enter.

## Supported Operations

### Basic Arithmetic

<Tabs>
<TabItem label="Addition">
```text
5 + 3
# Result: 8
```
</TabItem>
<TabItem label="Subtraction">
```text
10 - 4
# Result: 6
```
</TabItem>
<TabItem label="Multiplication">
```text
7 * 6
# Result: 42
```
</TabItem>
<TabItem label="Division">
```text
20 / 4
# Result: 5
```
</TabItem>
<TabItem label="Modulo">
```text
17 % 5
# Result: 2
```
</TabItem>
<TabItem label="Exponentiation">
```text
2 ^ 8
# Result: 256
```
</TabItem>
</Tabs>

### Mathematical Functions

The calculator supports common mathematical functions:

| Function | Description | Example |
|----------|-------------|--------|
| `sqrt(x)` | Square root | `sqrt(16)` → 4 |
| `sin(x)` | Sine (radians) | `sin(0)` → 0 |
| `cos(x)` | Cosine (radians) | `cos(0)` → 1 |
| `tan(x)` | Tangent (radians) | `tan(0)` → 0 |
| `log(x)` | Base-10 logarithm | `log(100)` → 2 |
| `ln(x)` | Natural logarithm | `ln(2.718)` → ~1 |
| `exp(x)` | Exponential (e^x) | `exp(1)` → ~2.718 |
| `abs(x)` | Absolute value | `abs(-5)` → 5 |
| `floor(x)` | Round down | `floor(3.7)` → 3 |
| `ceil(x)` | Round up | `ceil(3.2)` → 4 |

### Complex Expressions

You can combine multiple operations and functions:

<Tabs>
<TabItem label="Nested Functions">
```text
sqrt(16) + abs(-5)
# Result: 9
```
</TabItem>
<TabItem label="Order of Operations">
```text
2 + 3 * 4
# Result: 14 (multiplication first)
```
</TabItem>
<TabItem label="Parentheses">
```text
(2 + 3) * 4
# Result: 20
```
</TabItem>
<TabItem label="Scientific">
```text
exp(ln(10))
# Result: 10
```
</TabItem>
</Tabs>

## Usage

### Basic Usage

1. Launch Raffi in native mode
2. Type a mathematical expression
3. The result appears automatically
4. Press **Enter** to copy the result to clipboard

<Image src={calculatorScreenshot} alt="Calculator example" width={800} />

### Keyboard Shortcuts

- **Enter**: Copy result to clipboard
- **Esc**: Clear input and return to normal mode

## Configuration

The calculator is enabled by default in native mode. To disable it:

```yaml raffi.yaml
addons:
  calculator:
    enabled: false
```

### Enable Calculator

<Tabs>
  <TabItem label="Enabled (Default)">
    ```yaml
    addons:
      calculator:
        enabled: true
    ```
  </TabItem>
  <TabItem label="Disabled">
    ```yaml
    addons:
      calculator:
        enabled: false
    ```
  </TabItem>
</Tabs>

## Requirements

<Aside type="note">
The calculator needs `wl-copy` (from wl-clipboard), `xclip` or `xsel` to copy results to the clipboard.
</Aside>

On Wayland, install wl-clipboard:

<Tabs>
<TabItem label="Arch Linux">
```bash
sudo pacman -S wl-clipboard
```
</TabItem>
<TabItem label="Debian/Ubuntu">
```bash
sudo apt install wl-clipboard
```
</TabItem>
<TabItem label="Fedora">
```bash
sudo dnf install wl-clipboard
```
</TabItem>
</Tabs>

## Examples


  <details>
<summary>Basic Calculations</summary>

    ```text
    2 + 2           → 4
    10 - 3          → 7
    5 * 4           → 20
    100 / 4         → 25
    2 ^ 10          → 1024
    ```
  </details>

  <details>
<summary>Scientific Functions</summary>

    ```text
    sqrt(144)       → 12
    abs(-42)        → 42
    floor(3.9)      → 3
    ceil(2.1)       → 3
    exp(0)          → 1
    ln(1)           → 0
    ```
  </details>

  <details>
<summary>Trigonometry</summary>

    ```text
    sin(0)          → 0
    cos(0)          → 1
    tan(0)          → 0
    ```

    <Aside type="note">
    All trigonometric functions use radians, not degrees.
    </Aside>
  </details>

  <details>
<summary>Complex Expressions</summary>

    ```text
    sqrt(16) * 5                    → 20
    (10 + 5) * 2                    → 30
    2 ^ 3 + sqrt(9)                 → 11
    abs(-5) * floor(3.7)            → 15
    exp(ln(100))                    → 100
    ```
  </details>


## Tips

<Aside type="tip">
You don't need to type a special prefix or keyword. Just start typing a mathematical expression and the calculator will activate automatically.
</Aside>

<Aside type="caution">
Make sure you have `wl-copy`, `xclip` or `xsel` installed if you want to copy results to the clipboard. Without it, you can still see the results but cannot copy them.
</Aside>