Compare commits

...

20 Commits

@ -49,17 +49,17 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

@ -13,17 +13,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@ -57,17 +57,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@ -90,17 +90,17 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

@ -1,4 +1,23 @@
## v0.1.12-dev
## v0.1.15
- Update `alphanumeric-sort` dependency so `cargo install phd` works again.
- Recommend `cargo install phd --locked` in the README
## v0.1.14
- If the `NO_COLOR` env variable is set, colors won't be printed to
the log. Same as starting with `--no-color`.
See https://no-color.org/.
## v0.1.13
- Added `--no-color` command line option to not display color when
logging.
- Slight change to binding behavior: if `-p` is passed without `-b`,
we'll try to bind to that port. To this easier: `phd -p 7777`
- Accept `?` as query string indicator, not just `TAB`. See #3.
## v0.1.12
`phd` now uses `-b` and `--bind` to set the host and port to
bind to. `-p` and `-h` are now strictly for URL generation.
@ -20,7 +39,6 @@ For now you can view it by cloning the repository and running:
Enjoy!
## v0.1.10
`phd` can now render a single page to stdout, instead of starting

42
Cargo.lock generated

@ -1,74 +1,74 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "alphanumeric-sort"
version = "1.0.11"
version = "1.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77e9c9abb82613923ec78d7a461595d52491ba7240f3c64c0bbe0e6d98e0fce0"
[[package]]
name = "content_inspector"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
dependencies = [
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr",
]
[[package]]
name = "hermit-abi"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7"
dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"libc",
]
[[package]]
name = "libc"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
[[package]]
name = "memchr"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
[[package]]
name = "num_cpus"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
dependencies = [
"hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"hermit-abi",
"libc",
]
[[package]]
name = "phd"
version = "0.1.12"
version = "0.1.15"
dependencies = [
"alphanumeric-sort 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"content_inspector 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"alphanumeric-sort",
"content_inspector",
"shell-escape",
"threadpool",
]
[[package]]
name = "shell-escape"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
[[package]]
name = "threadpool"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
dependencies = [
"num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus",
]
[metadata]
"checksum alphanumeric-sort 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f37ce94154d73f6961f87571a3ab7814e1608f373bd55a933e3e771b6dd59fc4"
"checksum content_inspector 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38"
"checksum hermit-abi 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f629dc602392d3ec14bfc8a09b5e644d7ffd725102b48b81e59f90f2633621d7"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72"
"checksum shell-escape 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "170a13e64f2a51b77a45702ba77287f5c6829375b04a69cf2222acd17d0cfab9"
"checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"

@ -1,6 +1,6 @@
[package]
name = "phd"
version = "0.1.12"
version = "0.1.15"
authors = ["chris west <c@xvxx.io>"]
license = "MIT"
edition = "2018"
@ -22,11 +22,11 @@ opt-level = 'z' # Optimize for size.
pre-release-replacements = [
{file="README.md", search="phd-v\\d+\\.\\d+\\.\\d+-", replace="{{crate_name}}-v{{version}}-"},
{file="README.md", search="/v\\d+\\.\\d+\\.\\d+/", replace="/v{{version}}/"},
{file="CHANGELOG.md", search="\\d+\\.\\d+\\.\\d+-dev", replace="{{version}}"},
]
dev-version-ext = "dev"
[dependencies]
content_inspector = "0.2.4"
threadpool = "1.7.1"
alphanumeric-sort = "1.0.11"
alphanumeric-sort = "1.4"
shell-escape = "0.1.4"

@ -142,6 +142,7 @@ of Gopher!
-h, --host HOST Hostname for links. [Default: {host}]
-p, --port PORT Port for links. [Default: {port}]
-b, --bind ADDRESS Socket address to bind to. [Default: {bind}]
--no-color Don't show colors in log messages.
Other flags:
@ -165,15 +166,15 @@ On macOS you can install with [Homebrew](https://brew.sh/):
Binaries for Linux, Mac, and Raspberry Pi are available at
gopher://phkt.io/1/releases/phd and https://github.com/xvxx/phd/releases:
- [phd-v0.1.12-linux-x86_64.tar.gz][0]
- [phd-v0.1.12-linux-armv7.tar.gz (Raspberry Pi)][1]
- [phd-v0.1.12-macos.zip][2]
- [phd-v0.1.15-linux-x86_64.tar.gz][0]
- [phd-v0.1.15-linux-armv7.tar.gz (Raspberry Pi)][1]
- [phd-v0.1.15-macos.zip][2]
Just unzip/untar the `phd` program into your `$PATH` and get going!
If you have **[cargo][rustup]**, you can install the crate directly:
cargo install phd
cargo install phd --locked
## ~ development ~
@ -192,9 +193,13 @@ If you have **[cargo][rustup]**, you can install the crate directly:
- [ ] TLS support
- [ ] user input sanitization tests
[0]: https://github.com/xvxx/phd/releases/download/v0.1.12/phd-v0.1.12-linux-x86_64.tar.gz
[1]: https://github.com/xvxx/phd/releases/download/v0.1.12/phd-v0.1.12-linux-armv7.tar.gz
[2]: https://github.com/xvxx/phd/releases/download/v0.1.12/phd-v0.1.12-macos.zip
## ~ status ~
phd is no longer under active development, but the latest version works great.
[0]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-linux-x86_64.tar.gz
[1]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-linux-armv7.tar.gz
[2]: https://github.com/xvxx/phd/releases/download/v0.1.15/phd-v0.1.15-macos.zip
[map]: https://en.wikipedia.org/wiki/Gopher_(protocol)#Source_code_of_a_menu
[gmi]: http://r-36.net/scm/geomyidae/
[rustup]: https://rustup.rs

@ -5,7 +5,24 @@
//! println!("{}Error: {}{}", color::Red, "Something broke.", color::Reset);
//! ```
use std::fmt;
use std::{
fmt,
sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
};
/// Whether to show colors or not.
/// Defaults to true.
static SHOW_COLORS: AtomicBool = AtomicBool::new(true);
/// Hide colors.
pub fn hide_colors() {
SHOW_COLORS.swap(false, AtomicOrdering::Relaxed);
}
/// Are we showing colors are not?
pub fn showing_colors() -> bool {
SHOW_COLORS.load(AtomicOrdering::Relaxed)
}
macro_rules! color {
($t:ident, $code:expr) => {
@ -13,7 +30,11 @@ macro_rules! color {
pub struct $t;
impl fmt::Display for $t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\x1b[{}m", $code)
if showing_colors() {
write!(f, "\x1b[{}m", $code)
} else {
write!(f, "")
}
}
}
};

@ -1,5 +1,4 @@
use phd;
use std::net::SocketAddr;
use std::process;
const DEFAULT_BIND: &str = "[::]:7070";
@ -10,14 +9,16 @@ fn main() {
let args = std::env::args().skip(1).collect::<Vec<_>>();
let mut args = args.iter();
let mut root = ".";
let mut bind: SocketAddr = DEFAULT_BIND.parse().unwrap();
let mut addr = DEFAULT_BIND;
let mut host = DEFAULT_HOST;
let mut port = DEFAULT_PORT;
let mut render = "";
while let Some(arg) = args.next() {
match arg.as_ref() {
"--version" | "-v" | "-version" => return print_version(),
"--help" | "-help" => return print_help(),
"--no-color" | "-no-color" => phd::color::hide_colors(),
"--render" | "-render" | "-r" => {
if let Some(path) = args.next() {
render = path;
@ -26,14 +27,8 @@ fn main() {
}
}
"--bind" | "-b" | "-bind" => {
if let Some(b) = args.next() {
bind = b
.parse()
.map_err(|_| {
eprintln!("bad socket bind: {}", b);
process::exit(1)
})
.unwrap();
if let Some(a) = args.next() {
addr = a
}
}
"--port" | "-p" | "-port" => {
@ -70,6 +65,18 @@ fn main() {
}
}
// https://no-color.org/
if std::env::var("NO_COLOR").is_ok() {
phd::color::hide_colors()
}
// If port was given and socket wasn't, bind to that port.
let bind = if port != DEFAULT_PORT && addr == DEFAULT_BIND {
format!("[::]:{}", port).parse().unwrap()
} else {
addr.parse().unwrap()
};
if !render.is_empty() {
return match phd::server::render(host, port, root, &render) {
Ok(out) => print!("{}", out),
@ -94,6 +101,7 @@ Options:
-h, --host HOST Hostname for links. [Default: {host}]
-p, --port PORT Port for links. [Default: {port}]
-b, --bind ADDRESS Socket address to bind to. [Default: {bind}]
--no-color Don't show colors in log messages.
Other flags:

@ -51,7 +51,11 @@ impl Request {
pub fn parse_request(&mut self, line: &str) {
self.query.clear();
self.selector.clear();
if let Some(i) = line.find('\t') {
if let Some((i, _)) = line
.chars()
.enumerate()
.find(|&(_, c)| c == '\t' || c == '?')
{
if line.len() > i {
self.query.push_str(&line[i + 1..]);
self.selector.push_str(&line[..i]);

@ -10,6 +10,7 @@ use std::{
path::Path,
process::Command,
str,
sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
};
use threadpool::ThreadPool;
@ -23,8 +24,6 @@ const MAX_PEEK_SIZE: usize = 1024;
/// Files not displayed in directory listings.
const IGNORED_FILES: [&str; 3] = ["header.gph", "footer.gph", ".reverse"];
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
/// Whether to print info!() messages to stdout.
/// Defaults to true.
static SHOW_INFO: AtomicBool = AtomicBool::new(true);
@ -411,7 +410,10 @@ fn sort_paths(dir_path: &str, reverse: bool) -> Result<Vec<DirEntry>> {
let a_is_dir = is_dir(a);
let b_is_dir = is_dir(b);
if a_is_dir && b_is_dir || !a_is_dir && !b_is_dir {
let ord = alphanumeric_sort::compare_os_str(a.path().as_ref(), b.path().as_ref());
let ord = alphanumeric_sort::compare_os_str::<&Path, &Path>(
a.path().as_ref(),
b.path().as_ref(),
);
if reverse {
ord.reverse()
} else {

Loading…
Cancel
Save