Skip to content

Commit

Permalink
feat(fx): wipe from top/bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
grampelberg committed Oct 3, 2024
1 parent 37c36d7 commit 94f7512
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 169 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ allowed-duplicate-crates = [
"hyper",
"itertools",
"mio",
"nu-ansi-term",
"pbkdf2",
"regex-automata",
"regex-syntax",
Expand Down
3 changes: 3 additions & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

export RUST_BACKTRACE=full
export RUST_LOG=none,kty=debug
# export TRACING_TREE=none,kty=trace

export LOCAL_REGISTRY="kty:5432"

# export GHCR_USER="me"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ warp = "0.3.7"
workspace = true

[profile.dev]
debug = 0
debug = 1
split-debuginfo = "unpacked"

[profile.release]
Expand Down
5 changes: 4 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ git rebase -ff branch-name && git push origin branch-name

On PR, CI produces a darwin-arm64 binary and helm chart. Click on any step from
the PR and then `Summary` on the left sidebar to see the uploaded artifacts.
Docker images are not currently build/uploaded on PR runs.
Docker images are built to verify that the `linux-amd64` binary can be built but
they are not pushed or uploaded anywhere.

## Environment

Expand Down Expand Up @@ -60,6 +61,8 @@ The global debug level can be overly noisy. Instead of doing `-vvvv`, try:
RUST_LOG=none,kty=debug
```

If you'd like to see backtraces on panic, set `RUST_BACKTRACE`.

### Tracing Tree

It can be a little difficult to reason about how events filter through the
Expand Down
69 changes: 28 additions & 41 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,18 @@
## Server

- Move over to axum for health instead of warp.
- Terminate the session (but not the server) on panic.

## TUI

- There needs to be some way to pre-flight permissions for a component so that
an error is shown instead of letting the component fail.

- Is it possible to get the kubelet logs?

- `kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/` works as
`NodeQueryLog` which is beta in 1.30. It is a little weird though, k3s at
least returns html? And it doesn't contain the kubelet logs?

- Use SSH forwarding to get into the nodes.

- Does it make sense to do the `nsenter` trick for some use cases? This
requires privileged mode to work.

- This is waiting on the next release of russh as `handle.open_channel_agent`
just landed.

- There's some kind of lag happening when scrolling aggressively (aka, holding
down a cursor). It goes fine for ~10 items and then has a hitch in the
rendering.

- Terminal resizing isn't wired up for the dev dashboard.

- The way that layers work would be better served by something with ndarray. In
particular, calculating what the area of a widget would be is ugly.

- Add an error screen if the ready channel is closed with an error. See
widget/pod.rs.

- Add routing back in.

- Calculate visibility via areas + zindex to understand what needs to be
Expand All @@ -73,20 +53,32 @@
- Dashboard as a struct doesn't really make sense anymore, it should likely be
converted over to a simple function.

- Move YAML over to viewport. Should viewport be doing syntax highlighting by
default? How do we do a viewport over a set of lines that require history to
do highlighting?

- There's a bug somewhere in `log_stream`. My k3d cluster restarted and while I
could get all the logs, the stream wouldn't keep running - it'd terminate
immediately. `stern` seemed to be working fine. Recreating the cluster causedx
everything to work again.

- Move over to something like
[ratatui-textarea](https://github.com/rhysd/tui-textarea) for the inputs.

- Add an editor to allow for creation of resources (should it just be pods?).

- Animate the egress/ingress tunnel lines. In particular, it would be nice to
watch `Active` fade to `Listening` after a request goes through.

### Nodes

- Is it possible to get the kubelet logs?

- `kubectl get --raw "/api/v1/nodes/node-1.example/proxy/logs/` works as
`NodeQueryLog` which is beta in 1.30. It is a little weird though, k3s at
least returns html? And it doesn't contain the kubelet logs?

- Use SSH forwarding to get into the nodes.

- Does it make sense to do the `nsenter` trick for some use cases? This
requires privileged mode to work.

- This is waiting on the next release of russh as `handle.open_channel_agent`
just landed.

### Pods

- Rethink the pod detail view. The yaml doesn't feel like the most important
thing to look at, neither do logs. Shell feels the closest, but that's not
great either. Maybe something like `kubectl describe`? It could be multi-panel
Expand All @@ -95,11 +87,15 @@
_everything_ into memory (but doesn't try to render the entire thing every
100ms).

- Animate the egress/ingress tunnel lines. In particular, it would be nice to
watch `Active` fade to `Listening` after a request goes through.
- Add `graph` to the pod view.

### Table

- Highlight filter matches in the list.

## SFTP

- Get a watchman style demo working.
- Allow globs in file paths, eg `/*/nginx**/etc/passwd`.
- Return an error that is nicer than "no files found" when a container doesn't
have cat/ls.
Expand All @@ -108,7 +104,6 @@
## SSH Functionality

- Allow `ssh` directly into a pod without starting the dashboard.

- How can `ssh` be shutdown without causing it to have a 1 as an exit code?

## Ingress Tunnel
Expand All @@ -126,9 +121,6 @@

## Build

- Figure out why `git cliff` goes `0.2.0` -> `0.2.1` -> `0.3.0` instead of
`0.2.2`.

- Add integration test for `kty resources install`.

- Add integration test for `helm install`.
Expand All @@ -137,11 +129,6 @@
be great for the development experience. Is there a way to have defaults but
override them? Maybe with a dev instance of auth0?

## Deployment

- Add `kustomize` to allow for an easier getting started.
- Make `helm install` work if someone's checked the repo out.

## Misc

- Move to [bon](https://docs.rs/bon/latest/bon/) instead of `derive_builder`.
117 changes: 6 additions & 111 deletions src/fx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod wipe;

use bon::{builder, Builder};
use eyre::Result;
use ndarray::{s, ArrayViewMut2};
use ratatui::{buffer::Buffer, layout::Rect, Frame};
use tachyonfx::{CellFilter, CellIterator, Duration, Effect, EffectRenderer, EffectTimer, Shader};
use tachyonfx::{Effect, EffectRenderer, EffectTimer, Shader};
pub use wipe::Start;

use crate::{
dashboard::render_interval,
Expand Down Expand Up @@ -46,124 +48,17 @@ impl Widget for Animated {
}
}

#[derive(Clone, Default)]
pub enum Start {
Left,
#[default]
Right,
}

/// Wipes content in from the start edge, uses `previous` as the source and then
/// the current buffer as the destination.
#[derive(Builder, Clone)]
pub struct Wipe {
#[builder(into)]
timer: EffectTimer,
#[builder(default)]
start: Start,
previous: Buffer,
#[builder(default)]
done: bool,
}

#[builder]
pub fn horizontal_wipe<T: Into<EffectTimer>>(
pub fn wipe<T: Into<EffectTimer>>(
timer: T,
buffer: Buffer,
#[builder(default)] start: Start,
) -> Effect {
Effect::new(
Wipe::builder()
wipe::Wipe::builder()
.timer(timer.into())
.previous(buffer)
.start(start)
.build(),
)
}

// This assumes that the area from the original buffer to the new one doesn't
// change. If it is unable to create a slice correctly, it'll just give up.
impl Shader for Wipe {
fn name(&self) -> &'static str {
"slider"
}

#[allow(
clippy::cast_possible_truncation,
clippy::cast_sign_loss,
clippy::cast_precision_loss
)]
fn process(&mut self, duration: Duration, buf: &mut Buffer, area: Rect) -> Option<Duration> {
let (overflow, alpha) = self
.timer_mut()
.map_or((None, 1.0), |t| (t.process(duration), t.alpha()));

let x = area.x as usize;
let y = area.y as usize;
let width = area.width as usize;
let height = area.height as usize;
let buffer_width = self.previous.area.width as usize;
let buffer_height = self.previous.area.height as usize;

let window = ((width as f32 * alpha).round() as usize).clamp(0, width);

if window == width {
self.done = true;
}

let Ok(previous) =
ArrayViewMut2::from_shape((buffer_height, buffer_width), &mut self.previous.content)
else {
tracing::debug!(area = ?area, "unable to create view from previous buffer");

self.done = true;
return overflow;
};

let Ok(mut next) =
ArrayViewMut2::from_shape((buffer_height, buffer_width), &mut buf.content)
else {
tracing::debug!(area = ?area, "unable to create view from next buffer");

self.done = true;
return overflow;
};

let slice = match self.start {
Start::Left => s![y..height, x + window..x + width],
Start::Right => s![y..y + height, x..x + width - window],
};

let previous_section = previous.slice(slice);

next.slice_mut(slice).assign(&previous_section);

overflow
}

fn execute(&mut self, _: f32, _: Rect, _: CellIterator<'_>) {}

fn done(&self) -> bool {
self.done
}

fn clone_box(&self) -> Box<dyn Shader> {
Box::new(self.clone())
}

fn area(&self) -> Option<Rect> {
None
}

fn set_area(&mut self, _area: Rect) {}

fn set_cell_selection(&mut self, _: CellFilter) {}

fn timer_mut(&mut self) -> Option<&mut EffectTimer> {
Some(&mut self.timer)
}

fn timer(&self) -> Option<EffectTimer> {
Some(self.timer)
}
}
Loading

0 comments on commit 94f7512

Please sign in to comment.