Skip to content
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

v0.6.0 #41

Merged
merged 45 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
579c01d
bump up version to v0.6.0
ynqa Dec 15, 2024
af0e33d
init: jsonz to manage serde_json::Value as viewable
ynqa Dec 12, 2024
ab9b969
chore: define `Row` for flatjson
ynqa Dec 12, 2024
dc826d5
chore: define tests for `create_rows` in advance
ynqa Dec 12, 2024
609e3d0
feat: create_rows
ynqa Dec 12, 2024
8fcd743
chore: define trait for Vec<Rows>
ynqa Dec 12, 2024
d770afe
chore: define tests for `up` in advance
ynqa Dec 12, 2024
e26867e
feat: up
ynqa Dec 12, 2024
698058e
chore: define tests for `down` in advance
ynqa Dec 12, 2024
90bb914
feat: down
ynqa Dec 12, 2024
76ef7ff
fix: do not move down on last collapsed element
ynqa Dec 12, 2024
087c33a
chore: define tests for `toggle` in advance
ynqa Dec 13, 2024
7ca9d5f
feat: toggle
ynqa Dec 13, 2024
c2d0440
chore: define tests for `extract` in advance
ynqa Dec 13, 2024
adba1d0
feat: extract
ynqa Dec 13, 2024
635adc7
fix: use toggle for up/down testings
ynqa Dec 13, 2024
f63d0a8
fix: toggle returns open index
ynqa Dec 13, 2024
13ec261
chore: test for jsonl
ynqa Dec 13, 2024
f8db9f3
on-error: use jsonz for json rendering (still old-version for jsonstr…
ynqa Dec 14, 2024
654317e
bug:
ynqa Dec 14, 2024
fbca186
resolve: comma for Open
ynqa Dec 14, 2024
cfdb9a4
chore: use … instead of ... for ellipsis
ynqa Dec 14, 2024
07816c8
resolve: active_item_attribute for line entire
ynqa Dec 14, 2024
53641ee
chore: mut is unnecessary for up/down
ynqa Dec 14, 2024
2abd7f6
FIX: snapshot is too slow for large data because of clone-cost for `b…
ynqa Dec 14, 2024
bf8b792
example: fixup json
ynqa Dec 14, 2024
740b90a
chore: do not require clone() for create_rows
ynqa Dec 14, 2024
0b985aa
cargo clippy
ynqa Dec 14, 2024
9352380
chore: define tests for `get_all_paths` in advance
ynqa Dec 14, 2024
bed0863
feat: get_all_paths
ynqa Dec 14, 2024
fd3b0ca
chore: give &[] instread of Vec for format_rows
ynqa Dec 15, 2024
f5f9778
chore: separate formatter for Vec<Row>
ynqa Dec 15, 2024
b911e1d
chore: add empty_str for ContainerType
ynqa Dec 15, 2024
65ef732
chore: add a comment about extract_rows and Close
ynqa Dec 15, 2024
d52a34c
chore: define tests for `format_raw_json` in advance
ynqa Dec 15, 2024
2d0394c
feat: format_raw_json
ynqa Dec 15, 2024
cb34e81
chore: define `rows` for JsonStream
ynqa Dec 15, 2024
1103a1a
chore: define tests for `tail` in advance
ynqa Dec 15, 2024
f011468
feat: tail
ynqa Dec 15, 2024
33db62e
feat: head
ynqa Dec 15, 2024
0c60005
feat: set_nodes_visibility
ynqa Dec 15, 2024
a367af6
chore: define tests for `set_nodes_visibility`
ynqa Dec 15, 2024
9364611
chore: use Vec<Row> methods for JsonStream
ynqa Dec 15, 2024
f54bb9f
Merge pull request #42 from ynqa/serde_json=>vec<row>
ynqa Dec 15, 2024
fd78850
chore: backward/forward => up/down
ynqa Dec 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Put the package in your `Cargo.toml`.

```toml
[dependencies]
promkit = "0.5.1"
promkit = "0.6.0"
```

## Features
Expand Down
3 changes: 2 additions & 1 deletion promkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "promkit"
version = "0.5.1"
version = "0.6.0"
authors = ["ynqa <un.pensiero.vano@gmail.com>"]
edition = "2021"
description = "A toolkit for building your own interactive command-line tools"
Expand All @@ -17,6 +17,7 @@ anyhow = "1.0.81"
crossterm = { version = "0.28.1", features = ["use-dev-tty"] }
indexmap = "2.2.3"
radix_trie = "0.2.1"
rayon = "1.10.0"
serde = { version = "1.0.197" }
serde_json = { version = "1.0.114", features = ["preserve_order"] }
unicode-width = "0.1.8"
255 changes: 237 additions & 18 deletions promkit/examples/json.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,248 @@
use promkit::{json::JsonStream, preset::json::Json, serde_json::Deserializer};
use promkit::{jsonstream::JsonStream, preset::json::Json};
use serde_json::Deserializer;

fn main() -> anyhow::Result<()> {
let stream = JsonStream::new(
Deserializer::from_str(
r#"{
"number": 9,
"map": {
"entry1": "first",
"entry2": "second"
},
"list": [
"abc",
"def"
]
}"#,
r#"
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"annotations": {
"kubeadm.kubernetes.io/etcd.advertise-client-urls": "https://172.18.0.2:2379",
"kubernetes.io/config.hash": "9c4c3ba79af7ad68d939c568f053bfff",
"kubernetes.io/config.mirror": "9c4c3ba79af7ad68d939c568f053bfff",
"kubernetes.io/config.seen": "2024-10-12T12:53:27.751706220Z",
"kubernetes.io/config.source": "file"
},
"creationTimestamp": "2024-10-12T12:53:31Z",
"labels": {
"component": "etcd",
"tier": "control-plane"
},
"name": "etcd-kind-control-plane",
"namespace": "kube-system",
"ownerReferences": [
{
"apiVersion": "v1",
"controller": true,
"kind": "Node",
"name": "kind-control-plane",
"uid": "6cb2c3e5-1a73-4932-9cc5-6d69b80a9932"
}
],
"resourceVersion": "192988",
"uid": "77465839-5a58-43b1-b754-55deed66d5ca"
},
"spec": {
"containers": [
{
"command": [
"etcd",
"--advertise-client-urls=https://172.18.0.2:2379",
"--cert-file=/etc/kubernetes/pki/etcd/server.crt",
"--client-cert-auth=true",
"--data-dir=/var/lib/etcd",
"--experimental-initial-corrupt-check=true",
"--experimental-watch-progress-notify-interval=5s",
"--initial-advertise-peer-urls=https://172.18.0.2:2380",
"--initial-cluster=kind-control-plane=https://172.18.0.2:2380",
"--key-file=/etc/kubernetes/pki/etcd/server.key",
"--listen-client-urls=https://127.0.0.1:2379,https://172.18.0.2:2379",
"--listen-metrics-urls=http://127.0.0.1:2381",
"--listen-peer-urls=https://172.18.0.2:2380",
"--name=kind-control-plane",
"--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt",
"--peer-client-cert-auth=true",
"--peer-key-file=/etc/kubernetes/pki/etcd/peer.key",
"--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt",
"--snapshot-count=10000",
"--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt"
],
"image": "registry.k8s.io/etcd:3.5.15-0",
"imagePullPolicy": "IfNotPresent",
"livenessProbe": {
"failureThreshold": 8,
"httpGet": {
"host": "127.0.0.1",
"path": "/livez",
"port": 2381,
"scheme": "HTTP"
},
"initialDelaySeconds": 10,
"periodSeconds": 10,
"successThreshold": 1,
"timeoutSeconds": 15
},
"name": "etcd",
"readinessProbe": {
"failureThreshold": 3,
"httpGet": {
"host": "127.0.0.1",
"path": "/readyz",
"port": 2381,
"scheme": "HTTP"
},
"periodSeconds": 1,
"successThreshold": 1,
"timeoutSeconds": 15
},
"resources": {
"requests": {
"cpu": "100m",
"memory": "100Mi"
}
},
"startupProbe": {
"failureThreshold": 24,
"httpGet": {
"host": "127.0.0.1",
"path": "/readyz",
"port": 2381,
"scheme": "HTTP"
},
"initialDelaySeconds": 10,
"periodSeconds": 10,
"successThreshold": 1,
"timeoutSeconds": 15
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/lib/etcd",
"name": "etcd-data"
},
{
"mountPath": "/etc/kubernetes/pki/etcd",
"name": "etcd-certs"
}
]
}
],
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"hostNetwork": true,
"nodeName": "kind-control-plane",
"preemptionPolicy": "PreemptLowerPriority",
"priority": 2000001000,
"priorityClassName": "system-node-critical",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {
"seccompProfile": {
"type": "RuntimeDefault"
}
},
"terminationGracePeriodSeconds": 30,
"tolerations": [
{
"effect": "NoExecute",
"operator": "Exists"
}
],
"volumes": [
{
"hostPath": {
"path": "/etc/kubernetes/pki/etcd",
"type": "DirectoryOrCreate"
},
"name": "etcd-certs"
},
{
"hostPath": {
"path": "/var/lib/etcd",
"type": "DirectoryOrCreate"
},
"name": "etcd-data"
}
]
},
"status": {
"conditions": [
{
"lastProbeTime": null,
"lastTransitionTime": "2024-12-06T13:28:35Z",
"status": "True",
"type": "PodReadyToStartContainers"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2024-12-06T13:28:34Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2024-12-06T13:28:50Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2024-12-06T13:28:50Z",
"status": "True",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2024-12-06T13:28:34Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [
{
"containerID": "containerd://de0d57479a3ac10e213df6ea4fc1d648ad4d70d4ddf1b95a7999d0050171a41e",
"image": "registry.k8s.io/etcd:3.5.15-0",
"imageID": "sha256:27e3830e1402783674d8b594038967deea9d51f0d91b34c93c8f39d2f68af7da",
"lastState": {
"terminated": {
"containerID": "containerd://28d1a65bd9cfa40624a0c17979208f66a5cc7f496a57fa9a879907bb936f57b3",
"exitCode": 255,
"finishedAt": "2024-12-06T13:28:31Z",
"reason": "Unknown",
"startedAt": "2024-11-04T15:14:19Z"
}
},
"name": "etcd",
"ready": true,
"restartCount": 2,
"started": true,
"state": {
"running": {
"startedAt": "2024-12-06T13:28:35Z"
}
}
}
],
"hostIP": "172.18.0.2",
"hostIPs": [
{
"ip": "172.18.0.2"
}
],
"phase": "Running",
"podIP": "172.18.0.2",
"podIPs": [
{
"ip": "172.18.0.2"
}
],
"qosClass": "Burstable",
"startTime": "2024-12-06T13:28:34Z"
}
}
"#,
)
.into_iter::<serde_json::Value>()
.filter_map(serde_json::Result::ok),
None,
.filter_map(serde_json::Result::ok)
.collect::<Vec<_>>()
.iter(),
);

let mut p = Json::new(stream)
.title("JSON viewer")
.json_lines(5)
.prompt()?;
let mut p = Json::new(stream).title("JSON viewer").prompt()?;
println!("result: {:?}", p.run()?);
Ok(())
}
2 changes: 1 addition & 1 deletion promkit/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod checkbox;
mod cursor;
pub use cursor::Cursor;
pub mod json;
pub mod jsonstream;
pub mod listbox;
pub mod snapshot;
pub mod text;
Expand Down
2 changes: 0 additions & 2 deletions promkit/src/core/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod len;
use len::Len;
mod composite;
pub use composite::CompositeCursor;

/// A generic cursor structure for navigating and manipulating collections.
/// It maintains a position within the collection
Expand Down
Loading
Loading