Skip to content

Commit

Permalink
Image previews
Browse files Browse the repository at this point in the history
The `sixel` flag enables sixel support in `ratatu-image`, which then
needs libsixel to build.

Additionally to enable the preview feature, one must add it to
config.json:
```json
    "image_preview": {
      "size": {
        "width": 60,
        "height": 10,
      }
    }
```

There is a `backend: "halfblocks"` option in `image_preview` to force a
specific backend rather than guessing it, which might not be 100%
reliable in all terminals.
  • Loading branch information
benjajaja committed Aug 31, 2023
1 parent 3604f12 commit 5ea2108
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 33 deletions.
141 changes: 121 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ features = ["e2e-encryption", "sled", "rustls-tls"]
version = "1.24.1"
features = ["macros", "net", "rt-multi-thread", "sync", "time"]

[dependencies.ratatu-image]
version = "0.1.1"
optional = true
features = ["serde", "rustix"]

[dev-dependencies]
lazy_static = "1.4.0"
pretty_assertions = "1.4.0"

[profile.release]
lto = true
incremental = false

[features]
default = ["sixel"]
sixel = ["ratatu-image/sixel"]
7 changes: 4 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
};
devShell = mkShell {
buildInputs = [
(rustNightly.override { extensions = [ "rust-src" ]; })
(rustNightly.override {
extensions = [ "rust-src" "rust-analyzer-preview" "rustfmt" "clippy" ];
})
pkg-config
cargo-tarpaulin
rust-analyzer
rustfmt
cargo-watch
];
};
});
Expand Down
14 changes: 13 additions & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};

use emojis::Emoji;
use ratatu_image::picker::Picker;
use serde::{
de::Error as SerdeError,
de::Visitor,
Expand Down Expand Up @@ -383,6 +384,12 @@ pub enum IambError {

#[error("Could not use system clipboard data")]
Clipboard,

#[error("IO error: {0}")]
IOError(#[from] std::io::Error),

#[error("Preview error: {0}")]
Preview(String),
}

impl From<IambError> for UIError<IambInfo> {
Expand Down Expand Up @@ -482,6 +489,10 @@ impl RoomInfo {
self.messages.get(self.get_message_key(event_id)?)
}

pub fn get_event_mut(&mut self, event_id: &EventId) -> Option<&mut Message> {
self.messages.get_mut(self.keys.get(event_id)?.to_message_key()?)
}

pub fn insert_reaction(&mut self, react: ReactionEvent) {
match react {
MessageLikeEvent::Original(react) => {
Expand Down Expand Up @@ -670,14 +681,15 @@ pub struct ChatStore {
pub need_load: HashSet<OwnedRoomId>,
pub emojis: CompletionMap<String, &'static Emoji>,
pub sync_info: SyncInfo,
pub picker: Option<Picker>,
}

impl ChatStore {
pub fn new(worker: Requester, settings: ApplicationSettings) -> Self {
ChatStore {
worker,
settings,

picker: None,
cmds: crate::commands::setup_commands(),
emojis: emoji_map(),

Expand Down
Loading

0 comments on commit 5ea2108

Please sign in to comment.