Skip to content

Commit

Permalink
Feature: explorer add stream view (#17)
Browse files Browse the repository at this point in the history
* update: stream example

* feat: stream view
  • Loading branch information
honhimW authored Oct 21, 2024
1 parent 6593a7f commit 4e75e4c
Show file tree
Hide file tree
Showing 11 changed files with 572 additions and 44 deletions.
34 changes: 34 additions & 0 deletions examples/redis_stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[path = "common/lib.rs"]
mod common;
use crate::common::client::dead_pool;
use anyhow::Result;
use itertools::Itertools;
use redis::{Cmd, Value};
use ratisui::utils::bytes_to_string;

#[tokio::main]
async fn main() -> Result<()> {
let pool = dead_pool()?;
let mut connection = pool.get().await?;
let cmd = str_cmd!("xrevrange stream + -");
let x: Vec<(Vec<String>, Vec<Vec<String>>)> = cmd.query_async(&mut connection).await?;
let x: Value = cmd.query_async(&mut connection).await?;
println!("{:?}", x);

let value = Value::BulkString("".as_bytes().to_vec());

if let Value::BulkString(bulk_string) = value {
let bulk_string = bytes_to_string(bulk_string.clone()).unwrap_or_else(|e| e.to_string());
let bulk_string = bulk_string.replace("\t", "\\t");
// let bulk_string = format!("\"{}\"", bulk_string);
let lines = bulk_string.lines();
let format = |str: &str| {
format!("{str}")
};
let vec = lines.map(|line| {
format(line)
}).collect_vec();
}

Ok(())
}
1 change: 1 addition & 0 deletions src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub struct GlobalChannel {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum GlobalEvent {
ClientChanged,
#[allow(unused)]
Dynamic(String),
}

Expand Down
6 changes: 2 additions & 4 deletions src/components/hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl HashValue {
lines.push(bar.into());
}
lines.push("".into());
let heilight_symbol = Text::from(lines);
let highlight_symbol = Text::from(lines);
let t = Table::new(
rows,
[
Expand All @@ -219,7 +219,7 @@ impl HashValue {
)
.header(header)
.highlight_style(selected_style)
.highlight_symbol(heilight_symbol)
.highlight_symbol(highlight_symbol)
.bg(self.colors.buffer_bg)
.highlight_spacing(HighlightSpacing::Always);
frame.render_stateful_widget(t, area, &mut self.state);
Expand Down Expand Up @@ -272,8 +272,6 @@ impl Listenable for HashValue {
self.previous();
true
},
// KeyCode::Char('l') | KeyCode::Right => self.next_color(),
// KeyCode::Char('h') | KeyCode::Left => self.previous_color(),
_ => {false},
};
return Ok(accepted);
Expand Down
6 changes: 2 additions & 4 deletions src/components/list_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl ListValue {
lines.push(bar.into());
}
lines.push("".into());
let heilight_symbol = Text::from(lines);
let highlight_symbol = Text::from(lines);
let t = Table::new(
rows,
[
Expand All @@ -211,7 +211,7 @@ impl ListValue {
)
.header(header)
.highlight_style(selected_style)
.highlight_symbol(heilight_symbol)
.highlight_symbol(highlight_symbol)
.bg(self.colors.buffer_bg)
.highlight_spacing(HighlightSpacing::Always);
frame.render_stateful_widget(t, area, &mut self.state);
Expand Down Expand Up @@ -264,8 +264,6 @@ impl Listenable for ListValue {
self.previous();
true
},
// KeyCode::Char('l') | KeyCode::Right => self.next_color(),
// KeyCode::Char('h') | KeyCode::Left => self.previous_color(),
_ => {false},
};
return Ok(accepted);
Expand Down
3 changes: 2 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ mod database_editor;
pub mod create_key_editor;
pub mod console_output;
pub mod redis_cli;
pub mod raw_paragraph;
pub mod raw_paragraph;
pub mod stream_view;
6 changes: 2 additions & 4 deletions src/components/set_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl SetValue {
lines.push(bar.into());
}
lines.push("".into());
let heilight_symbol = Text::from(lines);
let highlight_symbol = Text::from(lines);
let t = Table::new(
rows,
[
Expand All @@ -211,7 +211,7 @@ impl SetValue {
)
.header(header)
.highlight_style(selected_style)
.highlight_symbol(heilight_symbol)
.highlight_symbol(highlight_symbol)
.bg(self.colors.buffer_bg)
.highlight_spacing(HighlightSpacing::Always);
frame.render_stateful_widget(t, area, &mut self.state);
Expand Down Expand Up @@ -264,8 +264,6 @@ impl Listenable for SetValue {
self.previous();
true
},
// KeyCode::Char('l') | KeyCode::Right => self.next_color(),
// KeyCode::Char('h') | KeyCode::Left => self.previous_color(),
_ => {false},
};
return Ok(accepted);
Expand Down
Loading

0 comments on commit 4e75e4c

Please sign in to comment.