Skip to content

Commit

Permalink
Merge pull request #38 from fluentci-io/feat/tui
Browse files Browse the repository at this point in the history
feat: implement new terminal ui
  • Loading branch information
tsirysndr authored Aug 21, 2024
2 parents a725583 + 61f8e5d commit 28e1d44
Show file tree
Hide file tree
Showing 11 changed files with 585 additions and 40 deletions.
453 changes: 439 additions & 14 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ cargo run -p fluentci-engine -- serve
## 📦 Downloads

- `Mac`: arm64: [fluentci-engine_v0.4.8_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.8/fluentci-engine_v0.4.8_aarch64-apple-darwin.tar.gz) intel: [fluentci-engine_v0.4.8_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.8/fluentci-engine_v0.4.8_x86_64-apple-darwin.tar.gz)
- `Linux`: intel: [fluentci-engine_v0.4.8_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.8/fluentci-engine_v0.4.8_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci-engine_v0.4.8_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.8/fluentci-engine_v0.4.8_aarch64-unknown-linux-gnu.tar.gz)
- `Mac`: arm64: [fluentci-engine_v0.4.9_aarch64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.9/fluentci-engine_v0.4.9_aarch64-apple-darwin.tar.gz) intel: [fluentci-engine_v0.4.9_x86_64-apple-darwin.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.9/fluentci-engine_v0.4.9_x86_64-apple-darwin.tar.gz)
- `Linux`: intel: [fluentci-engine_v0.4.9_x86_64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.9/fluentci-engine_v0.4.9_x86_64-unknown-linux-gnu.tar.gz) arm64: [fluentci-engine_v0.4.9_aarch64-unknown-linux-gnu.tar.gz](https://github.com/fluentci-io/fluentci-engine/releases/download/v0.4.9/fluentci-engine_v0.4.9_aarch64-unknown-linux-gnu.tar.gz)

## 📚 Documentation

Expand Down
10 changes: 5 additions & 5 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ license = "MPL-2.0"
name = "fluentci-engine"
readme = "../../README.md"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.4.8"
version = "0.4.9"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
clap = "3.2.20"
extism = "1.2.0"
fluentci-core = {path = "../core", version = "0.3.6"}
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-server = {path = "../server", version = "0.3.7"}
fluentci-shared = {path = "../shared", version = "0.2.7"}
fluentci-core = {path = "../core", version = "0.3.7"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-server = {path = "../server", version = "0.3.8"}
fluentci-shared = {path = "../shared", version = "0.2.8"}
get-port = "4.0.0"
md5 = "0.7.0"
regex = "1.10.3"
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn call(module: &str, command: &str) -> Result<(), Error> {
let args = command.split_whitespace().skip(1).collect::<Vec<&str>>();
let args = args.join(" ");
match plugin.call::<&str, &str>(func, &args) {
Ok(res) => println!("{}", res),
Ok(_) => {}
Err(err) => {
println!("{}", err);
std::process::exit(1);
Expand Down
6 changes: 3 additions & 3 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-common"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.7"
version = "0.2.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
dirs = "5.0.1"
fluentci-core = {path = "../core", version = "0.3.6"}
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-core = {path = "../core", version = "0.3.7"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.8"}
regex = "1.10.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-core"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.6"
version = "0.3.7"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.81"
chrono = "0.4.35"
dirs = "5.0.1"
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-logging = {path = "../logging", version = "0.1.0"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.8"}
Expand Down
3 changes: 2 additions & 1 deletion crates/ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-ext"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.5"
version = "0.2.6"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -27,5 +27,6 @@ owo-colors = "4.0.0"
regex = "1.10.3"
sha2 = "0.10.8"
sha256 = "1.5.0"
superconsole = "0.2.0"
tokio = {version = "1.36.0", features = ["tokio-macros", "macros", "rt", "rt-multi-thread"]}
users = "0.11.0"
119 changes: 119 additions & 0 deletions crates/ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::{
env,
io::{BufRead, BufReader},
process::{Command, ExitStatus, Stdio},
sync::mpsc::{self, Receiver, Sender},
thread,
time::Instant,
};

use anyhow::Error;
use fluentci_types::Output;
use owo_colors::OwoColorize;
use superconsole::{
style::Stylize, Component, Dimensions, DrawMode, Line, Lines, Span, SuperConsole,
};

pub mod archive;
pub mod cache;
Expand Down Expand Up @@ -74,6 +80,71 @@ pub fn exec(
let namespace = cmd.to_string().clone();

thread::spawn(move || {
if let Some(mut console) = SuperConsole::new() {
if env::var("FLUENTCI_CONSOLE").unwrap_or_default() == "0" {
let mut stdout = String::new();
while let Ok(line) = stdout_rx.recv() {
println!("{}", line);
match fluentci_logging::info(&line, &namespace) {
Ok(_) => {}
Err(_) => {}
}
stdout.push_str(&line);
stdout.push_str("\n");
}

if out_clone == Output::Stdout && last_cmd {
match tx_clone.send(stdout) {
Ok(_) => {}
Err(_) => {}
}
}
return;
}
let created = Instant::now();
let mut stdout = String::new();
let mut lines = vec![];
while let Ok(line) = stdout_rx.recv() {
lines.push(line.clone());
if lines.len() > 20 {
lines.remove(0);
}

console
.render(&Log {
command: &namespace,
lines: lines.clone(),
created,
now: Instant::now(),
})
.unwrap();
match fluentci_logging::info(&line, &namespace) {
Ok(_) => {}
Err(e) => {
println!("Error: {}", e);
}
}
stdout.push_str(&line);
stdout.push_str("\n");
}

console
.finalize(&Log {
command: &namespace,
lines: vec![],
created,
now: Instant::now(),
})
.unwrap();
if out_clone == Output::Stdout && last_cmd {
match tx_clone.send(stdout) {
Ok(_) => {}
Err(_) => {}
}
}
return;
}

let mut stdout = String::new();
while let Ok(line) = stdout_rx.recv() {
println!("{}", line);
Expand All @@ -86,6 +157,7 @@ pub fn exec(
stdout.push_str(&line);
stdout.push_str("\n");
}

if out_clone == Output::Stdout && last_cmd {
match tx_clone.send(stdout) {
Ok(_) => {}
Expand Down Expand Up @@ -131,3 +203,50 @@ pub fn exec(

child.wait().map_err(Error::from)
}

struct Log<'a> {
command: &'a str,
lines: Vec<String>,
created: Instant,
now: Instant,
}

impl<'a> Component for Log<'a> {
fn draw_unchecked(&self, _dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
Ok(match mode {
DrawMode::Normal => {
let mut lines: Vec<Line> = self
.lines
.iter()
.map(|l| vec![l.clone()].try_into().unwrap())
.collect();
lines.push(
vec![format!(
" {} {}",
"Executing".bright_green().bold(),
self.command.bright_purple(),
)]
.try_into()
.unwrap(),
);
Lines(lines)
}
DrawMode::Final => {
const FINISHED: &str = " Finished ";
let finished = Span::new_styled(FINISHED.to_owned().green().bold())?;
let completion = format!(
"{} in {}{}",
self.command.bright_purple(),
(self.now.duration_since(self.created).as_millis() as f64 / 1000.0)
.to_string()
.bright_blue(),
"s".bright_blue()
);
Lines(vec![Line::from_iter([
finished,
Span::new_unstyled(&completion)?,
])])
}
})
}
}
8 changes: 4 additions & 4 deletions crates/graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-graphql"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.7"
version = "0.3.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -16,9 +16,9 @@ anyhow = "1.0.80"
async-graphql = "7.0.2"
async-graphql-actix-web = "7.0.2"
dirs = "5.0.1"
fluentci-common = {path = "../common", version = "0.2.7"}
fluentci-core = {path = "../core", version = "0.3.6"}
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-common = {path = "../common", version = "0.2.8"}
fluentci-core = {path = "../core", version = "0.3.7"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.8"}
regex = "1.10.3"
Expand Down
8 changes: 4 additions & 4 deletions crates/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-server"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.3.7"
version = "0.3.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -17,9 +17,9 @@ actix-web = "4.5.1"
anyhow = "1.0.81"
async-graphql = "7.0.2"
async-graphql-actix-web = "7.0.2"
fluentci-core = {path = "../core", version = "0.3.6"}
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-graphql = {path = "../graphql", version = "0.3.7"}
fluentci-core = {path = "../core", version = "0.3.7"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-graphql = {path = "../graphql", version = "0.3.8"}
mime_guess = "2.0.4"
owo-colors = "4.0.0"
tokio = "1.36.0"
8 changes: 4 additions & 4 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ keywords = ["nix", "environment", "ci", "wasm", "devops"]
license = "MPL-2.0"
name = "fluentci-shared"
repository = "https://github.com/fluentci-io/fluentci-engine"
version = "0.2.7"
version = "0.2.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.82"
extism = "1.2.0"
extism-pdk = "1.1.0"
fluentci-common = {path = "../common", version = "0.2.7"}
fluentci-core = {path = "../core", version = "0.3.6"}
fluentci-ext = {path = "../ext", version = "0.2.5"}
fluentci-common = {path = "../common", version = "0.2.8"}
fluentci-core = {path = "../core", version = "0.3.7"}
fluentci-ext = {path = "../ext", version = "0.2.6"}
fluentci-secrets = {path = "../secrets", version = "0.1.0"}
fluentci-types = {path = "../types", version = "0.1.8"}
serde = {version = "1.0.197", features = ["serde_derive", "derive"]}
Expand Down

0 comments on commit 28e1d44

Please sign in to comment.