Skip to content

Commit

Permalink
tui is unmaintained; use ratatui instead
Browse files Browse the repository at this point in the history
Signed-off-by: chengqinglin <[email protected]>
  • Loading branch information
imuxin committed Oct 25, 2023
1 parent 52af49e commit c2bc615
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 83 deletions.
206 changes: 151 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[workspace]
default-members = ["kubectl-watch"]
members = [
"kubectl-watch",
"difftastic-lib",
]
members = ["kubectl-watch", "difftastic-lib"]
resolver = "2"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ kubectl-watch {resource} -include-managed-fields

## Acknowledgment

- [tui-rs](https://github.com/fdehau/tui-rs)
- [ratatui](https://github.com/ratatui-org/ratatui)
- [difftastic](https://github.com/Wilfred/difftastic)
- [kube-rs](https://github.com/kube-rs/kube-rs)
- [rust](https://github.com/rust-lang/rust)
4 changes: 2 additions & 2 deletions difftastic-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.0.2"
authors = ["Wilfred Hughes <[email protected]>", "chengqinglin <[email protected]>"]
keywords = ["diff", "syntax"]
categories = ["development-tools", "command-line-utilities", "parser-implementations"]
edition = "2018"
edition = "2021"
include = [
"/build.rs",
"/src/",
Expand Down Expand Up @@ -63,7 +63,7 @@ version_check = "0.9.4"
# flamegraph.
#
# https://doc.rust-lang.org/cargo/reference/profiles.html#release
debug = false
# debug = false

[[bin]]
name = "difft"
Expand Down
17 changes: 13 additions & 4 deletions kubectl-watch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@ readme = "../README.md"

[dependencies]
anyhow = "1.0.44"
clap = { version = "3.1.9", default-features = false, features = ["std", "cargo", "derive"] }
clap = { version = "3.1.9", default-features = false, features = [
"std",
"cargo",
"derive",
] }
colored = "2"
crossterm = "0.26"
# difftastic-lib = "0.0.1"
difftastic-lib = { path = "../difftastic-lib" , version = "0.0.2"}
difftastic-lib = { path = "../difftastic-lib", version = "0.0.2" }
edit = "0.1.3"
either = "1.6.1"
futures = "0.3.17"
grep-cli = "0.1.6"
itertools = "0.10.5"
kube = { version = "0.78.0", default-features = false, features = ["runtime", "derive", "client", "rustls-tls"] }
kube = { version = "0.78.0", default-features = false, features = [
"runtime",
"derive",
"client",
"rustls-tls",
] }
k8s-openapi = { version = "0.17.0", features = ["v1_24"] }
serde = { version = "1.0.144", features = ["derive"] }
serde_json = "1.0.85"
Expand All @@ -32,4 +41,4 @@ tracing = "0.1.29"
tracing-subscriber = "0.3.3"
terminal_size = "0.2.1"
term_size = "0.3.2"
tui = "0.19"
ratatui = "0.24.0"
8 changes: 4 additions & 4 deletions kubectl-watch/src/diff/difft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::persistent;

use difft_lib::{diff_file, options, print_diff_result, tui_diff_result, FgColor};
use kube::api::DynamicObject;
use std::path::PathBuf;
use tui::{
use ratatui::{
style::{Color, Style},
text::{Span, Spans},
text::{Line, Span},
widgets::{Paragraph, Wrap},
};
use std::path::PathBuf;

pub struct Difft {
include_managed_fields: bool,
Expand Down Expand Up @@ -127,7 +127,7 @@ fn to_paragraph<'a>(result: Vec<Vec<(String, FgColor)>>) -> Paragraph<'a> {
Span::styled(content.clone(), Style::default().fg(c))
})
.collect::<Vec<_>>();
Spans::from(spans)
Line::from(spans)
})
.collect::<Vec<_>>(),
)
Expand Down
2 changes: 1 addition & 1 deletion kubectl-watch/src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::options;

use kube::api::DynamicObject;
use std::path::PathBuf;
use tui::widgets::Paragraph;
use ratatui::widgets::Paragraph;

pub trait Diff<'a> {
fn diff(&mut self, minus_file: PathBuf, plus_file: PathBuf) -> std::io::Result<i32>;
Expand Down
18 changes: 6 additions & 12 deletions kubectl-watch/src/output/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use kube::{api::DynamicObject, ResourceExt};
use std::{collections::HashMap, io};
use tokio::sync::mpsc;
use tui::{
use ratatui::{
backend::{Backend, CrosstermBackend},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
Expand All @@ -22,6 +20,8 @@ use tui::{
Frame,
Terminal,
};
use std::{collections::HashMap, io};
use tokio::sync::mpsc;

impl UID for DynamicObject {
fn resource_version(&self) -> String {
Expand Down Expand Up @@ -262,7 +262,7 @@ async fn run_tui<B: Backend>(
}
}

fn ui<B: Backend>(f: &mut Frame<B>, ctrl: &mut Controller) {
fn ui(f: &mut Frame, ctrl: &mut Controller) {
let chunks = Layout::default()
.constraints([Constraint::Length(10), Constraint::Min(10)].as_ref())
.split(f.size());
Expand All @@ -271,10 +271,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, ctrl: &mut Controller) {
draw_diff(f, ctrl, chunks[1]);
}

fn draw_resources_event<B>(f: &mut Frame<B>, ctrl: &mut Controller, area: Rect)
where
B: Backend,
{
fn draw_resources_event(f: &mut Frame, ctrl: &mut Controller, area: Rect) {
let selected_style = Style::default().bg(Color::Black).fg(Color::LightRed);
let header = Row::new(ctrl.get_header())
.style(Style::default().fg(Color::LightBlue))
Expand Down Expand Up @@ -311,10 +308,7 @@ where
f.render_stateful_widget(t, area, &mut ctrl.state);
}

fn draw_diff<B>(f: &mut Frame<B>, ctrl: &mut Controller, area: Rect)
where
B: Backend,
{
fn draw_diff(f: &mut Frame, ctrl: &mut Controller, area: Rect) {
f.render_widget(
Block::default().borders(Borders::ALL).title("Diff Result"),
area,
Expand Down

0 comments on commit c2bc615

Please sign in to comment.