-
-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking(ish): pane.get_current_working_dir now returns Url
Previously we'd return the Url string. Now we provide a Url object that provides access to the various elements of the Url. This will cause slightly breakage for folks that were treating it as a string in their status event handlers, for example. The docs have been updated to show how to run with both this new Url object and also continue to run on older versions of wezterm. They now also show how to manually percent decode the url for older versions of wezterm. refs: #4157 refs: #4000
- Loading branch information
Showing
17 changed files
with
223 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,32 @@ | ||
# Url object | ||
|
||
{{since('nightly')}} | ||
|
||
The `Url` object represents a parsed Url. It has the following fields: | ||
|
||
* `scheme` - the URL scheme such as `"file"`, or `"https"` | ||
* `file_path` - decodes the `path` field and interprets it as a file path | ||
* `username` - the username portion of the URL, or an empty string if none is specified | ||
* `password` - the password portion of the URL, or `nil` if none is specified | ||
* `host` - the hostname portion of the URL, with IDNA decoded to UTF-8 | ||
* `path` - the path portion of the URL, complete with percent encoding | ||
* `fragment` - the fragment portion of the URL | ||
* `query` - the query portion of the URL | ||
|
||
```lua | ||
local wezterm = require 'wezterm' | ||
|
||
local url = wezterm.url.parse 'file://myhost/some/path%20with%20spaces' | ||
assert(url.scheme == 'file') | ||
assert(url.file_path == '/some/path with spaces') | ||
|
||
local url = | ||
wezterm.url.parse 'https://github.com/rust-lang/rust/issues?labels=E-easy&state=open' | ||
assert(url.scheme == 'https') | ||
assert(url.username == '') | ||
assert(url.password == nil) | ||
assert(url.host == 'github.com') | ||
assert(url.path == '/rust-lang/rust/issues') | ||
assert(url.query == 'labels=E-easy&state=open') | ||
``` | ||
|
This file contains 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,10 @@ | ||
# `wezterm.url` module | ||
|
||
{{since('nightly')}} | ||
|
||
The `wezterm.url` module exposes functions that allow working | ||
with URLs. | ||
|
||
## Available functions and objects | ||
|
||
|
This file contains 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,7 @@ | ||
# `wezterm.url.parse(URL_STRING)` | ||
|
||
{{since('nightly')}} | ||
|
||
Attempts to parse the provided *URL_STRING* as a URL. | ||
If success, returns a [Url](Url.md) object representing that URL. | ||
|
This file contains 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 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 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 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 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 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,14 @@ | ||
[package] | ||
name = "url-funcs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
config = { path = "../../config" } | ||
luahelper = { path = "../../luahelper" } | ||
percent-encoding = "2.3" | ||
url = "2" | ||
wezterm-dynamic = { path = "../../wezterm-dynamic" } |
This file contains 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,83 @@ | ||
use crate::mlua::UserDataFields; | ||
use config::lua::get_or_create_sub_module; | ||
use config::lua::mlua::{self, Lua, MetaMethod, UserData, UserDataMethods}; | ||
use percent_encoding::percent_decode; | ||
|
||
pub fn register(lua: &Lua) -> anyhow::Result<()> { | ||
let url_mod = get_or_create_sub_module(lua, "url")?; | ||
|
||
url_mod.set( | ||
"parse", | ||
lua.create_function(|_, s: String| { | ||
let url = url::Url::parse(&s).map_err(|err| { | ||
mlua::Error::external(format!("{err:#} while parsing {s} as URL")) | ||
})?; | ||
Ok(Url { url }) | ||
})?, | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Url { | ||
pub url: url::Url, | ||
} | ||
|
||
impl std::ops::Deref for Url { | ||
type Target = url::Url; | ||
fn deref(&self) -> &url::Url { | ||
&self.url | ||
} | ||
} | ||
|
||
impl std::ops::DerefMut for Url { | ||
fn deref_mut(&mut self) -> &mut url::Url { | ||
&mut self.url | ||
} | ||
} | ||
|
||
impl UserData for Url { | ||
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { | ||
methods.add_meta_method(MetaMethod::ToString, |_, this, _: ()| { | ||
Ok(this.url.as_str().to_string()) | ||
}); | ||
} | ||
|
||
fn add_fields<'lua, F: UserDataFields<'lua, Self>>(fields: &mut F) { | ||
fields.add_field_method_get("scheme", |_, this| Ok(this.scheme().to_string())); | ||
fields.add_field_method_get("username", |_, this| Ok(this.username().to_string())); | ||
fields.add_field_method_get("password", |_, this| { | ||
Ok(this.password().map(|s| s.to_string())) | ||
}); | ||
fields.add_field_method_get("host", |_, this| Ok(this.host_str().map(|s| s.to_string()))); | ||
fields.add_field_method_get("port", |_, this| Ok(this.port())); | ||
fields.add_field_method_get("query", |_, this| Ok(this.query().map(|s| s.to_string()))); | ||
fields.add_field_method_get("fragment", |_, this| { | ||
Ok(this.fragment().map(|s| s.to_string())) | ||
}); | ||
fields.add_field_method_get("path", |_, this| Ok(this.path().to_string())); | ||
fields.add_field_method_get("file_path", |lua, this| { | ||
if let Some(segments) = this.path_segments() { | ||
let mut bytes = vec![]; | ||
for segment in segments { | ||
bytes.push(b'/'); | ||
bytes.extend(percent_decode(segment.as_bytes())); | ||
} | ||
|
||
// A windows drive letter must end with a slash. | ||
if bytes.len() > 2 | ||
&& bytes[bytes.len() - 2].is_ascii_alphabetic() | ||
&& matches!(bytes[bytes.len() - 1], b':' | b'|') | ||
{ | ||
bytes.push(b'/'); | ||
} | ||
|
||
let s = lua.create_string(bytes)?; | ||
Ok(Some(s)) | ||
} else { | ||
Ok(None) | ||
} | ||
}); | ||
} | ||
} |
This file contains 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 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