Why Nostr? What is Njump?
2024-06-10 20:04:32

npub1p6…jsykv on Nostr: commit 5108300e0dcd4f3e635bd58c7ee86269de56bf6f Author: randymcmillan ...

commit 5108300e0dcd4f3e635bd58c7ee86269de56bf6f
Author: randymcmillan <[email protected]>
Date: Tue May 21 22:28:42 2024 -0400

apply cargo fmt sort

cargo add pango

diff --git a/Cargo.toml b/Cargo.toml
index 1dee0c8..99f166e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,16 +24,18 @@ readme = { workspace = true }
exclude = ["webview-sys/**", "webview-examples/**", ".github/**", "Cargo.lock"]

[dependencies]
+boxfnonce = "0.1"
comrak = "0.23.0"
include_dir = { version = "0.7.3", features = ["glob", "metadata"] }
indicatif = "0.17.8"
markdown = { version = "1.0.0-alpha.17", features = ["json", "log", "serde"] }
markdown2html-converter = "1.1.12"
+pango = "0.19.5"
+pango-sys = { version = "0.19.5", features = ["v1_42"] }
+tinyfiledialogs = "3.3"

urlencoding = "1.1"
webview-sys = { path = "webview-sys", version = "0.6.2" }
-boxfnonce = "0.1"
-tinyfiledialogs = "3.3"

[build-dependencies]
include_dir = { version = "0.7.3", features = ["glob", "metadata"] }
diff --git a/build.rs b/build.rs
index d02e678..3673de7 100644
--- a/build.rs
+++ b/build.rs
@@ -10,21 +10,12 @@ static PROJECT_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR");
fn main() -> std::io::Result<()> {
let _out_dir = env::var("OUT_DIR").unwrap();

- Command::new("git")
- .args(&[
- "remote",
- "add",
- "gnostr-org",
- "[email protected]:gnostr-org/nips.git",
- ])
- .status()
- .unwrap();
Command::new("git")
.args(&[
"remote",
"add",
"upstream",
- "[email protected]:nostr-protocol/nips.git",
+ "https://github.com/nostr-protocol/nips.git";,
])
.status()
.unwrap();
@@ -41,22 +32,21 @@ fn main() -> std::io::Result<()> {
.status()
.unwrap();

- // //pandoc README.md | sed 's/.md/.html/g' > readme.html
+ ////pandoc README.md | sed 's/.md/.html/g' > readme.html
//
- // let mut count: u8 = 0;
- // let glob = "**/*.md";
- // let mut nip_vec = Vec::<String>::new(); // Create an empty Vec
+ //let mut count: u8 = 0;
+ //let glob = "**/*.md";
+ //let mut nip_vec = Vec::<String>::new(); // Create an empty Vec
//
- // for entry in PROJECT_DIR.find(glob).unwrap() {
- // count = count + 1;
- // //println!("count={}", count);
- // //println!("{}", entry.path().display());
- // nip_vec.push((entry.path().display()).to_string().replace(".md",
+ //for entry in PROJECT_DIR.find(glob).unwrap() {
+ // count = count + 1;
+ // //println!("count={}", count);
+ // //println!("{}", entry.path().display());
+ // nip_vec.push((entry.path().display()).to_string().replace(".md",
// ".html")); //nip_vec.push("md content".to_string());
- // let mut md_content = PROJECT_DIR.get_file(entry.path()).unwrap();
- // let content = md_content.contents_utf8().unwrap();
+ //let mut md_content = PROJECT_DIR.get_file(entry.path()).unwrap();
+ //let content = md_content.contents_utf8().unwrap();

- // Get the script name (replace "my_script.sh" with the actual script name)
let script_name = "./script.sh";

// Build the command
@@ -71,22 +61,5 @@ fn main() -> std::io::Result<()> {
.spawn()
.expect("script.sh command failed to start");

- // // Execute the script
- // match command.spawn() {
- // Ok(mut child) => {
- // // Wait for the script to finish
- // child.wait().expect("script failed to run");
- // println!("Script finished successfully!");
- // }
- // Err(err) => {
- // println!("Error running script: {}", err);
- // }
- // }
-
- //println!("\n{}", content);
- //println!("{}", markdown::to_html(content));
- //let content_html = markdown::to_html(content);
- //fs::write(format!("{}.html", count), content_html)?;
- //}
Ok(())
}
diff --git a/src/dialog.rs b/src/dialog.rs
index 93d9f06..26d578e 100644
--- a/src/dialog.rs
+++ b/src/dialog.rs
@@ -1,11 +1,13 @@
use std::path::PathBuf;
+
use tfd::MessageBoxIcon;

use crate::{WVResult, WebView};

/// A builder for opening a new dialog window.
#[deprecated(
- note = "Please use crates like 'tinyfiledialogs' for dialog handling, see example in examples/dialog.rs"
+ note = "Please use crates like 'tinyfiledialogs' for dialog handling, see example in \
+ examples/dialog.rs"
)]
#[derive(Debug)]
pub struct DialogBuilder<'a: 'b, 'b, T: 'a> {
@@ -38,7 +40,8 @@ impl<'a: 'b, 'b, T: 'a> DialogBuilder<'a, 'b, T> {
Ok(tfd::save_file_dialog("", "").map(|p| p.into()))
}

- /// Opens a new choose directory dialog as returns the chosen directory path.
+ /// Opens a new choose directory dialog as returns the chosen directory
+ /// path.
pub fn choose_directory<S, P>(
&mut self,
title: S,
diff --git a/src/error.rs b/src/error.rs
index 6ea615c..29a435c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,8 +1,6 @@
-use std::{
- error,
- ffi::NulError,
- fmt::{self, Debug, Display},
-};
+use std::error;
+use std::ffi::NulError;
+use std::fmt::{self, Debug, Display};

pub trait CustomError: Display + Debug + Send + Sync + 'static {}

@@ -11,7 +9,8 @@ impl<T: Display + Debug + Send + Sync + 'static> CustomError for T {}
/// A WebView error.
#[derive(Debug)]
pub enum Error {
- /// While attempting to build a WebView instance, a required field was not initialized.
+ /// While attempting to build a WebView instance, a required field was not
+ /// initialized.
UninitializedField(&'static str),
/// An error occurred while initializing a WebView instance.
Initialization,
@@ -21,15 +20,17 @@ pub enum Error {
JsEvaluation,
/// An error occurred while injecting CSS into a WebView instance.
CssInjection,
- /// Failure to dispatch a closure to a WebView instance via a handle, likely because the
- /// WebView was dropped.
+ /// Failure to dispatch a closure to a WebView instance via a handle, likely
+ /// because the WebView was dropped.
Dispatch,
- /// An user-specified error occurred. For use inside invoke and dispatch closures.
+ /// An user-specified error occurred. For use inside invoke and dispatch
+ /// closures.
Custom(Box<dyn CustomError>),
}

impl Error {
- /// Creates a custom error from a `T: Display + Debug + Send + Sync + 'static`.
+ /// Creates a custom error from a `T: Display + Debug + Send + Sync +
+ /// 'static`.
pub fn custom<E: CustomError>(error: E) -> Error {
Error::Custom(Box::new(error))
}
diff --git a/src/lib.rs b/src/lib.rs
index d305d64..1122033 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,15 +6,17 @@
//! [crates.io]: https://crates.io/crates/web-view
//!
//! This library provides Rust bindings for the [webview](https://github.com/zserge/webview) library
-//! to allow easy creation of cross-platform Rust desktop apps with GUIs based on web technologies.
+//! to allow easy creation of cross-platform Rust desktop apps with GUIs based
+//! on web technologies.
//!
-//! It supports two-way bindings for communication between the Rust backend and JavaScript frontend.
+//! It supports two-way bindings for communication between the Rust backend and
+//! JavaScript frontend.
//!
-//! It uses Cocoa/WebKit on macOS, gtk-webkit2 on Linux and MSHTML (IE10/11) on Windows, so your app
-//! will be **much** leaner than with Electron.
+//! It uses Cocoa/WebKit on macOS, gtk-webkit2 on Linux and MSHTML (IE10/11) on
+//! Windows, so your app will be **much** leaner than with Electron.
//!
-//! To use a custom version of webview, define an environment variable WEBVIEW_DIR with the path to
-//! its source directory.
+//! To use a custom version of webview, define an environment variable
+//! WEBVIEW_DIR with the path to its source directory.
//!
//! For usage info please check out [the examples] and the [original readme].
//!
@@ -33,20 +35,18 @@ mod dialog;
mod error;
mod escape;

+use std::ffi::{CStr, CString};
+use std::marker::PhantomData;
+use std::mem;
+use std::os::raw::*;
+use std::sync::{Arc, RwLock, Weak};
+
+use boxfnonce::SendBoxFnOnce;
pub use color::Color;
pub use dialog::DialogBuilder;
pub use error::{CustomError, Error, WVResult};
pub use escape::escape;
-
-use boxfnonce::SendBoxFnOnce;
use ffi::*;
-use std::{
- ffi::{CStr, CString},
- marker::PhantomData,
- mem,
- os::raw::*,
- sync::{Arc, RwLock, Weak},
-};
use urlencoding::encode;

/// JavaScript function used to insert new css rules to webview.
@@ -55,10 +55,10 @@ use urlencoding::encode;
/// With every call of this function new style element
/// will get created with css pasted as its children.
const CSS_INJECT_FUNCTION: &str = "(function(e){var \
- t=document.createElement('style'),d=document.head||document.\
- getElementsByTagName('head')[0];t.setAttribute('type','text/\
- css'),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.\
- createTextNode(e)),d.appendChild(t)})";
+ t=document.createElement('style'),d=document.head||document.\
+ getElementsByTagName('head')[0];t.setAttribute('type','text/\
+ css'),t.styleSheet?t.styleSheet.cssText=e:t.\
+ appendChild(document.createTextNode(e)),d.appendChild(t)})";

/// Content displayable inside a [`WebView`].
///
@@ -180,7 +180,8 @@ where
self
}

- /// Sets the resizability of the WebView window. If set to false, the window cannot be resized.
+ /// Sets the resizability of the WebView window. If set to false, the window
+ /// cannot be resized.
///
/// Defaults to `true`.
pub fn resizable(mut self, resizable: bool) -> Self {
@@ -228,12 +229,13 @@ where
self
}

- /// Sets the invoke handler callback. This will be called when a message is received from
- /// JavaScript.
+ /// Sets the invoke handler callback. This will be called when a message is
+ /// received from JavaScript.
///
/// # Errors
///
- /// If the closure returns an `Err`, it will be returned on the next call to [`step()`].
+ /// If the closure returns an `Err`, it will be returned on the next call to
+ /// [`step()`].
///
/// [`step()`]: struct.WebView.html#method.step
pub fn invoke_handler(mut self, invoke_handler: I) -> Self {
@@ -241,8 +243,9 @@ where
self
}

- /// Sets the initial state of the user data. This is an arbitrary value stored on the WebView
- /// thread, accessible from dispatched closures without synchronization overhead.
+ /// Sets the initial state of the user data. This is an arbitrary value
+ /// stored on the WebView thread, accessible from dispatched closures
+ /// without synchronization overhead.
pub fn user_data(mut self, user_data: T) -> Self {
self.user_data = Some(user_data);
self
@@ -285,7 +288,8 @@ where
)
}

- /// Validates provided arguments and runs a new WebView to completion, returning the user data.
+ /// Validates provided arguments and runs a new WebView to completion,
+ /// returning the user data.
///
/// Equivalent to `build()?.run()`.
pub fn run(self) -> WVResult<T> {
@@ -386,7 +390,8 @@ impl<'a, T> WebView<'a, T> {
}
}

- /// Creates a thread-safe [`Handle`] to the `WebView`, from which closures can be dispatched.
+ /// Creates a thread-safe [`Handle`] to the `WebView`, from which closures
+ /// can be dispatched.
///
/// [`Handle`]: struct.Handle.html
pub fn handle(&self) -> Handle<T> {
@@ -434,7 +439,8 @@ impl<'a, T> WebView<'a, T> {
unsafe { webview_exit(self.inner.unwrap()) }
}

- /// Executes the provided string as JavaScript code within the `WebView` instance.
+ /// Executes the provided string as JavaScript code within the `WebView`
+ /// instance.
pub fn eval(&mut self, js: &str) -> WVResult {
let js = CString::new(js)?;
let ret = unsafe { webview_eval(self.inner.unwrap(), js.as_ptr()) };
@@ -522,13 +528,15 @@ impl<'a, T> WebView<'a, T> {

/// Returns a builder for opening a new dialog window.
#[deprecated(
- note = "Please use crates like 'tinyfiledialogs' for dialog handling, see example in examples/dialog.rs"
+ note = "Please use crates like 'tinyfiledialogs' for dialog handling, see example in \
+ examples/dialog.rs"
)]
pub fn dialog<'b>(&'b mut self) -> DialogBuilder<'a, 'b, T> {
DialogBuilder::new(self)
}

- /// Iterates the event loop. Returns `None` if the view has been closed or terminated.
+ /// Iterates the event loop. Returns `None` if the view has been closed or
+ /// terminated.
pub fn step(&mut self) -> Option<WVResult> {
unsafe {
match webview_loop(self.inner.unwrap(), 1) {
@@ -591,7 +599,8 @@ impl<'a, T> Drop for WebView<'a, T> {
}
}

-/// A thread-safe handle to a [`WebView`] instance. Used to dispatch closures onto its task queue.
+/// A thread-safe handle to a [`WebView`] instance. Used to dispatch closures
+/// onto its task queue.
///
/// [`WebView`]: struct.WebView.html
pub struct Handle<T> {
@@ -617,7 +626,8 @@ impl<T> Handle<T> {
///
/// Returns [`Error::Dispatch`] if the [`WebView`] has been dropped.
///
- /// If the closure returns an `Err`, it will be returned on the next call to [`step()`].
+ /// If the closure returns an `Err`, it will be returned on the next call to
+ /// [`step()`].
///
/// [`WebView`]: struct.WebView.html
/// [`Error::Dispatch`]: enum.Error.html#variant.Dispatch
@@ -626,8 +636,8 @@ impl<T> Handle<T> {
where
F: FnOnce(&mut WebView<T>) -> WVResult + Send + 'static,
{
- // Abort if WebView has been dropped. Otherwise, keep it alive until closure has been
- // dispatched.
+ // Abort if WebView has been dropped. Otherwise, keep it alive until closure has
+ // been dispatched.
let mutex = self.live.upgrade().ok_or(Error::Dispatch)?;
let closure = Box::new(SendBoxFnOnce::new(f));
let _lock = mutex.read().map_err(|_| Error::Dispatch)?;
Author Public Key
npub1p6ds6sglqershqf8xlqglpfujvfgz77wkrnf6d5t0p03wwp64rmqajsykv