Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input field plugin #128

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target

.idea
67 changes: 51 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ members = [
"plugins/stdin",
"plugins/dictionary",
"plugins/websearch",
"plugins/input",
]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ The flake provides multiple packages:
- symbols - the symbols plugin
- translate - the translate plugin
- websearch - the websearch plugin
- input - the input field plugin

#### home-manager module

Expand Down
11 changes: 11 additions & 0 deletions plugins/input/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "input"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
anyrun-plugin = { git = "https://github.com/Kirottu/anyrun" }
abi_stable = "0.11.3"
7 changes: 7 additions & 0 deletions plugins/input/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Input
A simple plugin to make anyrun act like an input field, or in other words, it will return what you typed.

## Note
It's important to have this plugin loaded last, because otherwise, it will take priority over other ones, which makes it the permanent first option.
It's probably most useful as the only plugin loaded anyway.
I also recommend using `--hide-plugin-info true`.
30 changes: 30 additions & 0 deletions plugins/input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use abi_stable::std_types::{ROption, RString, RVec};
use anyrun_plugin::{get_matches, handler, HandleResult, info, init, Match, PluginInfo};

#[info]
fn info() -> PluginInfo {
PluginInfo {
name: "Input".into(),
icon: "input-keyboard".into(),
}
}

#[init]
fn init(_config_dir: RString) {}

#[get_matches]
fn get_matches(input: RString) -> RVec<Match> {
vec![Match {
title: input,
description: ROption::RNone,
use_pango: false,
icon: ROption::RNone,
id: ROption::RNone,
}]
.into()
}

#[handler]
fn handler(selection: Match) -> HandleResult {
HandleResult::Stdout(selection.title.into_bytes())
}