Skip to content

Commit

Permalink
Merge pull request #97 from seryj/features/ratatui-replacement
Browse files Browse the repository at this point in the history
replace tui by ratatui
  • Loading branch information
matthewmturner authored Aug 24, 2024
2 parents d3fd671 + a30c4bd commit 85404b9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 104 deletions.
107 changes: 38 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ log = "0.4"
mimalloc = { version = "0.1", default-features = false }
serde = "1.0.136"
serde_json = "1.0.79"
tui = { version = "0.17", default-features = false, features = [
ratatui = { version = "0.21", default-features = false, features = [
'crossterm',
'serde',
] }
tui-logger = "0.7"
tui-logger = {version="0.9", default-features = false, features = ["ratatui-support"]}
tokio = { version = "1", features = ["full"] }
unicode-width = "0.1.9"

Expand Down
20 changes: 5 additions & 15 deletions src/app/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ pub struct Tabs {
pub index: usize,
}

#[derive(Debug, Copy, Eq, PartialEq, Clone)]
#[derive(Default, Debug, Copy, Eq, PartialEq, Clone)]
pub enum TabItem {
#[default]
Editor,
QueryHistory,
Context,
Logs,
}

impl Default for TabItem {
fn default() -> TabItem {
TabItem::Editor
}
}

impl TabItem {
pub(crate) fn all_values() -> Vec<TabItem> {
vec![
Expand All @@ -68,7 +63,7 @@ impl TabItem {
}

pub(crate) fn title_with_key(&self) -> String {
return format!("{} [{}]", self.title(), self.list_index() + 1);
format!("{} [{}]", self.title(), self.list_index() + 1)
}

pub(crate) fn title(&self) -> &'static str {
Expand Down Expand Up @@ -109,19 +104,14 @@ impl From<TabItem> for usize {
}
}

#[derive(Debug, Copy, Clone)]
#[derive(Default, Debug, Copy, Clone)]
pub enum InputMode {
#[default]
Normal,
Editing,
Rc,
}

impl Default for InputMode {
fn default() -> InputMode {
InputMode::Normal
}
}

/// Status that determines whether app should continue or exit
#[derive(PartialEq)]
pub enum AppReturn {
Expand Down
2 changes: 1 addition & 1 deletion src/app/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Input {
self.current_row - MAX_EDITOR_LINES
} as usize;

let end = (start + (MAX_EDITOR_LINES as usize) + 1) as usize;
let end = start + (MAX_EDITOR_LINES as usize) + 1;

let text: Vec<&str> = if start == 0 {
// debug!("Combining all lines");
Expand Down
20 changes: 10 additions & 10 deletions src/app/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// specific language governing permissions and limitations
// under the License.

use tui::{
use ratatui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Span, Spans, Text},
text::{Line, Span, Text},
widgets::{Block, Borders, List, ListItem, Paragraph, Tabs},
Frame,
};
Expand Down Expand Up @@ -180,7 +180,7 @@ fn draw_sql_editor_help<'screen>(app: &App) -> Paragraph<'screen> {
Style::default(),
),
};
let mut text = Text::from(Spans::from(msg));
let mut text = Text::from(Line::from(msg));
text.patch_style(style);
Paragraph::new(text)
}
Expand All @@ -196,7 +196,7 @@ fn draw_default_help<'screen>() -> Paragraph<'screen> {
],
Style::default().add_modifier(Modifier::RAPID_BLINK),
);
let mut text = Text::from(Spans::from(msg));
let mut text = Text::from(Line::from(msg));
text.patch_style(style);
Paragraph::new(text)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ fn draw_tabs<'screen>(app: &App) -> Tabs<'screen> {
let titles = TabItem::all_values()
.iter()
.map(|tab| tab.title_with_key())
.map(|t| Spans::from(vec![Span::styled(t, Style::default())]))
.map(|t| Line::from(vec![Span::styled(t, Style::default())]))
.collect();

Tabs::new(titles)
Expand All @@ -280,12 +280,12 @@ fn draw_query_history<'screen>(app: &App) -> List<'screen> {
.enumerate()
.map(|(i, m)| {
let content = vec![
Spans::from(Span::raw(format!(
Line::from(Span::raw(format!(
"Query {} [ {} rows took {:.3} seconds ]",
i, m.rows, m.query_duration
))),
Spans::from(Span::raw(m.query.clone())),
Spans::from(Span::raw(String::new())),
Line::from(Span::raw(m.query.clone())),
Line::from(Span::raw(String::new())),
];
ListItem::new(content)
})
Expand Down Expand Up @@ -332,7 +332,7 @@ fn draw_execution_config<'screen>(app: &App) -> List<'screen> {
let config: Vec<ListItem> = exec_config
.iter()
.map(|i| {
let content = vec![Spans::from(Span::raw(i.to_string()))];
let content = vec![Line::from(Span::raw(i.to_string()))];
ListItem::new(content)
})
.collect();
Expand All @@ -349,7 +349,7 @@ fn draw_physical_optimizers<'screen>(app: &App) -> List<'screen> {
let opts: Vec<ListItem> = physical_optimizers
.iter()
.map(|i| {
let content = vec![Spans::from(Span::raw(i.to_string()))];
let content = vec![Line::from(Span::raw(i.to_string()))];
ListItem::new(content)
})
.collect();
Expand Down
Loading

0 comments on commit 85404b9

Please sign in to comment.