-
-
Notifications
You must be signed in to change notification settings - Fork 139
✨ zb: Add helper for IBus connection creation #1697
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
01057d0
🔧 zb: Extend process module run() to all Unix platforms
cachebag ac5583f
📦️ zb: Add async-recursion for Unix targets
cachebag d4f4850
✨ zb: Add helper for IBus connection creation
cachebag 9f4fc9a
👷 CI: Install and launch IBus daemon for testing
cachebag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| use crate::{Address, Result, process::run}; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| /// The transport properties of an IBus D-Bus address. | ||
| /// | ||
| /// This transport type queries the IBus daemon for its D-Bus address using the `ibus address` | ||
| /// command. IBus (Intelligent Input Bus) is an input method framework used primarily on Linux | ||
| /// systems for entering text in various languages. | ||
| /// | ||
| /// # Platform Support | ||
| /// | ||
| /// This transport is available on Unix-like systems where IBus is installed. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```no_run | ||
| /// # use zbus::address::transport::{Transport, Ibus}; | ||
| /// # use zbus::Address; | ||
| /// # | ||
| /// // Create an IBus transport | ||
| /// let ibus = Ibus::new(); | ||
| /// let _addr = Transport::Ibus(ibus); | ||
| /// | ||
| /// // Or use it directly as an address | ||
| /// let _addr = Address::from(Transport::Ibus(Ibus::new())); | ||
| /// ``` | ||
| pub struct Ibus; | ||
|
|
||
| impl Ibus { | ||
| /// Create a new IBus transport. | ||
| /// | ||
| /// This will query the IBus daemon for its D-Bus address when the connection is established. | ||
| #[must_use] | ||
| pub fn new() -> Self { | ||
| Self | ||
| } | ||
|
|
||
| /// Determine the actual transport details behind an IBus address. | ||
| /// | ||
| /// This method executes the `ibus address` command to retrieve the D-Bus address from the | ||
| /// running IBus daemon, then parses and returns the underlying transport. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if: | ||
| /// - The `ibus` command is not found or fails to execute | ||
| /// - The IBus daemon is not running | ||
| /// - The command output cannot be parsed as a valid D-Bus address | ||
| /// - The command output is not valid UTF-8 | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```no_run | ||
| /// # use zbus::connection::Builder; | ||
| /// # use zbus::block_on; | ||
| /// # | ||
| /// # block_on(async { | ||
| /// // This method is used internally by the connection builder | ||
| /// let _conn = Builder::ibus()?.build().await?; | ||
| /// # Ok::<(), zbus::Error>(()) | ||
| /// # }).unwrap(); | ||
| /// ``` | ||
| pub(super) async fn bus_address(&self) -> Result<Address> { | ||
| let output = run("ibus", ["address"]) | ||
| .await | ||
| .map_err(|e| crate::Error::Address(format!("Failed to execute ibus command: {e}")))?; | ||
|
|
||
| if !output.status.success() { | ||
| return Err(crate::Error::Address(format!( | ||
| "ibus terminated with code: {}", | ||
| output.status | ||
| ))); | ||
| } | ||
|
|
||
| let addr = String::from_utf8(output.stdout).map_err(|e| { | ||
| crate::Error::Address(format!("Unable to parse ibus output as UTF-8: {e}")) | ||
| })?; | ||
|
|
||
| addr.trim().parse() | ||
| } | ||
|
|
||
| /// Parse IBus transport from D-Bus address options. | ||
| /// | ||
| /// The IBus transport type does not require any options, so this method will succeed | ||
| /// as long as the transport type is specified as "ibus". | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// This method does not return errors for the IBus transport, but the signature is kept | ||
| /// consistent with other transport types. | ||
| pub(super) fn from_options(_opts: std::collections::HashMap<&str, &str>) -> Result<Self> { | ||
| Ok(Self) | ||
| } | ||
| } | ||
|
|
||
| impl Default for Ibus { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl std::fmt::Display for Ibus { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| write!(f, "ibus:") | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_ibus_new() { | ||
| let ibus = Ibus::new(); | ||
| assert_eq!(ibus.to_string(), "ibus:"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_ibus_default() { | ||
| let ibus = Ibus::default(); | ||
| assert_eq!(ibus.to_string(), "ibus:"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_ibus_from_options() { | ||
| let options = std::collections::HashMap::new(); | ||
| let ibus = Ibus::from_options(options).unwrap(); | ||
| assert_eq!(ibus, Ibus::new()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_ibus_display() { | ||
| let ibus = Ibus::new(); | ||
| assert_eq!(format!("{}", ibus), "ibus:"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.