feat: version 0.0.0-working-ui
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
9de5e6bbff
commit
21fc587e6e
169
Cargo.lock
generated
169
Cargo.lock
generated
@ -2,6 +2,21 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "addr2line"
|
||||||
|
version = "0.21.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
|
||||||
|
dependencies = [
|
||||||
|
"gimli",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.8.7"
|
version = "0.8.7"
|
||||||
@ -39,12 +54,27 @@ dependencies = [
|
|||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
"anstyle-query",
|
"anstyle-query",
|
||||||
"anstyle-wincon",
|
"anstyle-wincon 1.0.1",
|
||||||
"colorchoice",
|
"colorchoice",
|
||||||
"is-terminal",
|
"is-terminal",
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon 3.0.3",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle"
|
name = "anstyle"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@ -79,6 +109,16 @@ dependencies = [
|
|||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.71"
|
version = "1.0.71"
|
||||||
@ -176,6 +216,21 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace"
|
||||||
|
version = "0.3.71"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
|
||||||
|
dependencies = [
|
||||||
|
"addr2line",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"miniz_oxide",
|
||||||
|
"object",
|
||||||
|
"rustc-demangle",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.21.7"
|
version = "0.21.7"
|
||||||
@ -263,9 +318,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.79"
|
version = "1.0.96"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
@ -290,7 +345,7 @@ version = "4.3.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c1458a1df40e1e2afebb7ab60ce55c1fa8f431146205aa5f4887e0b111c27636"
|
checksum = "c1458a1df40e1e2afebb7ab60ce55c1fa8f431146205aa5f4887e0b111c27636"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream 0.3.2",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"clap_lex",
|
"clap_lex",
|
||||||
@ -689,6 +744,12 @@ dependencies = [
|
|||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gimli"
|
||||||
|
version = "0.28.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
@ -830,6 +891,22 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "human-panic"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4c5d0e9120f6bca6120d142c7ede1ba376dd6bf276d69dd3dbe6cbeb7824179"
|
||||||
|
dependencies = [
|
||||||
|
"anstream 0.6.14",
|
||||||
|
"anstyle",
|
||||||
|
"backtrace",
|
||||||
|
"os_info",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"toml",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -918,6 +995,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"directories",
|
"directories",
|
||||||
|
"human-panic",
|
||||||
"hyperlog-core",
|
"hyperlog-core",
|
||||||
"itertools",
|
"itertools",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
@ -977,6 +1055,12 @@ dependencies = [
|
|||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
@ -1114,6 +1198,15 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
|
||||||
|
dependencies = [
|
||||||
|
"adler",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.8.8"
|
version = "0.8.8"
|
||||||
@ -1215,6 +1308,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object"
|
||||||
|
version = "0.32.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.18.0"
|
version = "1.18.0"
|
||||||
@ -1227,6 +1329,17 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_info"
|
||||||
|
version = "3.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -1514,6 +1627,12 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-demangle"
|
||||||
|
version = "0.1.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.37.20"
|
version = "0.37.20"
|
||||||
@ -1639,6 +1758,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
@ -2251,6 +2379,39 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.8.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
"toml_edit",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_datetime"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml_edit"
|
||||||
|
version = "0.22.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned",
|
||||||
|
"toml_datetime",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower"
|
name = "tower"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
|
@ -13,7 +13,7 @@ pub enum ItemState {
|
|||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, PartialEq, Eq, Clone)]
|
#[derive(Deserialize, Serialize, PartialEq, Eq, Clone, Debug)]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum GraphItem {
|
pub enum GraphItem {
|
||||||
#[serde(rename = "user")]
|
#[serde(rename = "user")]
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
name = "hyperlog-tui"
|
name = "hyperlog-tui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
repository = "https://git.front.kjuulh.io/kjuulh/hyperlog"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hyperlog-core.workspace = true
|
hyperlog-core.workspace = true
|
||||||
@ -16,6 +17,7 @@ itertools.workspace = true
|
|||||||
ratatui = "0.26.2"
|
ratatui = "0.26.2"
|
||||||
crossterm = { version = "0.27.0", features = ["event-stream"] }
|
crossterm = { version = "0.27.0", features = ["event-stream"] }
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
|
human-panic = "2.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
similar-asserts = "1.5.0"
|
similar-asserts = "1.5.0"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{collections::HashMap, ops::Deref};
|
use std::ops::Deref;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use hyperlog_core::log::GraphItem;
|
use hyperlog_core::log::GraphItem;
|
||||||
@ -15,7 +15,7 @@ pub struct GraphExplorer<'a> {
|
|||||||
|
|
||||||
pub struct GraphExplorerState<'a> {
|
pub struct GraphExplorerState<'a> {
|
||||||
current_path: Option<&'a str>,
|
current_path: Option<&'a str>,
|
||||||
current_postition: Vec<usize>,
|
current_position: Vec<usize>,
|
||||||
|
|
||||||
graph: Option<GraphItem>,
|
graph: Option<GraphItem>,
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ impl GraphExplorer<'_> {
|
|||||||
state,
|
state,
|
||||||
inner: GraphExplorerState::<'_> {
|
inner: GraphExplorerState::<'_> {
|
||||||
current_path: None,
|
current_path: None,
|
||||||
current_postition: Vec::new(),
|
current_position: Vec::new(),
|
||||||
graph: None,
|
graph: None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -37,7 +37,8 @@ impl GraphExplorer<'_> {
|
|||||||
.state
|
.state
|
||||||
.querier
|
.querier
|
||||||
.get(
|
.get(
|
||||||
"something",
|
// FIXME: Replace with a setting or default instead, probaby user
|
||||||
|
"kjuulh",
|
||||||
self.inner
|
self.inner
|
||||||
.current_path
|
.current_path
|
||||||
.map(|p| p.split('.').collect::<Vec<_>>())
|
.map(|p| p.split('.').collect::<Vec<_>>())
|
||||||
@ -61,11 +62,12 @@ impl GraphExplorer<'_> {
|
|||||||
/// Choses: 0.1.0.0 else nothing
|
/// Choses: 0.1.0.0 else nothing
|
||||||
pub(crate) fn move_right(&mut self) -> Result<()> {
|
pub(crate) fn move_right(&mut self) -> Result<()> {
|
||||||
if let Some(graph) = self.linearize_graph() {
|
if let Some(graph) = self.linearize_graph() {
|
||||||
let position_items = &self.inner.current_postition;
|
tracing::debug!("graph: {:?}", graph);
|
||||||
|
let position_items = &self.inner.current_position;
|
||||||
|
|
||||||
if let Some(next_item) = graph.next_right(position_items) {
|
if let Some(next_item) = graph.next_right(position_items) {
|
||||||
self.inner.current_postition.push(next_item.index);
|
self.inner.current_position.push(next_item.index);
|
||||||
tracing::trace!("found next item: {:?}", self.inner.current_postition);
|
tracing::trace!("found next item: {:?}", self.inner.current_position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,13 +77,13 @@ impl GraphExplorer<'_> {
|
|||||||
/// Will only incrmeent to the next level
|
/// Will only incrmeent to the next level
|
||||||
///
|
///
|
||||||
/// Current: 0.1.0
|
/// Current: 0.1.0
|
||||||
/// Available: 0.[0.1.2].0
|
/// Available: 0.[0,1,2].0
|
||||||
/// Choses: 0.1 else nothing
|
/// Choses: 0.1 else nothing
|
||||||
pub(crate) fn move_left(&mut self) -> Result<()> {
|
pub(crate) fn move_left(&mut self) -> Result<()> {
|
||||||
if let Some(last) = self.inner.current_postition.pop() {
|
if let Some(last) = self.inner.current_position.pop() {
|
||||||
tracing::trace!(
|
tracing::trace!(
|
||||||
"found last item: {:?}, popped: {}",
|
"found last item: {:?}, popped: {}",
|
||||||
self.inner.current_postition,
|
self.inner.current_position,
|
||||||
last
|
last
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -89,15 +91,147 @@ impl GraphExplorer<'_> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn move_up(&self) -> Result<()> {
|
/// Will move up if a sibling exists, or up to the most common sibling between sections
|
||||||
|
///
|
||||||
|
/// Current: 0.1.1
|
||||||
|
/// Available: 0.[0.[0,1],1.[0,1]]
|
||||||
|
/// Chose: 0.1.0 again 0.0 We don't choose a subitem in the next three instead we just find the most common sibling
|
||||||
|
pub(crate) fn move_up(&mut self) -> Result<()> {
|
||||||
|
if let Some(graph) = self.linearize_graph() {
|
||||||
|
let position_items = &self.inner.current_position;
|
||||||
|
|
||||||
|
if let Some(next_item) = graph.next_up(position_items) {
|
||||||
|
self.inner.current_position = next_item;
|
||||||
|
tracing::trace!("found next up: {:?}", self.inner.current_position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn move_down(&self) -> Result<()> {
|
/// Will move down if a sibling exists, or down to the most common sibling between sections
|
||||||
|
///
|
||||||
|
/// Current: 0.0.0
|
||||||
|
/// Available: 0.[0.[0,1],1.[0,1]]
|
||||||
|
/// Chose: 0.0.1 again 0.1
|
||||||
|
pub(crate) fn move_down(&mut self) -> Result<()> {
|
||||||
|
if let Some(graph) = self.linearize_graph() {
|
||||||
|
let position_items = &self.inner.current_position;
|
||||||
|
|
||||||
|
if let Some(next_item) = graph.next_down(position_items) {
|
||||||
|
self.inner.current_position = next_item;
|
||||||
|
tracing::trace!("found next down: {:?}", self.inner.current_position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait RenderGraph {
|
||||||
|
fn render_graph(&self, items: &[usize]) -> Vec<Line>;
|
||||||
|
fn render_graph_spans(&self, items: &[usize]) -> Vec<Vec<Span>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderGraph for MovementGraph {
|
||||||
|
/// render_graph takes each level of items, renders them, and finally renders a strongly set selector for the current item the user is on
|
||||||
|
/// This is done from buttom up, and composed via. string padding
|
||||||
|
fn render_graph(&self, items: &[usize]) -> Vec<Line> {
|
||||||
|
// Gets the inner content of the strings
|
||||||
|
|
||||||
|
let mut lines = Vec::new();
|
||||||
|
|
||||||
|
for item in &self.items {
|
||||||
|
match items.split_first().map(|(first, rest)| {
|
||||||
|
if item.index == *first {
|
||||||
|
(true, rest)
|
||||||
|
} else {
|
||||||
|
(false, rest)
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Some((true, rest)) => {
|
||||||
|
if rest.is_empty() {
|
||||||
|
lines
|
||||||
|
.push(Line::raw(format!("- {}", item.name)).style(Style::new().bold()));
|
||||||
|
} else {
|
||||||
|
lines.push(Line::raw(format!("- {}", item.name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.push("".into());
|
||||||
|
|
||||||
|
let embedded_sections = item.values.render_graph_spans(rest);
|
||||||
|
for section in &embedded_sections {
|
||||||
|
let mut line = vec![Span::raw(" ")];
|
||||||
|
line.extend_from_slice(section);
|
||||||
|
lines.push(Line::from(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
lines.push(Line::raw(format!("- {}", item.name)));
|
||||||
|
|
||||||
|
lines.push("".into());
|
||||||
|
|
||||||
|
let embedded_sections = item.values.render_graph_spans(&[]);
|
||||||
|
for section in &embedded_sections {
|
||||||
|
let mut line = vec![Span::raw(" ")];
|
||||||
|
line.extend_from_slice(section);
|
||||||
|
lines.push(Line::from(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lines
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_graph_spans(&self, items: &[usize]) -> Vec<Vec<Span>> {
|
||||||
|
let mut lines = Vec::new();
|
||||||
|
|
||||||
|
for item in &self.items {
|
||||||
|
match items.split_first().map(|(first, rest)| {
|
||||||
|
if item.index == *first {
|
||||||
|
(true, rest)
|
||||||
|
} else {
|
||||||
|
(false, rest)
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Some((true, rest)) => {
|
||||||
|
let mut line = Vec::new();
|
||||||
|
if rest.is_empty() {
|
||||||
|
line.push(Span::raw(format!("- {}", item.name)).style(Style::new().bold()));
|
||||||
|
} else {
|
||||||
|
line.push(Span::raw(format!("- {}", item.name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.push(line);
|
||||||
|
lines.push(vec!["".into()]);
|
||||||
|
|
||||||
|
let embedded_sections = item.values.render_graph_spans(rest);
|
||||||
|
for section in &embedded_sections {
|
||||||
|
let mut line = vec![Span::raw(" ")];
|
||||||
|
line.extend_from_slice(section);
|
||||||
|
lines.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
lines.push(vec![Span::raw(format!("- {}", item.name))]);
|
||||||
|
|
||||||
|
lines.push(vec!["".into()]);
|
||||||
|
|
||||||
|
let embedded_sections = item.values.render_graph_spans(&[]);
|
||||||
|
for section in &embedded_sections {
|
||||||
|
let mut line = vec![Span::raw(" ")];
|
||||||
|
line.extend_from_slice(section);
|
||||||
|
lines.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> StatefulWidget for GraphExplorer<'a> {
|
impl<'a> StatefulWidget for GraphExplorer<'a> {
|
||||||
type State = GraphExplorerState<'a>;
|
type State = GraphExplorerState<'a>;
|
||||||
|
|
||||||
@ -106,20 +240,13 @@ impl<'a> StatefulWidget for GraphExplorer<'a> {
|
|||||||
let height = height as usize;
|
let height = height as usize;
|
||||||
|
|
||||||
if let Some(graph) = &state.graph {
|
if let Some(graph) = &state.graph {
|
||||||
if let Ok(graph) = serde_json::to_string_pretty(graph) {
|
let movement_graph: MovementGraph = graph.clone().into();
|
||||||
let lines = graph
|
let lines = movement_graph.render_graph(&state.current_position);
|
||||||
.split('\n')
|
|
||||||
.take(height)
|
|
||||||
.map(Line::raw)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let para = Paragraph::new(lines);
|
let para = Paragraph::new(lines);
|
||||||
|
|
||||||
para.render(area, buf);
|
para.render(area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
struct MovementGraphItem {
|
struct MovementGraphItem {
|
||||||
@ -143,6 +270,53 @@ impl MovementGraph {
|
|||||||
None => self.items.first().cloned(),
|
None => self.items.first().cloned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_up(&self, items: &[usize]) -> Option<Vec<usize>> {
|
||||||
|
match items.split_last() {
|
||||||
|
Some((0, _)) => None,
|
||||||
|
Some((current_index, rest)) => {
|
||||||
|
let mut vec = rest.to_vec();
|
||||||
|
vec.push(current_index - 1);
|
||||||
|
|
||||||
|
Some(vec)
|
||||||
|
}
|
||||||
|
// May need to reduce this to an Some(Vec::default()) instead
|
||||||
|
//None => Some(self.items.iter().map(|i| i.index).collect_vec()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_down(&self, items: &[usize]) -> Option<Vec<usize>> {
|
||||||
|
match items.split_last() {
|
||||||
|
Some((current_index, rest)) => {
|
||||||
|
if let Some(current_item) = self.get_graph_item(rest) {
|
||||||
|
if *current_index + 1 < current_item.items.len() {
|
||||||
|
let mut vec = rest.to_vec();
|
||||||
|
vec.push(current_index + 1);
|
||||||
|
|
||||||
|
Some(vec)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// May need to reduce this to an Some(Vec::default()) instead
|
||||||
|
//None => Some(self.items.iter().map(|i| i.index).collect_vec()),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_graph_item(&self, items: &[usize]) -> Option<&MovementGraph> {
|
||||||
|
match items.split_first() {
|
||||||
|
Some((first, rest)) => match self.items.get(*first).map(|s| &s.values) {
|
||||||
|
Some(next_graph) => next_graph.get_graph_item(rest),
|
||||||
|
None => Some(self),
|
||||||
|
},
|
||||||
|
None => Some(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<GraphItem>> for MovementGraph {
|
impl From<Box<GraphItem>> for MovementGraph {
|
||||||
@ -259,7 +433,7 @@ mod test {
|
|||||||
MovementGraphItem {
|
MovementGraphItem {
|
||||||
index: 0,
|
index: 0,
|
||||||
name: "00".into(),
|
name: "00".into(),
|
||||||
values: MovementGraph::default()
|
values: MovementGraph::default(),
|
||||||
},
|
},
|
||||||
MovementGraphItem {
|
MovementGraphItem {
|
||||||
index: 1,
|
index: 1,
|
||||||
@ -286,4 +460,234 @@ mod test {
|
|||||||
actual
|
actual
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_graph_item() -> anyhow::Result<()> {
|
||||||
|
let graph = MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 2,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 2,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
let actual_default = graph.get_graph_item(&[]);
|
||||||
|
assert_eq!(Some(&graph), actual_default);
|
||||||
|
|
||||||
|
let actual_first = graph.get_graph_item(&[0]);
|
||||||
|
assert_eq!(graph.items.first().map(|i| &i.values), actual_first);
|
||||||
|
|
||||||
|
let actual_second = graph.get_graph_item(&[1]);
|
||||||
|
assert_eq!(graph.items.get(1).map(|i| &i.values), actual_second);
|
||||||
|
|
||||||
|
let actual_nested = graph.get_graph_item(&[0, 0]);
|
||||||
|
assert_eq!(
|
||||||
|
graph
|
||||||
|
.items
|
||||||
|
.first()
|
||||||
|
.and_then(|i| i.values.items.first())
|
||||||
|
.map(|i| &i.values),
|
||||||
|
actual_nested
|
||||||
|
);
|
||||||
|
|
||||||
|
let actual_nested = graph.get_graph_item(&[0, 1]);
|
||||||
|
assert_eq!(
|
||||||
|
graph
|
||||||
|
.items
|
||||||
|
.first()
|
||||||
|
.and_then(|i| i.values.items.get(1))
|
||||||
|
.map(|i| &i.values),
|
||||||
|
actual_nested
|
||||||
|
);
|
||||||
|
|
||||||
|
let actual_nested = graph.get_graph_item(&[1, 2]);
|
||||||
|
assert_eq!(
|
||||||
|
graph
|
||||||
|
.items
|
||||||
|
.get(1)
|
||||||
|
.and_then(|i| i.values.items.get(2))
|
||||||
|
.map(|i| &i.values),
|
||||||
|
actual_nested
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn can_next_down() -> anyhow::Result<()> {
|
||||||
|
let graph = MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "1".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "1".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 2,
|
||||||
|
name: "2".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "0".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "1".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 2,
|
||||||
|
name: "2".into(),
|
||||||
|
values: MovementGraph::default(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
let actual = graph.next_down(&[]);
|
||||||
|
assert_eq!(None, actual);
|
||||||
|
|
||||||
|
let actual = graph.next_down(&[0]);
|
||||||
|
assert_eq!(Some(vec![1]), actual);
|
||||||
|
|
||||||
|
let actual = graph.next_down(&[1]);
|
||||||
|
assert_eq!(Some(vec![2]), actual);
|
||||||
|
|
||||||
|
let actual = graph.next_down(&[2]);
|
||||||
|
assert_eq!(None, actual);
|
||||||
|
|
||||||
|
let graph = MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "other".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "other".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "other".into(),
|
||||||
|
values: MovementGraph { items: vec![] },
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "some".into(),
|
||||||
|
values: MovementGraph { items: vec![] },
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 2,
|
||||||
|
name: "something".into(),
|
||||||
|
values: MovementGraph {
|
||||||
|
items: vec![
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 0,
|
||||||
|
name: "else".into(),
|
||||||
|
values: MovementGraph { items: vec![] },
|
||||||
|
},
|
||||||
|
MovementGraphItem {
|
||||||
|
index: 1,
|
||||||
|
name: "third".into(),
|
||||||
|
values: MovementGraph { items: vec![] },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
let actual = graph.next_down(&[0]);
|
||||||
|
assert_eq!(Some(vec![1]), actual);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,9 @@ pub fn initialize_panic_handler() -> anyhow::Result<()> {
|
|||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
use human_panic::{handle_dump, print_msg, Metadata};
|
use human_panic::{handle_dump, print_msg, Metadata};
|
||||||
let meta = Metadata {
|
let meta = Metadata::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
|
||||||
version: env!("CARGO_PKG_VERSION").into(),
|
.authors(env!("CARGO_PKG_AUTHORS").replace(':', ", "))
|
||||||
name: env!("CARGO_PKG_NAME").into(),
|
.homepage(env!("CARGO_PKG_HOMEPAGE"));
|
||||||
authors: env!("CARGO_PKG_AUTHORS").replace(':', ", ").into(),
|
|
||||||
homepage: env!("CARGO_PKG_HOMEPAGE").into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_path = handle_dump(&meta, panic_info);
|
let file_path = handle_dump(&meta, panic_info);
|
||||||
// prints human-panic message
|
// prints human-panic message
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
name = "hyperlog"
|
name = "hyperlog"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
repository = "https://git.front.kjuulh.io/kjuulh/hyperlog"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
hyperlog-core.workspace = true
|
hyperlog-core.workspace = true
|
||||||
|
Loading…
Reference in New Issue
Block a user