Skip to content

Commit

Permalink
[Chore] upgrade nvim-oxi to v0.5.1 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistricky authored Sep 22, 2024
1 parent c2924bf commit 3a09549
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 170 deletions.
209 changes: 63 additions & 146 deletions generator/Cargo.lock

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

2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
nvim-oxi = { features = ["neovim-0-9", "libuv", "oxi-libuv"], version = "0.3" }
nvim-oxi = { features = ["neovim-0-9", "libuv"], version = "0.5.1" }
tiny-skia = "0.11.4"
syntect = "5.2.0"
cosmic-text = "0.12.0"
Expand Down
5 changes: 2 additions & 3 deletions generator/src/components/interface/render_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use nvim_oxi::lua;
use thiserror::Error;

pub type Result<T> = std::result::Result<T, RenderError>;
Expand All @@ -21,8 +20,8 @@ pub enum RenderError {
NoSuchFile(String),
}

impl From<RenderError> for nvim_oxi::Error {
impl From<RenderError> for nvim_oxi::api::Error {
fn from(err: RenderError) -> Self {
nvim_oxi::Error::Lua(lua::Error::RuntimeError(err.to_string()))
nvim_oxi::api::Error::Other(err.to_string())
}
}
4 changes: 2 additions & 2 deletions generator/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::{config::TakeSnapshotParams, snapshot::take_snapshot};
use arboard::SetExtLinux;
use arboard::{Clipboard, ImageData};

use nvim_oxi::Result;
use nvim_oxi::api;

// The function will be called as FFI on Lua side
#[allow(dead_code)]
pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<()> {
pub fn copy_into_clipboard(config: TakeSnapshotParams) -> Result<(), api::Error> {
let pixmap = take_snapshot(config.clone())?;
let premultplied_colors = pixmap.pixels();
let colors = premultplied_colors
Expand Down
9 changes: 6 additions & 3 deletions generator/src/copy_ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use arboard::Clipboard;
#[cfg(target_os = "linux")]
use arboard::SetExtLinux;
use nvim_oxi::Result;
use nvim_oxi::api;
use std::cmp::max;

const SPACE_BOTH_SIDE: usize = 2;
Expand All @@ -19,7 +19,7 @@ fn optional(component: String, is_view: bool) -> String {
}

#[allow(dead_code)]
pub fn copy_ascii(params: TakeSnapshotParams) -> Result<()> {
pub fn copy_ascii(params: TakeSnapshotParams) -> Result<(), api::Error> {
let code = prepare_code(&params.code);
let (width, height) = calc_wh(&code, 1., 1.);
let calc_line_number_width =
Expand Down Expand Up @@ -71,7 +71,10 @@ pub fn copy_ascii(params: TakeSnapshotParams) -> Result<()> {
});

#[cfg(not(target_os = "linux"))]
Clipboard::new().unwrap().set_text(ascii_snapshot).unwrap();
Clipboard::new()
.unwrap()
.set_text(ascii_snapshot)
.map_err(|err| api::Error::Other(err.to_string()))?;

Ok(())
}
15 changes: 8 additions & 7 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ mod save;
mod snapshot;
mod text;

use config::TakeSnapshotParams;
use copy::copy_into_clipboard;
use copy_ascii::copy_ascii;
use nvim_oxi::{Dictionary, Function, Result};
use nvim_oxi::{api, Dictionary, Function};
use save::save_snapshot;

#[nvim_oxi::module]
fn generator() -> Result<Dictionary> {
#[nvim_oxi::plugin]
fn generator() -> nvim_oxi::Result<Dictionary> {
let copy_into_clipboard: Function<TakeSnapshotParams, Result<(), api::Error>> =
Function::from_fn(copy_into_clipboard);

Ok(Dictionary::from_iter([
(
"copy_into_clipboard",
Function::from_fn(copy_into_clipboard),
),
("copy_into_clipboard", copy_into_clipboard),
("save_snapshot", Function::from_fn(save_snapshot)),
("copy_ascii", Function::from_fn(copy_ascii)),
]))
Expand Down
Loading

0 comments on commit 3a09549

Please sign in to comment.